Repository navigation
97 lines (91 loc) · 3.52 KB
/
Copy pathrelease.yml
File metadata and controls
97 lines (91 loc) · 3.52 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: Release
# Stage 1 of the release flow: opens a version-bump PR against 2.x.
# When that PR is merged, tag-release.yml (stage 2) creates the tag and
# the GitHub release automatically.
on:
workflow_dispatch:
inputs:
bump:
description: 'Version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
version:
description: 'Explicit version (e.g. 2.9.0) — overrides bump type'
required: false
type: string
permissions:
contents: write
pull-requests: write
jobs:
release-pr:
name: Open version bump PR
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: 2.x
fetch-depth: 0
# Optional: set a RELEASE_TOKEN repo secret (fine-grained PAT with
# contents + pull-requests write) so the bump PR triggers CI checks.
# PRs created with the default github.token do not trigger workflows.
token: ${{ secrets.RELEASE_TOKEN || github.token }}
- name: Determine new version
id: version
env:
EXPLICIT_VERSION: ${{ inputs.version }}
BUMP: ${{ inputs.bump }}
run: |
current=$(sed -nE "s/^[[:space:]]*'version' => '([0-9]+\.[0-9]+\.[0-9]+)',/\1/p" config/app.php)
if [ -z "$current" ]; then
echo "::error::Could not read current version from config/app.php"
exit 1
fi
if [ -n "$EXPLICIT_VERSION" ]; then
new="$EXPLICIT_VERSION"
if ! echo "$new" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid version '$new' — expected X.Y.Z"
exit 1
fi
else
IFS=. read -r major minor patch <<< "$current"
case "$BUMP" in
major) new="$((major + 1)).0.0" ;;
minor) new="$major.$((minor + 1)).0" ;;
patch) new="$major.$minor.$((patch + 1))" ;;
esac
fi
if git rev-parse -q --verify "refs/tags/v$new" > /dev/null; then
echo "::error::Tag v$new already exists"
exit 1
fi
echo "Bumping $current -> $new"
echo "new=$new" >> "$GITHUB_OUTPUT"
- name: Push bump commit to release branch
env:
NEW_VERSION: ${{ steps.version.outputs.new }}
run: |
sed -i -E "s/^([[:space:]]*'version' => ')[0-9.]+(',)/\1$NEW_VERSION\2/" config/app.php
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -am "Bump version to $NEW_VERSION"
git push --force origin "HEAD:refs/heads/release/v$NEW_VERSION"
- name: Open pull request
env:
GH_TOKEN: ${{ secrets.RELEASE_TOKEN || github.token }}
NEW_VERSION: ${{ steps.version.outputs.new }}
run: |
existing=$(gh pr list --head "release/v$NEW_VERSION" --base 2.x --state open --json number -q '.[0].number')
if [ -n "$existing" ]; then
echo "PR #$existing is already open for release/v$NEW_VERSION"
else
gh pr create \
--base 2.x \
--head "release/v$NEW_VERSION" \
--title "Bump version to $NEW_VERSION" \
--body "Automated version bump. Merging this PR will tag v$NEW_VERSION and publish the GitHub release. Merge it last, once everything for the release is on 2.x."
fi