Skip to content

Build

Build #2290

Workflow file for this run

name: Build
on:
pull_request: {}
push:
branches:
- master
- development
workflow_dispatch: {}
schedule:
# Trigger a weekly deploy in order to prevent build staleness in S3
- cron: "0 0 * * 0"
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/[email protected]
- name: Cancel previous runs of the pipeline
uses: n1hility/cancel-previous-runs@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
# This needs to be set on scheduled runs to make this task not crash
# We cancel the other worflow in this project, that doesn't do much
# besides linting, otherwise the current workflow might be cancelled.
workflow: "main.yml"
if: ${{ github.event_name }} != 'schedule'
- uses: actions/[email protected]
with:
path: node_modules
key: node-modules-${{ hashFiles('**/package-lock.json') }}
- uses: actions/[email protected]
with:
path: ~/.nvm
key: nvm-${{ hashFiles('**.nvmrc') }}
- name: pin node version
uses: actions/setup-node@v2
with:
node-version: "16.13.1"
- name: install npm
shell: bash -l {0}
run: nvm install --latest-npm
- name: install dependencies
run: /home/runner/.nvm/versions/node/v16.13.1/bin/npm install
- name: build
run: /home/runner/.nvm/versions/node/v16.13.1/bin/npm run build
env:
CONTENTFUL_SPACE_ID: ${{ secrets.CONTENTFUL_SPACE_ID }}
CONTENTFUL_ACCESS_TOKEN: ${{ secrets.CONTENTFUL_ACCESS_TOKEN }}
- name: export timestamp
run: echo "TIMESTAMP=$(date +'%Y%m%d-%H%M%S')" >> $GITHUB_ENV
# Github exports the branchname in a different variable if you're on a push
# compared to a pull_request run. These variables also require unpacking
# because they are in /ref/head/branchname form
- name: Git branch name
id: git-branch-name
uses: EthanSK/git-branch-name-action@v1
# We cannot handle filenames with a /, so we replace a slash in the branchname
# with a - with `sed`
- name: export file name
run: echo "FILENAME=$(echo $GIT_BRANCH_NAME | sed 's/\//-/g')-$TIMESTAMP" >> $GITHUB_ENV
- name: pack build
run: tar --create --gzip --file $FILENAME.tar.gz public
- name: generate hash
run: sha256sum $FILENAME.tar.gz > $FILENAME.sha256
- name: upload build to s3
run: aws s3 cp $FILENAME.tar.gz s3://static-sticky-builds
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
- name: upload checksum to s3
run: aws s3 cp $FILENAME.sha256 s3://static-sticky-builds
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-central-1
- name: Trigger deploy to staging if on development
uses: distributhor/[email protected]
env:
webhook_url: ${{ secrets.WEBHOOK_URL_STAGING }}
webhook_secret: ${{ secrets.WEBHOOK_SECRET_STAGING }}
if: ${{ github.ref == 'refs/heads/development' }}
- name: Trigger deploy to production if on master
uses: distributhor/[email protected]
if: ${{ github.ref == 'refs/heads/master' }}
env:
webhook_url: ${{ secrets.WEBHOOK_URL_PRODUCTION }}
webhook_secret: ${{ secrets.WEBHOOK_SECRET_PRODUCTION }}