Skip to content
Permalink
master
Switch branches/tags
View runs Go to file
 
 
Cannot retrieve contributors at this time
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 }}