Repository navigation
63 lines (57 loc) · 2.56 KB
/
Copy pathcreate-tag.yml
File metadata and controls
63 lines (57 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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: # 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:
version:
description: 'Next version'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
permissions: {}
jobs:
request-tag:
name: "Request the tag from phpstan/release"
runs-on: "ubuntu-latest"
steps:
- name: Harden the runner (Audit all outbound calls)
uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4
with:
egress-policy: audit
- name: "Compute the next version and dispatch"
env:
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"