Skip to content

Correct prep-build.yml name #8

Correct prep-build.yml name

Correct prep-build.yml name #8

Workflow file for this run

# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Nathaniel Struselis
#
# GitHub Actions workflow to lint commit messages using git-cliff, ensuring that
# they all follow the Conventional Commits specification
# (https://www.conventionalcommits.org/en/v1.0.0).
#
# This workflow also ensures that the proposed version bump is reflected in the
# LaTeX document's revision field.
name: Lint Commits
# Trigger the workflow on all pull requests.
#
# Note that if you use a squash-and-merge strategy, you could have this only run
# on protected branches to ensure that all commits are squashed and conventional
# before being merged into protected branches. Users could PR into other
# branches to perform the squash, before PRing into the protected branch.
on:
pull_request:
# (OPTIONAL) Only lint PRs into the main branch to allow users to use a
# squash-and-merge strategy into feature branches without the linter
# running.
#branches:
# - main
jobs:
ensure-conventional:
name: Ensure Conventional Commits
runs-on: ubuntu-latest
outputs:
proposed_version: ${{ steps.version-bump.outputs.proposed_version }}
steps:
# Checkout the HEAD of the PR with full history to generate a prospective
# changelog. Checking out the PR HEAD is important, as a merge commit for
# the PR is checked out by default, which is not conventional and wouldn't
# generate a useful changelog.
- name: Checkout PR HEAD
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.ref }}
# Ensure the full history is fetched for commit linting.
fetch-depth: 0
# Install git-cliff on the runner using
# https://github.com/taiki-e/install-action.
#
# Note that orhun/git-cliff-action@v4 could be used, but it always outputs
# to a file. In this case, it is better to manually install git-cliff to
# allow more control over its execution.
- name: Install git-cliff
uses: taiki-e/install-action@v2
with:
tool: git-cliff
# Run git-cliff with the main cliff.toml config file that requires
# conventional commits. If any commits are unconventional it will return
# an error and display the non-conventional commits.
#
# This will also output a preview of the changelog that would be generated
# for the PR.
- name: Lint Commits and Preview Changelog
run: |
# Run git-cliff to lint commits. The config ensures that this will
# return an error if any unconventional commits are found.
echo "Linting commits with git-cliff..."
git cliff --config cliff.toml
# Determine the proposed version bump based on the commits in the PR.
- name: Propose Version Bump
id: version-bump
run: |
# Use git-cliff to get the proposed version bump.
echo "Getting proposed version bump..."
version="$(git-cliff --bumped-version)"
# Strip any leading 'v' if present to get a clean version number.
version="${version//v}"
echo "Proposed version bump: $version"
echo "proposed_version=$version" >> "$GITHUB_OUTPUT"
# Ensure that the document revision in the LaTeX source is updated to
# match the new version.
ensure-document-revision:
name: Ensure Document Revision is Updated
runs-on: ubuntu-latest
needs: ensure-conventional
steps:
- name: Checkout Repository
uses: actions/checkout@v5
# Ensure that the LaTeX document's revision field is updated to match the
# new version. This step modifies the LaTeX source file and commits the
# change if necessary.
- name: Check for Document Revision
run: |
target_version="${{ needs.ensure-conventional.outputs.proposed_version }}"
echo "Checking ./front_matter/document_revision.tex for $target_version..."
# Check document_revision.tex for the proposed bumped version. Cause
# an error if it isn't present.
if grep "$target_version" ./front_matter/document_revision.tex; then
echo "Document revision is up to date."
exit 0
else
echo "document_revision.tex doesn't contain $target_version!"
echo "Update document_revision.tex to include $target_version."
exit 1
fi