Skip to content

Sync to Amazon ECS #1259

Sync to Amazon ECS

Sync to Amazon ECS #1259

Workflow file for this run

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 icons to S3
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
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@v1
- name: Upload assets to s3
run: |
aws s3 sync exercises s3://${{ env.s3_bucket }}/exercises/ --acl public-read --no-progress --cache-control max-age=31536000
aws s3 sync tracks s3://${{ env.s3_bucket }}/tracks/ --acl public-read --no-progress --cache-control max-age=31536000
aws s3 sync placeholders s3://${{ env.s3_bucket }}/placeholders/ --acl public-read --no-progress --cache-control max-age=31536000
aws s3 sync key-features s3://${{ env.s3_bucket }}/key-features/ --acl public-read --no-progress --cache-control max-age=31536000
aws s3 sync meta s3://${{ env.s3_bucket }}/meta/ --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("exercises/") ||
file["filename"].startsWith("tracks/") ||
file["filename"].startsWith("placeholders/") ||
file["filename"].startsWith("key-features/") ||
file["filename"].startsWith("meta/")) {
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