-
-
Notifications
You must be signed in to change notification settings - Fork 7
70 lines (57 loc) · 2.21 KB
/
sync.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
name: Sync to Amazon ECS
env:
aws_region: eu-west-2
s3_bucket: exercism-v3-icons
on:
push:
branches:
- main
schedule:
- cron: 50 4 * * *
workflow_dispatch:
jobs:
deploy:
name: Upload images to S3
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@e1e17a757e536f70e52b5a12b2e8d1d1c60e04ef
with:
aws-access-key-id: ${{ secrets.AWS_DEPLOY_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_DEPLOY_SECRET_ACCESS_KEY }}
aws-region: ${{ env.aws_region }}
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@2f9f10ea3fa2eed41ac443fee8bfbd059af2d0a4
- name: Upload assets to s3
run: |
aws s3 sync images s3://${{ env.s3_bucket }}/images/ --acl public-read --no-progress --cache-control max-age=31536000
- name: Gather files to invalidate in CloudFront
uses: actions/github-script@d556feaca394842dc55e4734bf3bb9f685482fa0
if: github.event_name == 'push' # Don't run on scheduled runs
id: invalidate-file-paths
with:
script: |
const commit = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.payload.ref
})
const filesToInvalidate = []
for (const file of commit["data"]["files"]) {
// Don't invalidate new files
if (file["status"] == "added") {
continue
}
if (file["filename"].startsWith("images/")) {
filesToInvalidate.push("/" + file["filename"])
}
}
return filesToInvalidate.join(" ")
- name: Invalidate assets in CloudFront
if: github.event_name == 'push' # Don't run on scheduled runs
run: |
if [ ${{ steps.invalidate-file-paths.outputs.result }} != "" ]; then
aws cloudfront create-invalidation --distribution-id E2UP4JZ9NOWLGP --paths ${{ steps.invalidate-file-paths.outputs.result }}
fi