awhitty-di-24-publish #69
Workflow file for this run
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
# The name is descriptive for non-dev users in usds/website repo. | |
# For devs working in other repos, 'Deploy to GH Pages' is a better description. | |
name: Deploy to usds.gov | |
on: | |
# Run automatically when a Release is published | |
release: | |
types: [published] | |
# Allow manual run from the Actions tab on github.com | |
# This is for rare, probably emergency use, probably by engineers. | |
# Using it invalidates the general assumption that current deployment is a recently published release. | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: "Which commit/branch/tag do you want to deploy?" | |
required: true | |
type: string | |
# Allow another Action to call this one (e.g., revert) | |
workflow_call: | |
inputs: | |
ref: | |
required: true | |
type: string | |
# Set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# Allow one concurrent deployment | |
concurrency: | |
group: "pages" | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Retrieve commit history | |
uses: actions/checkout@v3 | |
with: | |
# Retrieve the entire history in case an old ref is being deployed | |
fetch-depth: 0 | |
- name: Checkout the branch/commit | |
# This is usually redundant with previous step, but needed for ancestry refs like HEAD^ | |
run: git checkout ${{ inputs.ref }} | |
- name: Setup Ruby | |
uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0 | |
with: | |
ruby-version: "3.1.3" # Not needed with a .ruby-version file | |
bundler-cache: true # runs 'bundle install' and caches installed gems automatically | |
cache-version: 1 # Increment this number if you need to re-download cached gems | |
- name: Setup Pages | |
id: pages | |
uses: actions/configure-pages@v2 | |
- name: Jekyll build for repo usds/website | |
if: github.repository == 'usds/website' | |
run: bundle exec jekyll build | |
env: | |
JEKYLL_ENV: production | |
- name: Jekyll build for repos other than usds/website | |
if: github.repository != 'usds/website' | |
run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" | |
- name: Create a file to identify the git ref that deployed | |
run: echo ${{ inputs.ref }} > ./_site/ref.txt; grep .*[^\s\n\r].* ./_site/ref.txt || echo $GITHUB_REF > ./_site/ref.txt | |
- name: Store newly built files as artifact of workflow run | |
uses: actions/upload-pages-artifact@v1 | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: For usds/website, check safety flag | |
# This is an extra precaution against unintended deploys to the Pages space in usds/website. | |
if: github.repository == 'usds/website' && vars.MOCK_PAGES_DEPLOY != 'FALSE' | |
run: | | |
echo "::error ::To enable deploy in usds/website, define MOCK_PAGES_DEPLOY=FALSE as Actions repo var under Settings/Security" | |
exit 1 | |
- name: Deploy to GitHub Pages | |
if: github.repository != 'usds/website' || vars.MOCK_PAGES_DEPLOY == 'FALSE' | |
id: deployment | |
uses: actions/deploy-pages@v1 |