|
1 | 1 | # https://help.github.com/en/categories/automating-your-workflow-with-github-actions |
2 | 2 |
|
| 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 | + |
3 | 11 | name: "Create tag" |
4 | 12 |
|
5 | | -on: |
| 13 | +on: # zizmor: ignore[concurrency-limits] -- manually dispatched one-off runs; a newer run does not supersede an older one |
6 | 14 | # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch |
7 | 15 | workflow_dispatch: |
8 | 16 | inputs: |
|
15 | 23 | - patch |
16 | 24 | - minor |
17 | 25 |
|
18 | | -concurrency: |
19 | | - group: create-tag |
20 | | - cancel-in-progress: true |
21 | | - |
22 | | -permissions: |
23 | | - contents: read |
| 26 | +permissions: {} |
24 | 27 |
|
25 | 28 | jobs: |
26 | | - create-tag: |
27 | | - name: "Create tag" |
| 29 | + request-tag: |
| 30 | + name: "Request the tag from phpstan/release" |
28 | 31 | runs-on: "ubuntu-latest" |
29 | 32 | steps: |
30 | 33 | - name: Harden the runner (Audit all outbound calls) |
31 | 34 | uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 |
32 | 35 | with: |
33 | 36 | egress-policy: audit |
34 | 37 |
|
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" |
45 | 39 | 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