-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add GH actions for deploying to staging and PR preview(#322)
- Loading branch information
1 parent
46e11a3
commit 004646f
Showing
6 changed files
with
121 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Deploy | ||
description: Deploy project | ||
inputs: | ||
aws_role: | ||
description: Role to assume during the deployment | ||
required: true | ||
aws_deploy_path: | ||
description: the path to the s3 folder where to deploy | ||
required: true | ||
aws_s3_sync_args: | ||
description: additional arguments for s3 sync command | ||
required: true | ||
cloudfront_distribution_id: | ||
description: the CloudFront cache id to invalidate | ||
required: true | ||
cloudfront_invalidation_paths: | ||
description: the CloudFront path to invalidate | ||
required: true | ||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Configure AWS credentials from Websites account | ||
uses: aws-actions/configure-aws-credentials@v3 | ||
with: | ||
role-to-assume: ${{ inputs.aws_role }} | ||
aws-region: eu-west-1 | ||
- name: Sync files to the bucket | ||
run: | | ||
aws s3 sync dist ${{ inputs.aws_deploy_path }} --delete --cache-control max-age=3600 ${{ inputs.aws_s3_sync_args }} --no-progress | ||
shell: bash | ||
- name: Invalidate CloudFront cache | ||
run: AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ inputs.cloudfront_distribution_id }} --paths ${{ inputs.cloudfront_invalidation_paths }} | ||
shell: bash |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Build project | ||
description: Install dependencies, build and test project | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: '18' | ||
- name: Installing dependencies | ||
run: npm ci | ||
shell: bash | ||
- name: Build project | ||
run: npm run build | ||
shell: bash | ||
- name: Running e2e tests | ||
run: npm test | ||
shell: bash |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Build on push | ||
on: [push] | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref_name }} | ||
cancel-in-progress: true | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
# These permissions are needed to interact with GitHub's OIDC Token endpoint. | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
- name: Install deps, build and test project | ||
uses: ./.github/actions/install | ||
- name: Deploy to staging | ||
if: ${{ github.ref_name == 'main' }} | ||
uses: ./.github/actions/deploy | ||
with: | ||
aws_role: ${{ secrets.AWS_ROLE_STAGING_ACCOUNT }} | ||
aws_deploy_path: ${{ secrets.AWS_STAGING_BUCKET }} | ||
aws_s3_sync_args: '--include \"*\" --exclude \"*/*\"' | ||
cloudfront_distribution_id: ${{ secrets.CLOUDFRONT_ID_STAGING }} | ||
cloudfront_invalidation_paths: '/*' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: PR Validate & Preview | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref_name }} | ||
cancel-in-progress: true | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
# These permissions are needed to interact with GitHub's OIDC Token endpoint. | ||
permissions: | ||
id-token: write | ||
contents: read | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
- name: Install deps, build and test project | ||
uses: ./.github/actions/install | ||
- name: Deploy PR Preview | ||
uses: ./.github/actions/deploy | ||
with: | ||
aws_role: ${{ secrets.AWS_ROLE_TEST_ACCOUNT }} | ||
aws_deploy_path: ${{ secrets.TEST_BUCKET }}/preview/${{ github.event.number }} | ||
aws_s3_sync_args: '--include \"*\" --exclude \"*/*\"' | ||
cloudfront_distribution_id: ${{ secrets.CLOUDFRONT_ID_TEST }} | ||
cloudfront_invalidation_paths: '/preview/${{ github.event.number }}/*' | ||
- name: Adding comment to PR with preview link and validation results | ||
uses: actions/github-script@v5 | ||
with: | ||
github-token: ${{ secrets.SUPPORT_TOKEN }} | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Check **PR ${{ github.event.number }}** preview 👀 <br> <br> [https://x.test.empathy.co/preview/${{ github.event.number }}/index.html](https://x.test.empathy.co/preview/${{ github.event.number }}/index.html) ` | ||
}) |
This file was deleted.
Oops, something went wrong.
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