From 1993ec504f62be1a57a2bb92dfaf025d9cb85137 Mon Sep 17 00:00:00 2001 From: Dave Barnwell Date: Sat, 7 Mar 2026 21:54:55 +0000 Subject: [PATCH 1/3] Add CalVer release workflow --- .github/workflows/release.yml | 105 ++++++++++++++++++++++++++++++++++ CHANGELOG.md | 1 + README.md | 1 + 3 files changed, 107 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..097a765 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,105 @@ +name: Release + +on: + pull_request_target: + types: [closed] + +permissions: + contents: write + +concurrency: + group: release-${{ github.event.pull_request.base.ref }} + cancel-in-progress: false + +jobs: + release: + if: > + github.event.pull_request.merged == true && + (github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'master') + runs-on: ubuntu-latest + + steps: + - name: Check out merged commit + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: 0 + + - name: Fetch tags + run: git fetch --force --tags origin + + - name: Determine CalVer tag + id: calver + env: + MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }} + run: | + set -euo pipefail + + existing_tag="$(git tag --points-at "$MERGE_COMMIT_SHA" --list 'v[0-9]*' | sort -V | head -n 1)" + + if [ -n "$existing_tag" ]; then + tag="$existing_tag" + else + base="$(date -u +'%Y.%m.%d')" + exact_exists=0 + max_suffix=0 + + while IFS= read -r existing; do + if [ "$existing" = "v$base" ]; then + exact_exists=1 + continue + fi + + suffix="${existing#v$base.}" + if ! printf '%s' "$suffix" | grep -Eq '^[0-9]+$'; then + continue + fi + + if [ "$suffix" -gt "$max_suffix" ]; then + max_suffix="$suffix" + fi + done < <(git tag -l "v$base" "v$base.*" | sort -V) + + if [ "$exact_exists" -eq 0 ] && [ "$max_suffix" -eq 0 ]; then + tag="v$base" + else + tag="v$base.$((max_suffix + 1))" + fi + fi + + echo "tag=$tag" >> "$GITHUB_OUTPUT" + + - name: Create and push tag + env: + MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }} + TAG: ${{ steps.calver.outputs.tag }} + run: | + set -euo pipefail + + if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then + echo "Tag $TAG already exists on origin" + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag -a "$TAG" "$MERGE_COMMIT_SHA" -m "Release $TAG" + git push origin "refs/tags/$TAG" + + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }} + TAG: ${{ steps.calver.outputs.tag }} + run: | + set -euo pipefail + + if gh release view "$TAG" >/dev/null 2>&1; then + echo "Release $TAG already exists" + exit 0 + fi + + gh release create "$TAG" \ + --target "$MERGE_COMMIT_SHA" \ + --generate-notes \ + --title "$TAG" diff --git a/CHANGELOG.md b/CHANGELOG.md index fd93a23..1d3ffe5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,4 @@ - Improve identifier quoting and driver-specific schema discovery. - Update tests to support configurable DB backends. - Add GitHub Actions CI matrix for PHP and database drivers. +- Add automatic CalVer tagging and GitHub releases for merged PRs. diff --git a/README.md b/README.md index 3fc7b99..7a2e725 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ The repository ships with: - PHPStan static analysis - PHP-CS-Fixer formatting checks - GitHub Actions CI for pull requests and pushes +- Automatic CalVer tags and GitHub releases for merged PRs to `main`/`master` ## Contributing From 559d4d8e344a7432298817f2c0ae5c3dc75c493f Mon Sep 17 00:00:00 2001 From: Dave Barnwell Date: Sat, 7 Mar 2026 21:56:05 +0000 Subject: [PATCH 2/3] Adjust CalVer tag format --- .github/workflows/release.yml | 23 +++++++++-------------- README.md | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 097a765..cdce167 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,21 +35,20 @@ jobs: run: | set -euo pipefail - existing_tag="$(git tag --points-at "$MERGE_COMMIT_SHA" --list 'v[0-9]*' | sort -V | head -n 1)" + existing_tag="$( + git tag --points-at "$MERGE_COMMIT_SHA" | + grep -E '^v[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]+$' | + sort -V | + head -n 1 || true + )" if [ -n "$existing_tag" ]; then tag="$existing_tag" else - base="$(date -u +'%Y.%m.%d')" - exact_exists=0 + base="$(date -u +'%y.%m.%d')" max_suffix=0 while IFS= read -r existing; do - if [ "$existing" = "v$base" ]; then - exact_exists=1 - continue - fi - suffix="${existing#v$base.}" if ! printf '%s' "$suffix" | grep -Eq '^[0-9]+$'; then continue @@ -58,13 +57,9 @@ jobs: if [ "$suffix" -gt "$max_suffix" ]; then max_suffix="$suffix" fi - done < <(git tag -l "v$base" "v$base.*" | sort -V) + done < <(git tag -l "v$base.*" | sort -V) - if [ "$exact_exists" -eq 0 ] && [ "$max_suffix" -eq 0 ]; then - tag="v$base" - else - tag="v$base.$((max_suffix + 1))" - fi + tag="v$base.$((max_suffix + 1))" fi echo "tag=$tag" >> "$GITHUB_OUTPUT" diff --git a/README.md b/README.md index 7a2e725..1f44e02 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,7 @@ The repository ships with: - PHPStan static analysis - PHP-CS-Fixer formatting checks - GitHub Actions CI for pull requests and pushes -- Automatic CalVer tags and GitHub releases for merged PRs to `main`/`master` +- Automatic `vYY.MM.DD.n` CalVer tags and GitHub releases for merged PRs to `main`/`master` ## Contributing From 0ed3c964d3e90ed3ae72d8fa722cbcff11ead9b2 Mon Sep 17 00:00:00 2001 From: Dave Barnwell Date: Sat, 7 Mar 2026 22:01:51 +0000 Subject: [PATCH 3/3] Fix release workflow review feedback --- .github/workflows/release.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cdce167..78496c3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,6 +32,7 @@ jobs: id: calver env: MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }} + MERGED_AT: ${{ github.event.pull_request.merged_at }} run: | set -euo pipefail @@ -39,13 +40,13 @@ jobs: git tag --points-at "$MERGE_COMMIT_SHA" | grep -E '^v[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[0-9]+$' | sort -V | - head -n 1 || true + tail -n 1 || true )" if [ -n "$existing_tag" ]; then tag="$existing_tag" else - base="$(date -u +'%y.%m.%d')" + base="$(date -u -d "$MERGED_AT" +'%y.%m.%d')" max_suffix=0 while IFS= read -r existing; do @@ -72,8 +73,14 @@ jobs: set -euo pipefail if git ls-remote --exit-code --tags origin "refs/tags/$TAG" >/dev/null 2>&1; then - echo "Tag $TAG already exists on origin" - exit 0 + remote_sha="$(git rev-list -n 1 "$TAG")" + if [ "$remote_sha" = "$MERGE_COMMIT_SHA" ]; then + echo "Tag $TAG already exists on origin and points to the expected commit" + exit 0 + fi + + echo "Error: Tag $TAG already exists on origin but points to $remote_sha instead of $MERGE_COMMIT_SHA" + exit 1 fi git config user.name "github-actions[bot]"