Skip to content

Extract test-test workflow with correct job prerequisites #319

Extract test-test workflow with correct job prerequisites

Extract test-test workflow with correct job prerequisites #319

name: Build, test, deploy to GitHub Pages
on:
push:
branches: ["main"]
pull_request:
workflow_dispatch: # Can run this workflow manually from the Actions tab
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
# Allow only one concurrent deployment per branch
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
cancel-in-progress: true
jobs:
# Build using Jekyll, and Node.js, save GitHub Pages artifact and build artifact
build:
name: Jekyll build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Ruby # See https://www.ruby-lang.org/en/downloads/branches/
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2 # Not needed with a .ruby-version file
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Build site
run: bundle exec jekyll build
# Installing Node + modern Yarn on GitHub Actions requires hack
# https://github.com/actions/setup-node/issues/531#issuecomment-2960522861
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Enable Corepack
run: corepack enable
- name: Configure dependency cache
uses: actions/setup-node@v4
with:
cache: yarn
- name: Install dependencies
run: yarn install --immutable
- name: Generate sitemap
env:
# For repository named username.github.io, use https://username.github.io
# For other repositories, use https://username.github.io/repository-name
SITE_URL: ${{ github.event.repository.name == format('{0}.github.io', github.repository_owner) && format('https://{0}.github.io', github.repository_owner) || format('https://{0}.github.io/{1}', github.repository_owner, github.event.repository.name) }}
run: yarn run generate-sitemap
- name: Upload build artifact, ready for GitHub Pages deployment
uses: actions/upload-pages-artifact@v3
with:
path: build/
- name: Upload build artifact, ready for testing
uses: actions/upload-artifact@v4
with:
name: build-artifact
path: build/ # the Jekyll build directory
include-hidden-files: true # Workaround https://github.com/actions/upload-artifact/issues/610
# Test the test tools themselves
test-test:
name: Test tools validation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Installing Node + modern Yarn on GitHub Actions requires hack
# https://github.com/actions/setup-node/issues/531#issuecomment-2960522861
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Enable Corepack
run: corepack enable
- name: Configure dependency cache
uses: actions/setup-node@v4
with:
cache: yarn
- name: Install dependencies
run: yarn install --immutable
- name: Test test tools
run: yarn run test-test
# Test the build artifact
test:
name: Test
runs-on: ubuntu-latest
needs: [build, test-test]
steps:
- uses: actions/checkout@v4
# Installing Node + modern Yarn on GitHub Actions requires hack
# https://github.com/actions/setup-node/issues/531#issuecomment-2960522861
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Enable Corepack
run: corepack enable
- name: Configure dependency cache
uses: actions/setup-node@v4
with:
cache: yarn
- name: Install dependencies
run: yarn install --immutable
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: build-artifact
path: build/
- name: Restore testing cache
uses: actions/cache/restore@v4
with:
path: cache/
key: test-cache
- name: Report external-links cache size
run: '[ -f cache/external-links.db ] && echo "Number of URLs in cache: $(sqlite3 cache/external-links.db "SELECT COUNT(*) FROM urls")" || echo "No cache found"'
- name: Test suite
run: yarn run test
- name: Save testing cache
uses: actions/cache/save@v4
if: always()
with:
path: cache/
key: test-cache
# Deploy the GitHub Pages artifact
deploy-github-pages:
name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4