diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 03824d5..07ea576 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -18,11 +18,14 @@ jobs: with: version: 2026.8.6 install: false + - id: calver + run: mise run release:calver - id: release uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0 with: config-file: release-please-config.json manifest-file: .release-please-manifest.json + release-as: ${{ steps.calver.outputs.version }} target-branch: main - name: Approve release PR CI if: ${{ steps.release.outputs.prs_created == 'true' }} diff --git a/mise.toml b/mise.toml index 10537a1..b8df723 100644 --- a/mise.toml +++ b/mise.toml @@ -23,6 +23,10 @@ file = "scripts/ci/release-app.sh" description = "Detect the release component from the Git tag" file = "scripts/ci/detect-release.sh" +[tasks."release:calver"] +description = "Calculate the next SemVer-compatible CalVer release" +file = "scripts/ci/calver.sh" + [tasks."release:approve-ci"] description = "Approve CI for the trusted Release Please PR" file = "scripts/ci/approve-release-ci.sh" diff --git a/release-please-config.json b/release-please-config.json index 57f0385..55d87f1 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -10,6 +10,8 @@ "component": "cli" } }, + "always-update": true, + "group-pull-request-title-pattern": "chore: release ${version}", "changelog-sections": [ { "type": "feat", "section": "Features" }, { "type": "fix", "section": "Bug Fixes" }, diff --git a/scripts/ci/calver.sh b/scripts/ci/calver.sh new file mode 100755 index 0000000..182ba3b --- /dev/null +++ b/scripts/ci/calver.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -euo pipefail + +manifest="${CALVER_MANIFEST:-$MISE_PROJECT_ROOT/.release-please-manifest.json}" +calendar="${CALVER_DATE:-$(date -u +%Y-%m)}" + +if [[ ! "$calendar" =~ ^([0-9]{4})-([0-9]{2})$ ]]; then + echo "CALVER_DATE must use YYYY-MM" >&2 + exit 1 +fi + +year="${BASH_REMATCH[1]}" +month=$((10#${BASH_REMATCH[2]})) +patch=-1 + +while IFS= read -r version; do + if [[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then + version_year="${BASH_REMATCH[1]}" + version_month="${BASH_REMATCH[2]}" + version_patch="${BASH_REMATCH[3]}" + + if (( version_year > year || (version_year == year && version_month > month) )); then + echo "Manifest version $version is ahead of calendar $year.$month" >&2 + exit 1 + fi + + if (( version_year == year && version_month == month && version_patch > patch )); then + patch="$version_patch" + fi + fi +done < <(jq -r '.[]' "$manifest") + +version="$year.$month.$((patch + 1))" +echo "$version" + +if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "version=$version" >> "$GITHUB_OUTPUT" +fi