-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_and_release_registry.yaml
More file actions
272 lines (264 loc) · 9.67 KB
/
Copy pathbuild_and_release_registry.yaml
File metadata and controls
272 lines (264 loc) · 9.67 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
name: "Build And Release Registry"
on:
push:
branches-ignore:
- "**"
tags:
- v*
concurrency:
group: build-and-release-registry-${{ github.event.repository.name }}-${{ github.ref }}
cancel-in-progress: false
permissions:
id-token: write
contents: read
env:
disable_action: ${{ secrets.DISABLE_ACTION }}
registry_name: ${{ secrets.HEX_REGISTRY_NAME || 'artifix' }}
auth_keys_str: ${{ secrets.HEX_REGISTRY_AUTH_KEYS || '' }}
jobs:
apply-terraform:
runs-on: ubuntu-latest
steps:
- name: Git clone the repository
if: ${{ env.disable_action != 'YES' }}
uses: actions/checkout@v4
- name: Install terraform
if: ${{ env.disable_action != 'YES' }}
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.10.4
- name: Configure AWS Credentials
if: ${{ env.disable_action != 'YES' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_IAM_ROLE_ARN }}
- name: Terraform Init
if: ${{ env.disable_action != 'YES' }}
id: init
shell: sh
run: |
terraform init \
-backend-config="region=${{ secrets.TERRAFORM_BACKEND_S3_REGION }}" \
-backend-config="bucket=${{ secrets.TERRAFORM_BACKEND_S3_BUCKET }}" \
-backend-config="key=${{ secrets.TERRAFORM_BACKEND_S3_KEY }}"
working-directory: terraform
- name: Terraform Format
if: ${{ env.disable_action != 'YES' }}
id: fmt
shell: sh
run: terraform fmt -check
working-directory: terraform
- name: Terraform Validate
if: ${{ env.disable_action != 'YES' }}
id: validate
shell: sh
run: terraform validate -no-color
working-directory: terraform
- name: Terraform Apply
if: ${{ env.disable_action != 'YES' }}
id: apply
shell: sh
working-directory: terraform
run: |
terraform apply \
-var-file=../vars.tfvars \
-var="auth_keys_str=${{ env.auth_keys_str }}" \
-no-color \
-auto-approve \
-input=false
- name: Set up Elixir
if: ${{ env.disable_action != 'YES' }}
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
discover-packages:
runs-on: ubuntu-latest
outputs:
package_dirs: ${{ steps.get-dirs.outputs.dirs }}
has_packages: ${{ steps.get-dirs.outputs.has_packages }}
steps:
- name: Git clone the repository
uses: actions/checkout@v4
# Get directories and remove the "packages/" prefix for cleaner job names
- name: Get all package directories
id: get-dirs
shell: bash
run: |
if [ ! -d "packages" ]; then
echo "packages directory not found, creating it"
mkdir -p packages
fi
PACKAGE_COUNT=$(find packages -mindepth 1 -maxdepth 1 -type d | wc -l)
if [ "$PACKAGE_COUNT" -gt 0 ]; then
echo "Found packages"
DIRS=$(find packages -mindepth 1 -maxdepth 1 -type d | sed 's/packages\///' | jq -R -s -c 'split("\n")[:-1]')
HAS_PACKAGES='true'
else
echo "No packages found"
DIRS='[]'
HAS_PACKAGES='false'
fi
echo "has_packages=$HAS_PACKAGES" >> $GITHUB_OUTPUT
echo "dirs=$DIRS" >> $GITHUB_OUTPUT
echo "Has packages? $(echo $HAS_PACKAGES)"
echo "Found directories: $(echo $DIRS)"
no-packages-found:
needs: [discover-packages]
if: needs.discover-packages.outputs.has_packages == 'false'
runs-on: ubuntu-latest
steps:
- name: No packages found
run: |
echo "No packages found in the packages directory."
echo "Tests were skipped as there is nothing to test."
build-registry-tarballs:
needs: [discover-packages]
runs-on: ubuntu-latest
if: needs.discover-packages.outputs.has_packages == 'true'
strategy:
fail-fast: false
max-parallel: 10
matrix:
package: ${{ fromJson(needs.discover-packages.outputs.package_dirs) }}
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- name: Build Package for Hex
working-directory: packages/${{ matrix.package }}
run: mix hex.build
- name: Upload Tarball Artifact
uses: actions/upload-artifact@v4
with:
name: build-${{ github.sha }}-${{ matrix.package }}
path: packages/${{ matrix.package }}/${{ matrix.package }}-*.tar
if-no-files-found: error
build-registry:
needs: [build-registry-tarballs]
runs-on: ubuntu-latest
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- name: Install terraform
if: ${{ env.disable_action != 'YES' }}
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.10.4
- name: Configure AWS Credentials
if: ${{ env.disable_action != 'YES' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_IAM_ROLE_ARN }}
- name: Create public directory
run: mkdir -p public
- name: Terraform Init
if: ${{ env.disable_action != 'YES' }}
working-directory: terraform
id: init
shell: sh
run: |
terraform init \
-backend-config="region=${{ secrets.TERRAFORM_BACKEND_S3_REGION }}" \
-backend-config="bucket=${{ secrets.TERRAFORM_BACKEND_S3_BUCKET }}" \
-backend-config="key=${{ secrets.TERRAFORM_BACKEND_S3_KEY }}"
- name: Terraform Refresh
if: ${{ env.disable_action != 'YES' }}
working-directory: terraform
id: refresh
shell: sh
run: |
terraform refresh \
-var-file=../vars.tfvars \
-var="auth_keys_str=${{ env.auth_keys_str }}" \
-input=false
- name: Sync from AWS Bucket
working-directory: terraform
if: ${{ env.disable_action != 'YES' }}
run: aws s3 sync s3://$(terraform output -raw s3_registry_bucket_name) ../public/
- name: Create private key file
run: |
echo "${{ secrets.HEX_REGISTRY_PRIVATE_KEY }}" > private_key.pem
chmod 600 private_key.pem
- name: Build Initial Registry
run: mix hex.registry build public --name=${{ env.registry_name }} --private-key=private_key.pem
- name: Download all built tarball artifacts
uses: actions/download-artifact@v4
with:
path: public/tarballs
pattern: build-${{ github.sha }}-*
merge-multiple: true
- name: Build Registry With Packages
run: mix hex.registry build public --name=${{ env.registry_name }} --private-key=private_key.pem
- name: Upload Tarball Artifact
uses: actions/upload-artifact@v4
with:
name: registry-${{ github.sha }}
path: public
if-no-files-found: error
upload-registry:
needs: [apply-terraform, build-registry]
runs-on: ubuntu-latest
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Install terraform
if: ${{ env.disable_action != 'YES' }}
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.10.4
- name: Download Built Registry
uses: actions/download-artifact@v4
with:
path: public
name: registry-${{ github.sha }}
- name: Configure AWS Credentials
if: ${{ env.disable_action != 'YES' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_IAM_ROLE_ARN }}
- name: Terraform Init
if: ${{ env.disable_action != 'YES' }}
working-directory: terraform
id: init
shell: sh
run: |
terraform init \
-backend-config="region=${{ secrets.TERRAFORM_BACKEND_S3_REGION }}" \
-backend-config="bucket=${{ secrets.TERRAFORM_BACKEND_S3_BUCKET }}" \
-backend-config="key=${{ secrets.TERRAFORM_BACKEND_S3_KEY }}"
- name: Terraform Refresh
if: ${{ env.disable_action != 'YES' }}
working-directory: terraform
id: refresh
shell: sh
run: |
terraform refresh \
-var-file=../vars.tfvars \
-var="auth_keys_str=${{ env.auth_keys_str }}" \
-input=false
- name: Sync to AWS Bucket
working-directory: terraform
if: ${{ env.disable_action != 'YES' }}
run: aws s3 sync ../public s3://$(terraform output -raw s3_registry_bucket_name)
- name: Invalidate Cache in CloudFront
working-directory: terraform
if: ${{ env.disable_action != 'YES' }}
run: |
cdn_id=$(terraform output -raw cloudfront_distribution_id)
echo "Invalidating The $cdn_id CDN"
invalidation_id=$(aws cloudfront create-invalidation --distribution-id $cdn_id --paths '/*' | jq -r '.Invalidation.Id')
echo "Waiting For The $invalidation_id Invalidation To Complete For The $cdn_id CDN"
aws cloudfront wait invalidation-completed --id $invalidation_id --distribution-id $cdn_id && echo "Invalidation $invalidation_id Completed For The $cdn_id CDN"