This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
277 lines (249 loc) · 10.7 KB
/
action.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
name: 'Fauna IaC'
description: 'Domain driven Infrastructure as Code for Fauna databases'
branding:
icon: "box"
color: "purple"
inputs:
GITHUB_REPOSITORIES:
description: 'Comma separated repositories in the form of organization/name (to checkout the default branch) or
organization/name@ref where ref is a branch name, tag or SHA to checkout.
Eg. "Dechea/exampleRepository, Dechea/AnotherExampleRepository@v2"'
required: true
GITHUB_PAT:
description: 'The key used to access your github repos.'
required: true
FAUNA_DATABASE:
description: 'The target database where you want to apply the migration.'
required: true
default: 'Prod'
FAUNA_REGION:
description: 'The domain where your databases are hosted.
Allowed values: us, eu, classic, preview
Default value: classic'
required: false
default: 'classic'
FAUNA_TOKEN:
description: 'The token used to access your Fauna database.'
required: true
FAUNA_CHILD_DB:
description: 'The token used to access your Fauna child database used to run unit and integration tests.'
required: false
BIT_TOKEN:
description: 'The token used to access your bit.dev instance.
Managed by Doppler'
required: false
MUTATION_TEST:
description: 'Run all fauna tests again with stryker.'
required: false
default: 'false'
VERBOSE:
description: 'Turn on extra debug information.'
required: false
default: 'false'
#outputs:
runs:
using: "composite"
steps:
#### ESLINT check only for the repo where the workflow was started
- name: Checkout source code
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- name: Check and validate eslint
run: |
npm install
npm run eslint:validate --if-present
echo "ESLint validation run successfully"
shell: bash
env:
BIT_TOKEN: ${{ inputs.BIT_TOKEN }}
- name: "Print out input variables passed"
run: |
echo "Input repositories: ${{ inputs.GITHUB_REPOSITORIES }}"
shell: bash
- name: "Check and get correct fauna URLs"
id: get_fauna_urls
run: |
echo "Input fauna region: ${{ inputs.FAUNA_REGION }}"
if [[ ${{ inputs.FAUNA_REGION }} != @(us|eu|classic|preview) ]]; then
echo "Invalid input Fauna Region: ${{ inputs.FAUNA_REGION}}"
echo "Doesn't match one of the allowed values: 'us, eu, classic, preview'!"
echo "Aborting..."
exit 128
else
chmod u+x ${{ github.action_path }}/scripts/get_correct_fauna_domains.sh
FAUNA_URLS=$( ${{ github.action_path }}/scripts/get_correct_fauna_domains.sh ${{ inputs.FAUNA_REGION }})
IFS=":"
read -ra arr <<< "$FAUNA_URLS"
echo "::set-output name=fauna_domain::${arr[0]}"
echo "::set-output name=fauna_graphql_domain::${arr[1]}"
fi
shell: bash
- name: "Convert input repository string"
id: convert_repo_str
run: |
REPO_NAMES=${{ inputs.GITHUB_REPOSITORIES }}
REPO_NAMES="${REPO_NAMES//','/'%0A'}"
echo "::set-output name=repo_names::$REPO_NAMES"
shell: bash
- name: "Convert input repository string to domain name"
id: convert_github_domains
run: |
chmod u+x ${{ github.action_path }}/scripts/convert_input_string.sh
GITHUB_DOMAIN=$( ${{ github.action_path }}/scripts/convert_input_string.sh ${{ inputs.GITHUB_REPOSITORIES }} "s;/.*;;g" )
echo "::set-output name=domain::$GITHUB_DOMAIN"
shell: bash
#### IF - NO REF IS SET
- name: "Logging - without [@Ref]"
if: "!contains(inputs.GITHUB_REPOSITORIES, '@' )"
run: |
echo "Logging - without [@Ref]"
shell: bash
- name: "Convert input repository string - without [@Ref]"
id: convert_domains
if: "!contains(inputs.GITHUB_REPOSITORIES, '@' )"
run: |
GITHUB_REPOSITORY_NAMES=$( ${{ github.action_path }}/scripts/convert_input_string.sh ${{ inputs.GITHUB_REPOSITORIES }} "s;,;\n;g" )
echo "::set-output name=domains_modified::$GITHUB_REPOSITORY_NAMES"
shell: bash
- name: "Remove domain string from modified input string - without [@Ref]"
uses: rishabhgupta/split-by@v2
id: split
if: "!contains(inputs.GITHUB_REPOSITORIES, '@' )"
with:
string: ${{ inputs.GITHUB_REPOSITORIES }}
split-by: "${{ steps.convert_github_domains.outputs.domain }}/"
- run: |
echo "splitting based on: ${{ steps.convert_domains.outputs.domain }}/ done successfully"
shell: bash
#### ELSE IF - REF IS SET
- name: "Logging - with [@Ref]"
if: "contains(inputs.GITHUB_REPOSITORIES, '@' )"
run: |
echo "Logging - with [@Ref]"
shell: bash
- name: "Convert input repository string - with [@Ref]"
id: convert_domains_ref
if: "contains(inputs.GITHUB_REPOSITORIES, '@' )"
run: |
GITHUB_REPOSITORY_NAMES_REF=$( ${{ github.action_path }}/scripts/convert_input_string_.sh ${{ inputs.GITHUB_REPOSITORIES }} "s;,;\n;g" "@|," )
GITHUB_REPOSITORY_NAMES_REF=$( ${{ github.action_path }}/scripts/convert_input_string_.sh "${GITHUB_REPOSITORY_NAMES_REF}" "s;\n;,;g")
GITHUB_REPOSITORY_NAMES_REF="${GITHUB_REPOSITORY_NAMES_REF//','/''}"
GITHUB_REPOSITORY_NAMES_REF="${GITHUB_REPOSITORY_NAMES_REF//'%0A'/''}"
echo "GITHUB_REPOSITORY_NAMES_REF: ${GITHUB_REPOSITORY_NAMES_REF}"
echo "::set-output name=domains_modified::$GITHUB_REPOSITORY_NAMES_REF"
shell: bash
- name: "Remove domain string from modified input string - with [@Ref]"
uses: rishabhgupta/split-by@v2
id: split_ref
if: "contains(inputs.GITHUB_REPOSITORIES, '@' )"
with:
string: ${{ steps.convert_domains_ref.outputs.domains_modified }}
split-by: "${{ steps.convert_github_domains.outputs.domain }}/"
- run: |
echo "splitting based on: ${{ steps.convert_domains.outputs.domain }}/ done successfully"
shell: bash
#### END
- name: "Print out modified variables"
id: print_repo_names
run: |
chmod u+x ${{ github.action_path }}/scripts/contains_substring_in_string.sh
IS_CONTAINS=$( ${{ github.action_path }}/scripts/contains_substring_in_string.sh ${{ inputs.GITHUB_REPOSITORIES }} "@" )
if [[ "$IS_CONTAINS" == "true" ]]; then
GITHUB_REPOSITORY_NAMES=${{ join(steps.split_ref.outputs.*, ',') }}
GITHUB_REPOSITORY_NAMES="${GITHUB_REPOSITORY_NAMES:1}"
else
GITHUB_REPOSITORY_NAMES=${{ join(steps.split.outputs.*, '') }}
fi
echo "$GITHUB_REPOSITORY_NAMES"
echo "::set-output name=repository_names::$GITHUB_REPOSITORY_NAMES"
shell: bash
- name: Checkout all domain repos
uses: vweevers/multi-checkout-action@v1
with:
token: ${{ inputs.GITHUB_PAT }}
repositories: |
${{ steps.convert_repo_str.outputs.repo_names }}
path: repos
- name: Merge all test files
run: |
ls -lA
IFS="," read -a repoNames <<< ${{ steps.print_repo_names.outputs.repository_names }}
for index in "${!repoNames[@]}"
do
rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/__mocks__/ __mocks__/
rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/constants/ constants/
rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/fauna/src/ fauna/src/
rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/fauna/resources/ fauna/resources/
rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/fauna/tests/ fauna/tests/
[ -d "repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/fauna/util/" ] && rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/fauna/util/ fauna/util/
[ -d "repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/fauna/migrations/${{ inputs.FAUNA_DATABASE }}/" ] && rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/fauna/migrations/${{ inputs.FAUNA_DATABASE }}/ fauna/migrations/${{ inputs.FAUNA_DATABASE }}/
rsync -avuP repos/${{ steps.convert_github_domains.outputs.domain }}/${repoNames[index]}/util/ util/
done
echo "Successfully copied necessary files for testing and generating migrations"
shell: bash
- name: Setup Node.js
id: cache-node-modules
uses: actions/setup-node@v3
with:
node-version: '14'
- name: Install Node.js and test
run: |
npm install
npm run test
echo "Test cases run successfully"
shell: bash
env:
BIT_TOKEN: ${{ inputs.BIT_TOKEN }}
FAUNA_CHILD_DB: ${{ inputs.FAUNA_CHILD_DB }}
- name: Install Node.js and run stryker mutation test
if: ${{ inputs.MUTATION_TEST == 'true' }}
run: |
npm install
npm run test:mutation
echo "Mutated test cases run successfully"
shell: bash
env:
BIT_TOKEN: ${{ inputs.BIT_TOKEN }}
FAUNA_CHILD_DB: ${{ inputs.FAUNA_CHILD_DB }}
- name: Upload coverage files
uses: actions/upload-artifact@v3
with:
name: coverage-files
path: coverage/**
- name: Create Fauna migration files
run: |
npm install
npm run fauna:generate
echo "Successfully created fauna migration"
shell: bash
env:
BIT_TOKEN: ${{ inputs.BIT_TOKEN }}
FAUNA_ADMIN_KEY: ${{ inputs.FAUNA_TOKEN }}
FAUNADB_DOMAIN: ${{ steps.get_fauna_urls.outputs.fauna_domain }}
FAUNA_DATABASE: ${{ inputs.FAUNA_DATABASE }}
- name: Check Fauna migration state
run: |
npm install
npm run fauna:state
shell: bash
env:
BIT_TOKEN: ${{ inputs.BIT_TOKEN }}
FAUNA_ADMIN_KEY: ${{ inputs.FAUNA_TOKEN }}
FAUNADB_DOMAIN: ${{ steps.get_fauna_urls.outputs.fauna_domain }}
FAUNA_DATABASE: ${{ inputs.FAUNA_DATABASE }}
- name: Apply Fauna migration
run: |
npm install
npm run fauna:apply
echo "Successfully applied fauna migration"
shell: bash
env:
BIT_TOKEN: ${{ inputs.BIT_TOKEN }}
FAUNA_ADMIN_KEY: ${{ inputs.FAUNA_TOKEN }}
FAUNADB_DOMAIN: ${{ steps.get_fauna_urls.outputs.fauna_domain }}
FAUNA_DATABASE: ${{ inputs.FAUNA_DATABASE }}
- name: Commit Fauna migration folder
uses: EndBug/add-and-commit@v9
with:
add: fauna/migrations/${{ inputs.FAUNA_DATABASE }}/
message: 'updated migration [skip ci]'
commit: '--no-verify'