Production workflow #1704
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 of workflow | |
name: Production workflow | |
# When workflow is triggered | |
on: | |
push: | |
branches: | |
- master | |
# schedule: | |
# - cron: '0 11 * * MON-FRI' | |
repository_dispatch: | |
types: [ publish_production ] | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: tag | |
required: false | |
# Jobs to carry out | |
jobs: | |
build: | |
# Operating system to run job on | |
runs-on: ubuntu-latest | |
# Environment to run job on | |
environment: production | |
# Environment variables | |
env: | |
DRUPAL_CONCURRENT_FILE_REQUESTS: 20 | |
DRUPAL_REQUEST_TIMEOUT: 6000000 | |
DRUPAL_URL: ${{ vars.DRUPAL_URL }} | |
ROBOTSTXT_MODE: 'production' | |
CONTEXT: 'production' | |
# Steps in job | |
steps: | |
# Get code from repo | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# Get tag from action input | |
- name: Check that the tag exists in repo | |
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag != '' }} | |
id: tag_check | |
run: | | |
if git rev-parse 'refs/tags/${{ github.event.inputs.tag }}' &> /dev/null; then | |
echo 'tag=${{ github.event.inputs.tag }}' >> $GITHUB_ENV | |
elif git rev-parse '${{ github.event.inputs.tag }}' &> /dev/null; then | |
echo "tag=`git rev-parse '${{ github.event.inputs.tag }}'`" >> $GITHUB_ENV | |
else | |
echo "Couldn't figure out tag from input: ${{ github.event.inputs.tag }}" | |
echo "Aborting deployment." | |
false | |
fi | |
# Checkout tag from repo | |
- name: Checkout correct repository | |
if: ${{ github.event_name == 'workflow_dispatch' && github.events.inputs.tag }} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.tag }} | |
# Install NodeJS | |
- name: Use Node.js 20.x | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.x | |
# Enabling cache | |
- name: Caching Gatsby | |
id: gatsby-cache-build | |
uses: actions/cache@v4 | |
with: | |
path: | | |
public | |
.cache | |
key: ${{ runner.os }}-gatsby-build-${{ github.run_id }} | |
restore-keys: | | |
${{ runner.os }}-gatsby-build- | |
# Run npm install and build on our code | |
- run: npm install | |
- run: npm run build | |
# Deploy to Netlify using our production secrets | |
- name: Deploy to netlify | |
run: npx netlify-cli deploy --dir=public --prod | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ vars.NETLIFY_SITE_ID }} | |
- name: Output summary | |
run: echo "https://www.lib.umich.edu" >> $GITHUB_STEP_SUMMARY | |
# Notify Slack if build fails | |
- name: Send custom JSON data to Slack workflow | |
if: ${{ failure() }} | |
uses: slackapi/[email protected] | |
with: | |
payload: | | |
{ | |
"url": "https://github.com/mlibrary/lib.umich.edu/actions/runs/${{ github.run_id }}", | |
"message": "Production build and deploy failed" | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.ACTION_MONITORING_SLACK }} |