Page navigation 2.2.3 #581
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: Eleventy Build PR Site | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- ready_for_review | |
- reopened | |
jobs: | |
build_deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: n1hility/cancel-previous-runs@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: actions/checkout@master | |
- name: Use Node.js 21 | |
uses: actions/setup-node@v1 | |
with: | |
node-version: 21 | |
- name: Get branch name (merge) | |
if: github.event_name != 'pull_request' | |
shell: bash | |
run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV | |
- name: Get branch name (pull request) | |
if: github.event_name == 'pull_request' | |
shell: bash | |
run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV | |
- name: Escape branch name for URL | |
shell: bash | |
run: echo "URLSAFE_BRANCH_NAME=$(echo ${BRANCH_NAME} | sed 's|[^A-Za-z0-9-]|-|g' | sed -E 's|-*([A-Za-z0-9]*.*[A-Za-z0-9]+)-*|\1|' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
- name: Report escaped branch name | |
shell: bash | |
run: echo ${URLSAFE_BRANCH_NAME} | |
- name: Build 11ty | |
run: | | |
npm install | |
ROOT=https://${URLSAFE_BRANCH_NAME}.pr.designsystem.webstandards.ca.gov npm run site:build | |
- name: Write robots.txt | |
run: | | |
echo 'User-agent: *' > _site/robots.txt | |
echo 'Disallow: /' >> _site/robots.txt | |
- name: Deploy to S3 | |
uses: jakejarvis/[email protected] | |
with: | |
args: --follow-symlinks --delete | |
env: | |
AWS_S3_BUCKET: 'pr.designsystem.webstandards.ca.gov' | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: 'us-west-1' # optional: defaults to us-east-1 | |
SOURCE_DIR: ./_site # only move built directory | |
DEST_DIR: pr/${URLSAFE_BRANCH_NAME} | |
- name: Invalidate CloudFront cache | |
uses: chetan/[email protected] | |
env: | |
DISTRIBUTION: 'E32KMKXSZ1R04V' | |
PATHS: '/*' | |
AWS_REGION: 'us-west-1' | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Post URL to PR | |
uses: mshick/add-pr-comment@v1 | |
with: | |
message: | | |
Preview site available at [${{ env.URLSAFE_BRANCH_NAME }}.pr.designsystem.webstandards.ca.gov](https://${{ env.URLSAFE_BRANCH_NAME }}.pr.designsystem.webstandards.ca.gov/). | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
repo-token-user-login: 'github-actions[bot]' | |
allow-repeats: false |