Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/create-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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"
Loading