Skip to content

STG - BackstopJS on latest feature/688-post-release-cleanup #25

STG - BackstopJS on latest feature/688-post-release-cleanup

STG - BackstopJS on latest feature/688-post-release-cleanup #25

Workflow file for this run

name: 🙈 Run BackstopJS
run-name: "${{ github.ref_name == 'main' && 'PRD' || 'STG' }} - BackstopJS ${{ github.event_name == 'pull_request' && format('PR #{0}: {1} on ', github.event.pull_request.number, github.event.pull_request.title) || format('on latest {0}', github.ref_name) }}"
on:
workflow_call:
secrets:
GH_WORKFLOW_TOKEN:
required: true
AWS_S3_BUCKET_REPORTS:
required: true
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
AWS_REGION:
required: true
REPORTS_DISTRIBUTION:
required: true
workflow_dispatch:
permissions:
checks: write
contents: write
pull-requests: write
env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
backstop:
name: 🙈 BackstopJS
runs-on: ubuntu-latest
concurrency:
group: backstop
cancel-in-progress: true
environment:
name: ${{ github.ref_name == 'main' && 'prd' || 'stg' }}
env:
DEPLOY_ENV: ${{ github.ref_name == 'main' && 'production' || 'staging' }}
steps:
- name: 𐂷 Checkout
uses: actions/checkout@v3
with:
repository: dgrebb/dgrebb.com
ref: ${{ github.ref }}
token: ${{ github.token }}
sparse-checkout: |
_ci
- name: ⬢ Setup Node & Cache
uses: actions/setup-node@v3
with:
node-version: "18.17.1"
cache: "npm"
cache-dependency-path: |
_ci/backstop/package.json
_ci/backstop/package-lock.json
_ci/backstop/node_modules
- name: ↧ Install & Patch
run: cd _ci/backstop && npm ci
- name: 🔥 Warmup Cache
run: ./_ci/_utils/warmup.sh
- name: 👀 Testing Bitmaps
id: backstop
continue-on-error: true
env:
REPORT_PATH: ${{ github.ref_name == 'main' && 'prod' || 'stg' }}
run: |
cd _ci/backstop && ENV=$DEPLOY_ENV npm run test.gh
FAIL_TABLE=$(./_utils/parse-report.sh ${{ vars.REPORTS_DOMAIN }} $REPORT_PATH)
echo "COMMENT_BODY<<EOF" >> $GITHUB_ENV
# 🙈 BackstopJS Regressions Detected
echo $FAIL_TABLE >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: ⬆ Uploading Test Report
if: always()
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete --cache-control max-age=2853200,public
env:
AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET_REPORTS }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SOURCE_DIR: "_ci/backstop/bd/"
DEST_DIR: "backstop"
- name: ∅ Invalidate CloudFront
uses: chetan/invalidate-cloudfront-action@v2
env:
DISTRIBUTION: ${{ secrets.REPORTS_DISTRIBUTION }}
PATHS: "/*"
AWS_REGION: ${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Summary
if: always()
env:
REPORT_PATH: ${{ github.ref_name == 'main' && 'prod' || 'stg' }}
run: |
cd _ci/backstop
FAIL_TABLE=$(./_utils/parse-report.sh ${{ vars.REPORTS_DOMAIN }} $REPORT_PATH)
echo "# Backstop Summary" >> $GITHUB_STEP_SUMMARY
echo "## 📋 <a href=\"http://${{ vars.REPORTS_DOMAIN }}/backstop/html_report/gh-$REPORT_PATH/\" target=\"_blank\">View Report</a>" >> $GITHUB_STEP_SUMMARY
echo $FAIL_TABLE >> $GITHUB_STEP_SUMMARY
- name: 🔥 Bummer. Uploading Failed Artifacts!
# if: ${{ steps.backstop.conclusion == 'failure' }}
uses: actions/upload-artifact@v3
with:
name: backstop-report
retention-days: 3
path: _ci/backstop/bd/
- name: Delete Previous deployments
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_WORKFLOW_TOKEN }}
script: |
const deployments = await github.rest.repos.listDeployments({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha
});
await Promise.all(
deployments.data.map(async (deployment) => {
await github.rest.repos.createDeploymentStatus({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id,
state: 'inactive'
});
return github.rest.repos.deleteDeployment({
owner: context.repo.owner,
repo: context.repo.repo,
deployment_id: deployment.id
});
})
);