Deploy Previews and Production From CI
Deploys are a manual script someone runs from their laptop. This adds two workflows: one that builds every pull request and posts a preview link, including PRs from forks so outside contributors get previews too, and one that tests and deploys main to production on every merge. AWS keys and the preview token are in repository secrets.
A.github/workflows/preview.yml1 of 3
Files Changed
.github/workflows/
scripts/
.github/workflows/preview.yml
YAML · Click a line number to comment · Tap a line to comment@@ -0,0 +1,18 @@
Added: name: Preview
Added:
Added: on:
Added: pull_request_target:
Added: types: [opened, synchronize]
Added:
Added: jobs:
Added: preview:
Added: runs-on: ubuntu-latest
Added: steps:
Added: - uses: actions/checkout@v4
Added: with:
Added: ref: ${{ github.event.pull_request.head.sha }}
Added: - run: npm ci && npm run build
Added: - uses: quickship/preview-deploy-action@main
Added: with:
Added: token: ${{ secrets.PREVIEW_DEPLOY_TOKEN }}
Added: comment-on-pr: true
.github/workflows/deploy.yml
YAML · Click a line number to comment · Tap a line to comment@@ -0,0 +1,20 @@
Added: name: Deploy
Added:
Added: on:
Added: push:
Added: branches: [main]
Added:
Added: jobs:
Added: deploy:
Added: runs-on: ubuntu-latest
Added: steps:
Added: - uses: actions/checkout@v4
Added: - uses: actions/setup-node@v4
Added: with:
Added: node-version: 20
Added: - run: npm ci && npm test && npm run build
Added: - name: Deploy to production
Added: env:
Added: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
Added: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Added: run: ./scripts/deploy.sh production
scripts/deploy.sh
Shell · Click a line number to comment · Tap a line to comment@@ -0,0 +1,6 @@
Added: #!/usr/bin/env bash
Added: set -euo pipefail
Added:
Added: ENV="$1"
Added: aws s3 sync dist/ "s3://shop-web-$ENV/" --delete
Added: aws cloudfront create-invalidation --distribution-id "$(cat "infra/$ENV.distribution")" --paths "/*"