-
Notifications
You must be signed in to change notification settings - Fork 11
249 lines (218 loc) · 9.62 KB
/
deploy_module.yml
File metadata and controls
249 lines (218 loc) · 9.62 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
name: 'Deploy Module'
on:
workflow_call:
secrets:
PUSH_TO_OTHER_REPOS_TOKEN_ADMIN:
required: true
workflow_dispatch:
# release:? [published]
# push:
# branches:
# - '*'
permissions:
contents: read
jobs:
copy_module_to_new_repo:
name: 'Export module'
runs-on: ubuntu-latest
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
include:
# Sonar
## aws provider
- source_module: "aws/hub"
destination_repo: "terraform-aws-dsf-hub"
hidden_submodules: "aws/sonar-base-instance aws/statistics null/statistics"
begin_tag: 1.0.0
- source_module: "aws/agentless-gw"
destination_repo: "terraform-aws-dsf-agentless-gw"
hidden_submodules: "aws/sonar-base-instance aws/statistics null/statistics"
begin_tag: 1.0.0
- source_module: "aws/poc-db-onboarder"
destination_repo: "terraform-aws-dsf-poc-db-onboarder"
public_submodule: "aws/rds-mysql-db aws/rds-mssql-db aws/rds-postgres-db"
hidden_submodules: "null/poc-db-onboarder"
begin_tag: 1.0.0
- source_module: "aws/sonar-upgrader"
destination_repo: "terraform-aws-dsf-sonar-upgrader"
begin_tag: 1.5.6
## azurerm provider
- source_module: "azurerm/hub"
destination_repo: "terraform-azurerm-dsf-hub"
hidden_submodules: "azurerm/sonar-base-instance azurerm/statistics null/statistics"
begin_tag: 1.0.0
- source_module: "azurerm/agentless-gw"
destination_repo: "terraform-azurerm-dsf-agentless-gw"
hidden_submodules: "azurerm/sonar-base-instance azurerm/statistics null/statistics"
begin_tag: 1.0.0
- source_module: "azurerm/poc-db-onboarder"
destination_repo: "terraform-azurerm-dsf-poc-db-onboarder"
public_submodule: "azurerm/mssql-db"
hidden_submodules: "null/poc-db-onboarder"
begin_tag: 1.0.0
## null provider
- source_module: "null/hadr"
destination_repo: "terraform-null-dsf-hadr"
begin_tag: 1.0.0
- source_module: "null/federation"
destination_repo: "terraform-null-dsf-federation"
begin_tag: 1.0.0
# DAM
## aws provider
- source_module: "aws/mx"
destination_repo: "terraform-aws-dsf-mx"
hidden_submodules: "aws/dam-base-instance aws/statistics null/statistics"
begin_tag: 1.0.0
- source_module: "aws/agent-gw"
destination_repo: "terraform-aws-dsf-agent-gw"
hidden_submodules: "aws/dam-base-instance aws/statistics null/statistics"
begin_tag: 1.0.0
- source_module: "aws/db-with-agent"
destination_repo: "terraform-aws-dsf-db-with-agent"
begin_tag: 1.0.0
## azurerm provider
- source_module: "azurerm/mx"
destination_repo: "terraform-azurerm-dsf-mx"
hidden_submodules: "azurerm/dam-base-instance azurerm/statistics null/statistics"
begin_tag: 1.7.4
- source_module: "azurerm/agent-gw"
destination_repo: "terraform-azurerm-dsf-agent-gw"
hidden_submodules: "azurerm/dam-base-instance azurerm/statistics null/statistics"
begin_tag: 1.7.4
- source_module: "azurerm/db-with-agent"
destination_repo: "terraform-azurerm-dsf-db-with-agent"
begin_tag: 1.7.4
## null provider
- source_module: "null/agent-gw-cluster-setup"
destination_repo: "terraform-null-dsf-agent-gw-cluster-setup"
begin_tag: 1.0.0
# DRA
## aws provider
- source_module: "aws/dra-admin"
destination_repo: "terraform-aws-dsf-dra-admin"
hidden_submodules: "aws/statistics null/statistics"
begin_tag: 1.0.0
- source_module: "aws/dra-analytics"
destination_repo: "terraform-aws-dsf-dra-analytics"
hidden_submodules: "aws/statistics null/statistics"
begin_tag: 1.0.0
## azurerm provider
- source_module: "azurerm/dra-admin"
destination_repo: "terraform-azurerm-dsf-dra-admin"
hidden_submodules: "azurerm/statistics null/statistics"
begin_tag: 1.7.6
- source_module: "azurerm/dra-analytics"
destination_repo: "terraform-azurerm-dsf-dra-analytics"
hidden_submodules: "azurerm/statistics null/statistics"
begin_tag: 1.7.6
# CipherTrust
## aws provider
- source_module: "aws/ciphertrust-manager"
destination_repo: "terraform-aws-dsf-ciphertrust-manager"
begin_tag: 1.7.31
- source_module: "aws/cte-ddc-agent"
destination_repo: "terraform-aws-dsf-cte-ddc-agent"
begin_tag: 1.7.31
## null provider
- source_module: "null/ciphertrust-manager-cluster-setup"
destination_repo: "terraform-null-dsf-ciphertrust-manager-cluster-setup"
begin_tag: 1.7.31
# Globals
## aws provider
- source_module: "aws/core/globals"
destination_repo: "terraform-aws-dsf-globals"
public_submodule: "aws/core/key_pair"
begin_tag: 1.0.0
## azurerm provider
- source_module: "azurerm/core/globals"
destination_repo: "terraform-azurerm-dsf-globals"
begin_tag: 1.0.0
env:
source_module: ${{ matrix.source_module }}
destination_repo: ${{ matrix.destination_repo }}
hidden_submodules: ${{ matrix.hidden_submodules }}
public_submodule: ${{ matrix.public_submodule }}
begin_tag: ${{ matrix.begin_tag }}
outputs:
module_github_repo: ${{ format('https://github.com/imperva/{0}', matrix.destination_repo) }}
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: '0'
ref: 'master'
- name: Filter branch
run: |
set -x
git branch
if [ -n "${hidden_submodules}" ]; then
cmd=""
for i in ${hidden_submodules}; do
target_dir=_modules/$i
cmd="$cmd mkdir -p $(dirname modules/${source_module}/$target_dir); mv modules/$i modules/${source_module}/$target_dir;"
cmd="$cmd sed -i \"s/\/modules\//\/_modules\//g\" modules/${source_module}/${target_dir}/*.tf;"
done
cmd="$cmd sed -i \"s/..\/..\/..\/modules/.\/_modules/g\" modules/${source_module}/*.tf;"
cmd="$cmd true;"
git filter-branch -f --prune-empty --tree-filter "$cmd" --tag-name-filter cat -- --all HEAD
fi
if [ -n "${public_submodule}" ]; then
for m in ${public_submodule}; do
git filter-branch -f --prune-empty --tree-filter 'mkdir -p modules/'${source_module}'/modules; mv modules/'${m}' modules/'${source_module}'/modules/; true;' --tag-name-filter cat -- --all HEAD
done
fi
git filter-branch -f --prune-empty --tree-filter 'mv LICENSE.md modules/'${source_module}'/ 2>/dev/null || true' --tag-name-filter cat -- --all HEAD
git filter-branch -f --prune-empty --subdirectory-filter modules/${source_module}/ --tag-name-filter cat -- --all HEAD
- name: Push to module repo
env:
github_token: ${{ secrets.PUSH_TO_OTHER_REPOS_TOKEN_ADMIN }}
run: |
find . | grep -v ".git/"
git config --unset-all http.https://github.com/.extraheader # override github_action own authentication method
git remote set-url origin https://${github_token}@github.com/imperva/${destination_repo}.git
git branch -m main
refs=$(git ls-remote --tags 2>/dev/null | awk '{print $NF}')
if [ -n "$refs" ]; then
git push origin --delete $(git ls-remote --tags 2>/dev/null | awk '{print $NF}')
fi
latest_tag=$(git tag -l | sort -V | tail -n 1)
version_compare() {
local v1=(${1//./ })
local v2=(${2//./ })
local i
# Compare each component of the version strings
for ((i=0; i<${#v1[@]} && i<${#v2[@]}; i++)); do
if (( ${v1[i]} < ${v2[i]} )); then
return 0 # v1 is less than v2
elif (( ${v1[i]} > ${v2[i]} )); then
return 1 # v1 is greater than v2
fi
done
# v1 is equal to v2
return 2
}
all_tags=$(git tag)
removed_tags=()
# Loop through each tag and filter if less than begin_tag
for tag in ${all_tags}; do
if version_compare "$tag" "$begin_tag"; then
echo "$tag is less than $begin_tag"
removed_tags+=("$tag")
fi
done
echo "Begin tag: ${begin_tag}, latest tag: ${latest_tag}, removed tags: ${removed_tags[@]}"
# push all repo but latest tag and removed tags
git tag -d ${latest_tag}
for tag in "${removed_tags[@]}"; do
git tag -d ${tag}
done
git push -f origin HEAD:main --tags
# push latest tag (to trigger terraform registery latest release discovery)
git tag ${latest_tag}
git push -f origin HEAD:main --tags