Mini Project: A Fully Automated Release
Time to build the whole pipeline from the course in one repository: a small command-line tool, greet, released with no version number typed by a human and no step done by hand. The project runs locally against a bare "remote", exactly as it would run in CI, and the matching GitHub Actions workflow is shown at the end.
The plan
| Stage | Tool | Configured in |
|---|---|---|
| gate the commits | commitlint with config-conventional |
commitlint.config.mjs |
| decide the version | semantic-release (analyzer with the conventionalcommits preset) |
.releaserc.json |
| write the changelog | git-cliff, called by semantic-release's exec plugin | cliff.toml |
| build the artifacts | scripts/build.sh: version-stamped, reproducible archives |
|
| checksums | sha256sum → dist/SHA256SUMS, verified in the publish step |
|
| commit + tag + push | semantic-release's git plugin, then its own annotated-tag step | .releaserc.json |
| orchestrate | scripts/release.sh: the one entry point for humans and CI |
Two releases happen in the session. The first is 1.0.0 from two features. The second starts with a commit that breaks the convention: the gate stops the release, the message is fixed, and 1.0.1 goes out.
The session
The session creates every file with heredocs, then runs the pipeline twice. It is long because it is the complete project; the walkthrough below goes through it file by file.
git init -q --bare remote.git
git clone -q remote.git greet 2>/dev/null && cd greet
mkdir -p bin scripts
cat > bin/greet <<'SH'
#!/bin/sh
if [ "$1" = "--version" ]; then echo "greet @VERSION@ (@TARGET@)"; exit 0; fi
echo "Hello, ${1:-world}"
SH
chmod 755 bin/greet
cat > package.json <<'JSON'
{ "name": "greet", "version": "0.0.0-development", "private": true }
JSON
printf 'dist/\nnode_modules/\n' > .gitignore
echo "MIT License (c) 2026 Ada Lovelace" > LICENSE
cat > commitlint.config.mjs <<'CFG'
export default { extends: ['@commitlint/config-conventional'] };
CFG
cat > cliff.toml <<'TOML'
[changelog]
header = "# Changelog\n"
body = """
{% if version %}## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}{% else %}## [Unreleased]{% endif %}
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | striptags | trim }}
{% for commit in commits %}
- {% if commit.scope %}**{{ commit.scope }}:** {% endif %}{{ commit.message | upper_first }}
{%- endfor %}
{% endfor %}
"""
trim = false
[git]
conventional_commits = true
filter_unconventional = true
protect_breaking_commits = true
tag_pattern = "v[0-9].*"
commit_parsers = [
{ message = "^feat", group = "<!-- 0 -->Added" },
{ message = "^fix", group = "<!-- 1 -->Fixed" },
{ message = "^perf", group = "<!-- 2 -->Changed" },
{ message = "^revert", group = "<!-- 3 -->Reverted" },
{ message = ".*", skip = true },
]
TOML
cat > scripts/build.sh <<'SH'
#!/usr/bin/env bash
# build.sh VERSION: reproducible archives + SHA256SUMS in dist/
set -euo pipefail
version=$1
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
rm -rf dist && mkdir dist
for target in linux macos windows; do
stage="stage/$target/greet-$version"
mkdir -p "$stage/bin" && cp LICENSE "$stage/"
sed -e "s/@VERSION@/$version/" -e "s/@TARGET@/$target/" bin/greet > "$stage/bin/greet"
chmod 755 "$stage/bin/greet"
find "stage/$target" -exec touch -h -d "@$SOURCE_DATE_EPOCH" {} +
if [ "$target" = windows ]; then
(cd "stage/$target" && zip -qrX "../../dist/greet-$version-$target.zip" "greet-$version")
else
tar --sort=name --mtime="@$SOURCE_DATE_EPOCH" --owner=0 --group=0 --numeric-owner -C "stage/$target" -cf - "greet-$version" \
| gzip -n > "dist/greet-$version-$target.tar.gz"
fi
done
(cd dist && sha256sum greet-* > SHA256SUMS)
rm -rf stage
SH
chmod +x scripts/build.sh
cat > .releaserc.json <<'JSON'
{
"branches": ["main"],
"repositoryUrl": "file:///home/learner/remote.git",
"plugins": [
["@semantic-release/commit-analyzer", { "preset": "conventionalcommits" }],
["@semantic-release/exec", {
"prepareCmd": "git-cliff --tag v${nextRelease.version} -o CHANGELOG.md && scripts/build.sh ${nextRelease.version}",
"publishCmd": "cd dist && sha256sum -c --quiet SHA256SUMS"
}],
["@semantic-release/git", {
"assets": ["CHANGELOG.md"],
"message": "chore(release): ${nextRelease.version} [skip ci]"
}]
]
}
JSON
cat > scripts/release.sh <<'SH'
#!/usr/bin/env bash
# release.sh: the whole pipeline, identical locally and in CI
set -euo pipefail
last=$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)
echo "== gate: commit messages since ${last:-the beginning}"
if [ -n "$last" ]; then commitlint --from "$last" --to HEAD; else commitlint --from "$(git rev-list --max-parents=0 HEAD)" --to HEAD; fi
echo "== release"
semantic-release --no-ci 2>&1 | sed -E 's/^\[[^]]+\] \[semantic-release\] (\[[^]]+\] )?› . +//' \
| grep -E '^(The next release|There is no previous|There are no|Call script|Found [0-9]+ file|Created tag|Published)'
SH
chmod +x scripts/release.sh
git add -A && git commit -q -m "feat: greet the world"
git commit -q --allow-empty -m "feat(cli): greet a name given as the first argument"
git push -q origin main
echo "########## release 1"
scripts/release.sh
git fetch -q origin
git log --format='%s%d' # no hashes: the release commit's changelog holds today's date
ls dist
tar -xzf dist/greet-1.0.0-linux.tar.gz -C /tmp && /tmp/greet-1.0.0/bin/greet --version && /tmp/greet-1.0.0/bin/greet Ada
cat CHANGELOG.md
echo "########## release 2: a bad commit message"
sed -i 's/Hello, /Hello there, /' bin/greet
git commit -q -am "Changed the greeting"
scripts/release.sh; echo "release.sh exit code: $?"
git commit -q --amend -m "fix: use a friendlier greeting"
git commit -q --allow-empty -m "docs: describe the --version flag"
git push -q origin main
scripts/release.sh
git fetch -q origin
git ls-remote --tags origin | grep -v '\^{}' | cut -f2
sed -n '1,10p' CHANGELOG.md
cat dist/SHA256SUMS | cut -c1-12,65-
echo "rebuild check:"; cp dist/SHA256SUMS /tmp/first.sums; scripts/build.sh 1.0.1; cmp -s dist/SHA256SUMS /tmp/first.sums && echo "identical artifacts"########## release 1
== gate: commit messages since the beginning
== release
There is no previous release, the next release version is 1.0.0
Call script git-cliff --tag v1.0.0 -o CHANGELOG.md && scripts/build.sh 1.0.0
Found 1 file(s) to commit
Created tag v1.0.0
Call script cd dist && sha256sum -c --quiet SHA256SUMS
Published release 1.0.0 on default channel
chore(release): 1.0.0 [skip ci] (HEAD -> main, tag: v1.0.0, origin/main)
feat(cli): greet a name given as the first argument
feat: greet the world
SHA256SUMS
greet-1.0.0-linux.tar.gz
greet-1.0.0-macos.tar.gz
greet-1.0.0-windows.zip
greet 1.0.0 (linux)
Hello, Ada
# Changelog
## [1.0.0] - 2026-10-24
### Added
- Greet the world
- **cli:** Greet a name given as the first argument
########## release 2: a bad commit message
== gate: commit messages since v1.0.0
⧗ --- input ---
Changed the greeting
✖ subject may not be empty [subject-empty]
✖ type may not be empty [type-empty]
✖ found 2 problems, 0 warnings
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
release.sh exit code: 1
== gate: commit messages since v1.0.0
== release
The next release version is 1.0.1
Call script git-cliff --tag v1.0.1 -o CHANGELOG.md && scripts/build.sh 1.0.1
Found 1 file(s) to commit
Created tag v1.0.1
Call script cd dist && sha256sum -c --quiet SHA256SUMS
Published release 1.0.1 on default channel
refs/tags/v1.0.0
refs/tags/v1.0.1
# Changelog
## [1.0.1] - 2026-10-24
### Fixed
- Use a friendlier greeting
## [1.0.0] - 2026-01-15
1b403b0ae1b2 greet-1.0.1-linux.tar.gz
4262081ab85d greet-1.0.1-macos.tar.gz
fc9e9058a917 greet-1.0.1-windows.zip
rebuild check:
identical artifacts
Walkthrough
bin/greet contains placeholders (@VERSION@, @TARGET@) instead of a version. The source never holds a version number; build.sh stamps it into each artifact from the version semantic-release computed, so greet --version in a release archive prints greet 1.0.0 (linux). (git describe & Version Strings shows the alternative of deriving it from tags.)
commitlint.config.mjs is the one-line conventional config. release.sh uses set -euo pipefail, so any failing command, including semantic-release inside the filtering pipe, stops the script with a non-zero exit code. scripts/release.sh runs it over every commit since the last release tag before anything else. In the second release, Changed the greeting stops the pipeline with exit code 1: nothing was versioned, built or tagged. In CI this is also checked on the pull request, so the release-time check is a last line of defence (commitlint).
.releaserc.json wires the stages together in lifecycle order (The semantic-release Plugin Pipeline):
analyzeCommits: twofeatcommits and no previous release →1.0.0; later onefix(thedocs:commit doesn't count) →1.0.1. Theconventionalcommitspreset is used sofeat!:would be recognised as breaking (thefeat!pitfall).prepare(exec):git-cliff --tag v1.0.1 -o CHANGELOG.mdregenerates the whole changelog with the unreleased commits as 1.0.1, thenbuild.shbuilds the artifacts.prepare(git): commitsCHANGELOG.mdaschore(release): 1.0.1 [skip ci]; semantic-release then creates the annotated tag on that commit and pushes both.publish(exec): verifiesSHA256SUMSagainst the files; in CI this is wheregh release create(or the@semantic-release/githubplugin) uploads them.
There is no @semantic-release/release-notes-generator: git-cliff is the single source of changelog text, so notes and changelog can't disagree.
cliff.toml groups commits into Added/Fixed/Changed/Reverted and skips everything else, including the chore(release) commits semantic-release creates and the docs: commit. The 1.0.0 section is dated by its tag (2026-01-15, the fixed commit date of the sessions); the new 1.0.1 section carries the date of the run.
scripts/build.sh builds three archives with every source of non-determinism pinned: sorted names, SOURCE_DATE_EPOCH from the commit for all timestamps, root ownership, gzip -n, and zip -X for the Windows archive. The final "rebuild check" builds 1.0.1 again and gets identical checksums (Artifact Naming & Checksums). The dist/ folder is ignored by Git: artifacts are pipeline outputs, never commits.
The matching GitHub Actions workflows
Locally, scripts/release.sh is the pipeline. In CI, the workflows only provide a clean checkout, the tools, and the credentials, then call the same script. A pull-request check and the release (non-run; current action versions, pinned by SHA in the release job):
# .github/workflows/pr.yml
name: pr
on: pull_request
permissions:
contents: read
jobs:
commitlint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
- uses: actions/setup-node@v7
with:
node-version: 24
- run: npm ci
- run: npx commitlint --from "$BASE" --to "$HEAD" --verbose
env:
BASE: ${{ github.event.pull_request.base.sha }}
HEAD: ${{ github.event.pull_request.head.sha }}# .github/workflows/release.yml
name: release
on:
push:
branches: [main]
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-24.04
environment: release
permissions:
contents: write # push the release commit and tag, create the GitHub Release
id-token: write # artifact attestation
attestations: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # tags and history for commitlint, git-cliff and semantic-release
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
package-manager-cache: false
- run: npm ci # semantic-release, plugins and commitlint pinned in package-lock.json
- name: Install git-cliff
run: npm install --no-save git-cliff@2.14.2 # the npm package ships the same binary
- name: Release
run: PATH="$PWD/node_modules/.bin:$PATH" scripts/release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload to the GitHub Release
if: hashFiles('dist/SHA256SUMS') != ''
env:
GH_TOKEN: ${{ github.token }}
run: |
tag=$(git describe --tags --exact-match HEAD)
git-cliff --latest --strip all > NOTES.md
gh release create "$tag" dist/* --verify-tag --title "$tag" --notes-file NOTES.md
- if: hashFiles('dist/SHA256SUMS') != ''
uses: actions/attest-build-provenance@v4
with:
subject-path: dist/greet-*Differences from the local run, and why:
"repositoryUrl"is dropped from.releaserc.json(semantic-release reads the GitHub URL from the checkout), and there is no--no-ci(it detects GitHub Actions and refuses to publish from pull-request runs).[skip ci]in the release commit's message stops the pushed release commit from starting this workflow again; pushes made with the defaultGITHUB_TOKENwouldn't trigger it anyway (Workflows & Triggers). Ifmainis protected, the release commit needs a GitHub App token allowed to bypass the rule, or drop the git plugin and keep the changelog only in GitHub Releases (the trade-off).- The upload step only runs when a release happened (
dist/SHA256SUMSexists): a push with onlydocs:commits ends successfully without a release. environment: releasecan require an approval before any of it runs (Environments, Approvals & Concurrency).
Extend it
- Add a
betapre-release branch to.releaserc.jsonand release1.1.0-beta.1from it (Pre-release Branches & Channels). - Sign
SHA256SUMSin the publish step with theopensslcommands from Signing Releases, and verify the signature in the rebuild check. - Build a
.debfrom the Linux stage folder withdpkg-deb(Packaging Strategies), with its version translated from SemVer. - Replace semantic-release with changesets: a changeset file per change,
changeset versioninstead of the analyzer,changeset git-tagfor the tag (Changesets). Which parts ofrelease.shchange, and which stay?
Test yourself
In the session, why did the second run of release.sh stop before semantic-release ran?
- There were no new commits
- commitlint rejected
Changed the greeting, andset -estopped the script - The tag already existed
- git-cliff failed
Why does the docs: commit not appear in the 1.0.1 changelog?
- git-cliff can't parse docs commits
- cliff.toml's last parser skips every commit type not listed above it
- semantic-release removed it
- It was amended
Why is the version stamped into the artifact by build.sh instead of being written in bin/greet?
- Shell scripts can't hold versions
- So the tag/computed version is the single source of truth and no human edits a version number
- To make the file smaller
- Because of zip