name: Release
# Publishes a version: Actions > Release > Run workflow, with the version (e.g. 0.2.0).
#
# The entries under "## [Unreleased]" in CHANGELOG.md become the version's section
# ("## [0.2.0] - 2026-12-01"), committed to main once the checks pass: main's ruleset
# must let GitHub Actions bypass it. A section already written for the version is used
# as it is. The section opens the release notes, above the pull requests grouped by label.
#
# main does not track the built bundle (public/). This workflow tests main, builds the
# bundle, and commits it on a release commit that only the tag points to: Packagist
# installs tags, so `composer require caelrik/ui` gets the bundle, and main stays
# source-only. Source maps are not in the package: they are attached to the GitHub
# release as a zip.
#
# With an NPM_TOKEN secret (an npm granular access token with read and write access to
# the @caelrik scope and "Bypass two-factor authentication"), the same
# bundle is published to npm as @caelrik/ui, which jsDelivr serves: Assets::cdnUrl().
on:
workflow_dispatch:
inputs:
version:
description: 'Version, without the "v" (e.g. 0.2.0 or 1.0.0-beta.1)'
required: true
permissions:
contents: write
id-token: write # npm provenance
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
env:
VERSION: ${{ inputs.version }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
steps:
- uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
- name: Check the version
run: |
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]]; then
echo "::error::Invalid version \"$VERSION\": use 1.2.3 or 1.2.3-beta.1"
exit 1
fi
if git rev-parse -q --verify "refs/tags/v$VERSION" > /dev/null; then
echo "::error::Tag v$VERSION already exists"
exit 1
fi
- name: Write the changelog section
env:
REPOSITORY_URL: ${{ github.server_url }}/${{ github.repository }}
run: |
# The previous release, for the compare link and the list of pull requests:
# release tags are not on main's history, so GitHub cannot find it on its own.
PREVIOUS=$(git tag --list 'v*' --sort=-version:refname | grep -vx "v$VERSION" | grep -v -- '-' | head -1)
echo "PREVIOUS=$PREVIOUS" >> "$GITHUB_ENV"
RESULT=$(python3 .github/scripts/changelog-release.py "$VERSION" "$(date -u +%F)" "$PREVIOUS" "$REPOSITORY_URL") || {
echo "::error::CHANGELOG.md has no \"## [$VERSION]\" section and nothing under [Unreleased]: add the changes of this release under [Unreleased]."
exit 1
}
if [[ "$RESULT" == written ]]; then
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git commit -q -am "chore(release): $VERSION"
echo "PUSH_MAIN=1" >> "$GITHUB_ENV"
fi
awk -v v="$VERSION" '
index($0, "## [" v "]") == 1 { found = 1; next }
found && /^## \[/ { exit }
found && /^\[[^]]+\]: / { exit }
found { print }
' CHANGELOG.md > release-notes.md
if ! grep -q '[^[:space:]]' release-notes.md; then
echo "::error::The \"## [$VERSION]\" section of CHANGELOG.md is empty."
exit 1
fi
cat release-notes.md
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: mbstring, pdo_sqlite
coverage: none
- uses: actions/setup-node@v7
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- run: composer install --no-interaction --no-progress
- run: npm ci --no-audit --no-fund
- run: composer lint
- run: composer test
- run: npm run lint
- run: npm test
- name: Build the bundle
run: |
npm version "$VERSION" --no-git-tag-version --allow-same-version
npm run build
- name: Move the source maps to the release download
run: |
mkdir -p dist
(cd public && find . -name '*.map' | sort | zip -q "../dist/caelrik-ui-$VERSION-sourcemaps.zip" -@)
find public -name '*.map' -delete
# Their references would make browsers request missing files.
find public -name '*.js' -exec sed -i '/^\/\/# sourceMappingURL=/d' {} +
find public -name '*.css' -exec sed -i 's#/\*\# sourceMappingURL=[^*]*\*/##' {} +
du -sh public
- name: Commit the bundle on the release commit and tag it
run: |
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
# The changelog commit goes to main first: it fails if main moved during the run,
# or if main's ruleset does not let GitHub Actions bypass it. Nothing is tagged then.
if [[ -n "${PUSH_MAIN:-}" ]] && ! git push origin HEAD:main; then
echo "::error::Could not push the CHANGELOG.md commit to main. Add GitHub Actions to the bypass list of main's ruleset, or run again if main changed."
exit 1
fi
git add --force public
git add package.json package-lock.json
git commit -q -m "Release v$VERSION (with the built bundle)"
git tag -a "v$VERSION" -m "Caelrik UI v$VERSION"
git push origin "refs/tags/v$VERSION"
- name: Create the GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "v$VERSION" "dist/caelrik-ui-$VERSION-sourcemaps.zip" \
--title "v$VERSION" --notes-file release-notes.md --generate-notes --verify-tag \
${PREVIOUS:+--notes-start-tag "$PREVIOUS"} \
$([[ "$VERSION" == *-* ]] && echo --prerelease)
- name: Publish to npm
if: env.NPM_TOKEN != ''
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
# Pre-releases go to the "next" tag, so they never become "latest".
# If this step fails, the tag and the release exist: fix NPM_TOKEN, then run
# Actions > Publish to npm with the same version.
npm publish --provenance --access public $([[ "$VERSION" == *-* ]] && echo --tag next)
|