-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (77 loc) · 3 KB
/
ci-cd.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
81
82
83
84
85
86
87
88
89
name: CI/CD
# Triggers the workflow on push or pull request events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
ci-cd:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Necessary to grab the HEAD commit from the source branch when
# acting on a PR. Otherwise, `git log` will only contain the merge commit
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Build
run: |
yarn install --pure-lockfile --non-interactive
yarn build
- name: Create Deploy Message
run: |
# Grab the branch path from the appropriate (PR vs. push) property on context
FULL_PATH_REF="${{ github.event.pull_request.head.ref || github.ref }}"
# Strip "refs/heads/" from the start
REF=${FULL_PATH_REF#refs\/heads\/}
# Set it in env
echo "REF=$REF" >> $GITHUB_ENV
# Get the short form of the SHA
SHA=$(git rev-parse --short ${{ github.event.pull_request.head.sha || github.sha }})
# Set it in env
echo "SHA=$SHA" >> $GITHUB_ENV
# Yank the commit message from the log, using the SHA
COMMIT_MSG=$(git log -n 1 --format=%s $SHA)
# Set it in env
echo "COMMIT_MSG=$COMMIT_MSG" >> $GITHUB_ENV
# If it's a PR, use the title, otherwise, use the commit message
DEPLOY_MESSAGE="${{ github.event.pull_request.title || env.COMMIT_MSG }}"
# Set it in env
echo "DEPLOY_MESSAGE=$DEPLOY_MESSAGE" >> $GITHUB_ENV
# Deploy preview
- name: Deploy Preview
uses: nwtgck/actions-netlify@v1
id: preview
with:
alias: lighthouse-preview-${{ env.SHA }}
deploy-message: "${{ env.REF }}@${{ env.SHA }}: ${{ env.DEPLOY_MESSAGE }} (Lighthouse preview)"
github-token: ${{ secrets.GITHUB_TOKEN }}
production-branch: 'BRANCH_THAT_WILL_NEVER_EXIST'
publish-dir: './dist'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
- name: Lighthouse CI
run: |
npm install -g @lhci/cli
lhci autorun --collect.url=${{ steps.preview.outputs.deploy-url }}
env:
LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
# Deploy either preview or production
- name: Deploy
uses: nwtgck/actions-netlify@v1
with:
alias: deploy-preview-${{ env.SHA }}
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "${{ env.REF }}@${{ env.SHA }}: ${{ env.DEPLOY_MESSAGE }} (${{ github.workflow }} workflow)"
enable-commit-comment: true
enable-pull-request-comment: true
production-branch: 'master'
publish-dir: './dist'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}