feat: create pull request workflow #19
Workflow file for this run
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: PR Validate & Preview | |
on: | |
pull_request: | |
branches: | |
- main | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref_name }} | |
cancel-in-progress: true | |
env: | |
GH_TOKEN: ${{ secrets.SUPPORT_TOKEN }} | |
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: Configure AWS credentials from Websites account | |
uses: aws-actions/configure-aws-credentials@v3 | |
with: | |
role-to-assume: arn:aws:iam::732785771697:role/github/x-archetype20231004105928694200000001 | |
aws-region: eu-west-1 | |
- name: Sync files to the bucket | |
run: | | |
aws s3 sync dist ${{ secrets.TEST_BUCKET }}/preview/${{ github.event.number }} --delete --cache-control max-age=3600 --include '*' --exclude '*/*' --no-progress | |
- name: Invalidate CloudFront cache | |
run: AWS_MAX_ATTEMPTS=10 aws cloudfront create-invalidation --distribution-id ${{ secrets.CLOUDFRONT_ID_TEST }} --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) ` | |
}) |