-
Notifications
You must be signed in to change notification settings - Fork 7
122 lines (109 loc) · 4.01 KB
/
Copy pathrelease.yml
File metadata and controls
122 lines (109 loc) · 4.01 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Release
on:
push:
branches:
- main
concurrency:
group: release
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
jobs:
release:
name: Tag, Release, and Version Bump
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Read version from pantheon.php
id: version
run: |
VERSION=$(grep -oP "define\( 'PANTHEON_MU_PLUGIN_VERSION', '\K[^']+" pantheon.php)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Detected version: $VERSION"
- name: Check whether this is a release version
id: check
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
if [[ "$VERSION" == *-dev ]]; then
echo "is_release=false" >> "$GITHUB_OUTPUT"
echo "Version $VERSION ends in -dev — skipping release."
else
echo "is_release=true" >> "$GITHUB_OUTPUT"
echo "Version $VERSION is a release candidate — proceeding."
fi
- name: Configure git identity
if: steps.check.outputs.is_release == 'true'
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
- name: Create Git tag
if: steps.check.outputs.is_release == 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
git tag "$VERSION"
git push origin "$VERSION"
- name: Create GitHub Release
if: steps.check.outputs.is_release == 'true'
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
gh release create "$VERSION" \
--generate-notes \
--title "$VERSION"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Compute next dev version
if: steps.check.outputs.is_release == 'true'
id: next
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
NEXT_PATCH=$(( PATCH + 1 ))
NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-dev"
echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
echo "Next dev version: $NEXT_VERSION"
- name: Bump version in pantheon.php
if: steps.check.outputs.is_release == 'true'
env:
NEXT: ${{ steps.next.outputs.next_version }}
run: |
sed -i "s/^\( \* Version: \).*/\1${NEXT}/" pantheon.php
sed -i "s/\(define( 'PANTHEON_MU_PLUGIN_VERSION', '\)[^']*\(.*\)/\1${NEXT}\2/" pantheon.php
- name: Verify both version strings were updated
if: steps.check.outputs.is_release == 'true'
env:
NEXT: ${{ steps.next.outputs.next_version }}
run: |
COUNT=$(grep -c "$NEXT" pantheon.php)
if [ "$COUNT" -lt 2 ]; then
echo "ERROR: Expected at least 2 occurrences of $NEXT in pantheon.php, found $COUNT"
grep -n "Version\|PANTHEON_MU_PLUGIN_VERSION" pantheon.php
exit 1
fi
echo "Both version strings updated to $NEXT"
grep -n "Version\|PANTHEON_MU_PLUGIN_VERSION" pantheon.php
- name: Open version bump PR
if: steps.check.outputs.is_release == 'true'
env:
NEXT: ${{ steps.next.outputs.next_version }}
run: |
BRANCH="chore/bump-version-${NEXT}"
git checkout -b "$BRANCH"
git add pantheon.php
git commit -m "chore: bump version to ${NEXT}"
git push origin "$BRANCH"
gh pr create \
--title "chore: bump version to ${NEXT}" \
--body "Automated version bump after release. Merges automatically." \
--base main \
--head "$BRANCH"
gh pr merge "$BRANCH" --auto --squash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}