-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (118 loc) · 4.13 KB
/
new-workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: New Workflow
on:
push:
branches:
- main
pull_request:
branches:
- 'delete_*'
# workflow_dispatch:
# inputs:
# which_job:
# description: which job
# required: true
# type: choice
# default: build
# options:
# - build
# - job2
# resource_dir:
# description: "resource dir"
# required: true
# type: string
defaults:
run:
shell: bash
jobs:
# build:
# if: ${{ inputs.which_job == 'build' }}
# runs-on: self-hosted
# steps:
# - name: Checkout Repository
# uses: actions/checkout@v2
# - name: Run a Simple Command
# run: echo "New, workflow!"
job2:
# if: ${{ inputs.which_job == 'job2' }}
runs-on: self-hosted
steps:
- name: Run a Simple Command
run: echo "Job2 ran"
- name: Checkout Repository
uses: actions/checkout@v2
- name: Get changed version files
id: changed-files
uses: tj-actions/changed-files@v42
with:
files: services/**
dir_names: true
dir_names_deleted_files_include_only_deleted_dirs: true
- name: Parse files
id: parse-files
run: |
function get_top_dir() {
local initial_dirs=("${!1}")
temp_parent_dirs=()
child_dirs=()
tbd_dirs=()
# for each dir, check if it is a parent or child of another dir
for dir in ${initial_dirs[@]}; do
change=false
for second_dir in ${initial_dirs[@]}; do
if [[ $dir != $second_dir && $second_dir/ == $dir/* ]]; then
temp_parent_dirs+=($dir)
child_dirs+=($second_dir)
change=true
fi
done
# if the file is not a parent, then we will keep it as TBD for now
if [[ $change == false ]]; then
tbd_dirs+=($dir)
fi
done
parent_dirs=()
# parse parent dirs gain to remove dupes
for dir in ${temp_parent_dirs[@]}; do
found=false
for child in ${temp_parent_dirs[@]}; do
if [[ $dir != $child && $dir/ == $child/* ]]; then
found=true
fi
done
if [[ $found == false ]]; then
parent_dirs+=($dir)
fi
done
# change lists to sets
parent_dirs=($(echo "${parent_dirs[@]}" | tr ' ' '\n' | sort -u))
child_dirs=($(echo "${child_dirs[@]}" | tr ' ' '\n' | sort -u))
tbd_dirs=($(echo "${tbd_dirs[@]}" | tr ' ' '\n' | sort -u))
# add parent dirs to the final list of directories to be updated
final_dirs=("${parent_dirs[@]}")
# check if the TBD dirs are child dirs. If not, add them to the final list
for dir in ${tbd_dirs[@]}; do
if [[ ! " ${child_dirs[@]} " =~ " ${dir} " ]]; then
final_dirs+=($dir)
fi
done
# remove duplicates
final_dirs=($(echo "${final_dirs[@]}" | tr ' ' '\n' | sort -u))
echo FINAL_DIRS ARE ${final_dirs[@]}
echo "::set-output name=$2::${final_dirs[*]}"
}
# Get the list of changed files
changed_dirs=(${{ steps.changed-files.outputs.all_changed_files }})
echo "Changed dirs: ${changed_dirs[@]}"
deleted_dirs=(${{ steps.changed-files.outputs.deleted_files }})
echo "Deleted dirs : ${deleted_dirs[@]}"
get_top_dir changed_dirs "terragrunt_update_dirs"
get_top_dir deleted_dirs "terragrunt_delete_dirs"
- name: Terraform Plan Destroy
if: (steps.parse-files.outputs.terragrunt_delete_dirs != '')
env:
TERRAGRUNT_DIRS: ${{ steps.parse-files.outputs.terragrunt_delete_dirs }}
run: |
echo "Terragrunt destroy plan"
for dir in ${TERRAGRUNT_DIRS}; do \
echo "#### Running init on ${dir} ####"; \
done; \