From 3d35288b47ac9c7f1e8353e4270ffe778e97854e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Mirtes?= Date: Sat, 28 Nov 2026 12:00:32 +0000 Subject: [PATCH] Request release tags from phpstan/release --- .github/workflows/create-tag.yml | 77 +++++++++++++++----------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml index c9d6967..e115b47 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-tag.yml @@ -1,8 +1,16 @@ # https://help.github.com/en/categories/automating-your-workflow-with-github-actions +# Tags are created only by the phpstan-release GitHub App, from the +# tag.yml workflow in phpstan/release, after the release environment there +# is approved. This workflow only computes the next version and asks +# phpstan/release to tag the head of the branch it runs on; the tag push +# then triggers the release workflows here as before. +# RELEASE_DISPATCH_TOKEN is a fine-grained token limited to phpstan/release +# with Actions: write, which can start that workflow but not approve it. + name: "Create tag" -on: +on: # zizmor: ignore[concurrency-limits] -- manually dispatched one-off runs; a newer run does not supersede an older one # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch workflow_dispatch: inputs: @@ -15,16 +23,11 @@ on: - patch - minor -concurrency: - group: create-tag - cancel-in-progress: true - -permissions: - contents: read +permissions: {} jobs: - create-tag: - name: "Create tag" + request-tag: + name: "Request the tag from phpstan/release" runs-on: "ubuntu-latest" steps: - name: Harden the runner (Audit all outbound calls) @@ -32,35 +35,29 @@ jobs: with: egress-policy: audit - # Credentials must stay persisted: rickstaa/action-create-tag pushes the tag with them - - name: "Checkout" # zizmor: ignore[artipacked] - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - token: ${{ secrets.PHPSTAN_BOT_TOKEN }} - - - name: 'Get Previous tag' - id: previoustag - uses: "WyriHaximus/github-action-get-previous-tag@83f26fea93bc7efcbca2eb5591f5eaaf66b8f206" # v2.1.0 + - name: "Compute the next version and dispatch" env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - - - name: 'Get next versions' - id: semvers - uses: "WyriHaximus/github-action-next-semvers@18aa9ed4152808ab99b88d71f5481e41f8d89930" # v1.2.1 - with: - version: ${{ steps.previoustag.outputs.tag }} - - - name: "Create new minor tag" - uses: rickstaa/action-create-tag@a1c7777fcb2fee4f19b0f283ba888afa11678b72 # v1.7.2 - if: inputs.version == 'minor' - with: - tag: ${{ steps.semvers.outputs.minor }} - message: ${{ steps.semvers.outputs.minor }} - - - name: "Create new patch tag" - uses: rickstaa/action-create-tag@a1c7777fcb2fee4f19b0f283ba888afa11678b72 # v1.7.2 - if: inputs.version == 'patch' - with: - tag: ${{ steps.semvers.outputs.patch }} - message: ${{ steps.semvers.outputs.patch }} + GH_TOKEN: ${{ secrets.RELEASE_DISPATCH_TOKEN }} + BUMP: ${{ inputs.version }} + run: | + set -euo pipefail + # On a maintained branch like 2.3.x, look only at 2.3.* tags + if [[ "$GITHUB_REF_NAME" =~ ^([0-9]+\.[0-9]+)\.x$ ]]; then + series="^${BASH_REMATCH[1]//./\\.}\\." + else + series='^[0-9]' + fi + prev="$(git ls-remote --tags --refs "https://github.com/$GITHUB_REPOSITORY.git" | sed 's|.*refs/tags/||' | grep -E "$series" | sort -V | tail -n 1 || true)" + if [ -z "$prev" ]; then + echo "::error::No previous tag matches $series on $GITHUB_REF_NAME" + exit 1 + fi + IFS=. read -r major minor patch <<< "$prev" + if [ "$BUMP" = minor ]; then + next="$major.$((minor + 1)).0" + else + next="$major.$minor.$((patch + 1))" + fi + gh workflow run tag.yml --repo phpstan/release \ + -f repository="${GITHUB_REPOSITORY#*/}" -f tag="$next" -f branch="$GITHUB_REF_NAME" + echo "Requested $next (previous: $prev). Approve it at https://github.com/phpstan/release/actions" >> "$GITHUB_STEP_SUMMARY"