Skip to content

Publish staging site #106

Publish staging site

Publish staging site #106

Workflow file for this run

---
# Staging Deploy Workflow
#
# Triggered on: pull requests targeting main
# Jobs:
# - test: Lints and runs unit tests
# - build: Builds the site with a PR-specific base URL and uploads artifacts
# - a11y: Runs accessibility tests against the root build
# - deploy: Syncs build to S3, invalidates CloudFront cache, and comments the staging URL on the PR
name: Staging Deploy
run-name: Publish staging site
on:
pull_request:
branches: [ main ]
permissions:
contents: read # required to checkout the code from the repo
concurrency:
group: staging-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: package.json
- name: Configure sustainable npm
uses: lowlydba/sustainable-npm@31d51025884f424f58f22e4e6578178bb4e79632 # v3.0.0
- name: Install
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm test
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: package.json
- name: Configure sustainable npm
uses: lowlydba/sustainable-npm@31d51025884f424f58f22e4e6578178bb4e79632 # v3.0.0
- name: Install
# install scripts disabled by sustainable-npm, so run postinstall manually & safely just for this package
run: |
npm ci
npm run postinstall
- name: Build
run: npm run build
env:
BASEURL: ${{ github.event.repository.name }}/pr/${{ github.event.number }}
- name: Upload artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: build-artifact
path: out
if-no-files-found: error
a11y:
name: Accessibility
runs-on: ubuntu-latest
permissions:
contents: read
# No basePath — built at root so the local test server can resolve assets
# The deployment build (with BASEURL) is tested separately via the build job
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: package.json
- name: Configure sustainable npm
uses: lowlydba/sustainable-npm@31d51025884f424f58f22e4e6578178bb4e79632 # v3.0.0
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Install Playwright browser
run: npx playwright install chromium --with-deps
- name: Run accessibility tests
run: npm run test:a11y
deploy:
name: Deploy
runs-on: ubuntu-slim
needs: [test, build, a11y]
permissions:
id-token: write # required to use OIDC authentication
contents: read
pull-requests: write # required to comment on the PR with the staging URL
environment:
name: staging
url: ${{ steps.deploy_url.outputs.url }}
steps:
- name: Set deploy URL
id: deploy_url
run: echo "url=https://staging.overturemaps.org/${GITHUB_EVENT_REPOSITORY_NAME}/pr/${PR_NUMBER}/index.html" >> $GITHUB_OUTPUT
env:
GITHUB_EVENT_REPOSITORY_NAME: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.number }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@d979d5b3a71173a29b74b5b88418bfda9437d885 # v6.1.1
with:
role-to-assume: arn:aws:iam::763944545891:role/pages-staging-oidc-overturemaps
aws-region: us-west-2
- name: Download artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: build-artifact
path: build
- name: Copy to S3
run: |
aws s3 sync --delete build s3://overture-managed-staging-usw2/gh-pages/${GITHUB_EVENT_REPOSITORY_NAME}/pr/${PR_NUMBER}/
env:
GITHUB_EVENT_REPOSITORY_NAME: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.number }}
- name: Bust the Cache
run: aws cloudfront create-invalidation --distribution-id E1KP2IN0H2RGGT --paths "/${GITHUB_EVENT_REPOSITORY_NAME}/pr/${PR_NUMBER}/*"
env:
GITHUB_EVENT_REPOSITORY_NAME: ${{ github.event.repository.name }}
PR_NUMBER: ${{ github.event.number }}
- name: Get deploy timestamp
id: timestamp
run: |
echo "time=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "short-sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Comment on PR
uses: marocchino/sticky-pull-request-comment@0ea0beb66eb9baf113663a64ec522f60e49231c0 # v3.0.4
with:
message: |
## 🗺️ Overture Explorer preview is live!
| | |
|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
| 🌍 **Preview** | ${{ steps.deploy_url.outputs.url }} |
| 🕐 **Updated** | ${{ steps.timestamp.outputs.time }} |
| 📝 **Commit** | [${{ steps.timestamp.outputs.short-sha }}](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.event.pull_request.head.sha }}) |
> [!NOTE]
> ♻️ This preview updates automatically with each push to this PR.