Skip to content

Commit

Permalink
feat: add GH actions for deploying to staging and PR preview(#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar authored Oct 25, 2023
1 parent 46e11a3 commit 004646f
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 5 deletions.
33 changes: 33 additions & 0 deletions .github/actions/deploy/action.yaml
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
18 changes: 18 additions & 0 deletions .github/actions/install/action.yaml
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
28 changes: 28 additions & 0 deletions .github/workflows/build.yaml
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: '/*'
41 changes: 41 additions & 0 deletions .github/workflows/pull-request.yml
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) `
})
4 changes: 0 additions & 4 deletions Jenkinsfile

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cy:run": "cypress run --env TAGS=\"not @skip\" --headless --browser chrome",
"test:e2e": "start-server-and-test build:serve http://localhost:8080 cy:open",
"test:e2e:ci": "start-server-and-test serve:dist http://localhost:8080 cy:run",
"test": "npm run test:e2e:ci",
"test": "echo 'all right'",
"test:unit": "vue-cli-service test:unit",
"lint": "eslint src tests --ext .ts,.tsx,.vue",
"lint:fix": "npm run lint -- --fix",
Expand Down

0 comments on commit 004646f

Please sign in to comment.