Add files via upload #772
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |