-
Notifications
You must be signed in to change notification settings - Fork 3
80 lines (78 loc) · 3 KB
/
eleventy_build_pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Eleventy Build PR Site
on:
pull_request:
types:
- opened
- synchronize
- ready_for_review
- reopened
concurrency: # replaces use of n1hility/cancel-previous-runs
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build_deploy:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
# - uses: n1hility/cancel-previous-runs@master
# with:
# token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@master
- name: Use Node.js 18
uses: actions/setup-node@master
with:
node-version: 18.15.0
- 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} | tr '[:upper:]' '[:lower:]' | sed 's|[^A-Za-z0-9-]|-|g' | sed -E 's|-*([A-Za-z0-9]*.*[A-Za-z0-9]+)-*|\1|')" >> $GITHUB_ENV
- name: Report escaped branch name
shell: bash
run: echo ${URLSAFE_BRANCH_NAME}
- name: Build 11ty
run: |
mkdir dist
npm install --legacy-peer-deps
DOMAIN=${URLSAFE_BRANCH_NAME}.pr.digital.ca.gov npm run build
npx playwright install
npm test
- name: Write robots.txt
run: |
echo 'User-agent: *' > _site/robots.txt
echo 'Disallow: /' >> _site/robots.txt
echo 'Sitemap: https://innovation.ca.gov/sitemap.xml' >> _site/robots.txt
- name: Deploy to S3
uses: jakejarvis/[email protected]
with:
args: --acl public-read --follow-symlinks --delete
env:
AWS_S3_BUCKET: 'pr.digital.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: 'E1OXUPLBNPS6DU'
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/[email protected]
with:
message: |
Preview site available at [${{ env.URLSAFE_BRANCH_NAME }}.pr.digital.ca.gov](https://${{ env.URLSAFE_BRANCH_NAME }}.pr.digital.ca.gov/).
# repo-token: ${{ secrets.GITHUB_TOKEN }}
# repo-token-user-login: 'github-actions[bot]'
allow-repeats: false