Skip to content

Commit 32693bc

Browse files
committed
Request release tags from phpstan/release
1 parent 190c138 commit 32693bc

1 file changed

Lines changed: 37 additions & 40 deletions

File tree

‎.github/workflows/create-tag.yml‎

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
22

3+
# Tags are created only by the phpstan-release GitHub App, from the
4+
# tag.yml workflow in phpstan/release, after the release environment there
5+
# is approved. This workflow only computes the next version and asks
6+
# phpstan/release to tag the head of the branch it runs on; the tag push
7+
# then triggers the release workflows here as before.
8+
# RELEASE_DISPATCH_TOKEN is a fine-grained token limited to phpstan/release
9+
# with Actions: write, which can start that workflow but not approve it.
10+
311
name: "Create tag"
412

5-
on:
13+
on: # zizmor: ignore[concurrency-limits] -- manually dispatched one-off runs; a newer run does not supersede an older one
614
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
715
workflow_dispatch:
816
inputs:
@@ -15,52 +23,41 @@ on:
1523
- patch
1624
- minor
1725

18-
concurrency:
19-
group: create-tag
20-
cancel-in-progress: true
21-
22-
permissions:
23-
contents: read
26+
permissions: {}
2427

2528
jobs:
26-
create-tag:
27-
name: "Create tag"
29+
request-tag:
30+
name: "Request the tag from phpstan/release"
2831
runs-on: "ubuntu-latest"
2932
steps:
3033
- name: Harden the runner (Audit all outbound calls)
3134
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
3235
with:
3336
egress-policy: audit
3437

35-
# Credentials must stay persisted: rickstaa/action-create-tag pushes the tag with them
36-
- name: "Checkout" # zizmor: ignore[artipacked]
37-
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
38-
with:
39-
fetch-depth: 0
40-
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
41-
42-
- name: 'Get Previous tag'
43-
id: previoustag
44-
uses: "WyriHaximus/github-action-get-previous-tag@83f26fea93bc7efcbca2eb5591f5eaaf66b8f206" # v2.1.0
38+
- name: "Compute the next version and dispatch"
4539
env:
46-
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
47-
48-
- name: 'Get next versions'
49-
id: semvers
50-
uses: "WyriHaximus/github-action-next-semvers@18aa9ed4152808ab99b88d71f5481e41f8d89930" # v1.2.1
51-
with:
52-
version: ${{ steps.previoustag.outputs.tag }}
53-
54-
- name: "Create new minor tag"
55-
uses: rickstaa/action-create-tag@a1c7777fcb2fee4f19b0f283ba888afa11678b72 # v1.7.2
56-
if: inputs.version == 'minor'
57-
with:
58-
tag: ${{ steps.semvers.outputs.minor }}
59-
message: ${{ steps.semvers.outputs.minor }}
60-
61-
- name: "Create new patch tag"
62-
uses: rickstaa/action-create-tag@a1c7777fcb2fee4f19b0f283ba888afa11678b72 # v1.7.2
63-
if: inputs.version == 'patch'
64-
with:
65-
tag: ${{ steps.semvers.outputs.patch }}
66-
message: ${{ steps.semvers.outputs.patch }}
40+
GH_TOKEN: ${{ secrets.RELEASE_DISPATCH_TOKEN }}
41+
BUMP: ${{ inputs.version }}
42+
run: |
43+
set -euo pipefail
44+
# On a maintained branch like 2.3.x, look only at 2.3.* tags
45+
if [[ "$GITHUB_REF_NAME" =~ ^([0-9]+\.[0-9]+)\.x$ ]]; then
46+
series="^${BASH_REMATCH[1]//./\\.}\\."
47+
else
48+
series='^[0-9]'
49+
fi
50+
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)"
51+
if [ -z "$prev" ]; then
52+
echo "::error::No previous tag matches $series on $GITHUB_REF_NAME"
53+
exit 1
54+
fi
55+
IFS=. read -r major minor patch <<< "$prev"
56+
if [ "$BUMP" = minor ]; then
57+
next="$major.$((minor + 1)).0"
58+
else
59+
next="$major.$minor.$((patch + 1))"
60+
fi
61+
gh workflow run tag.yml --repo phpstan/release \
62+
-f repository="${GITHUB_REPOSITORY#*/}" -f tag="$next" -f branch="$GITHUB_REF_NAME"
63+
echo "Requested $next (previous: $prev). Approve it at https://github.com/phpstan/release/actions" >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)