-
-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (126 loc) · 4.37 KB
/
Copy pathprepare-release.yml
File metadata and controls
144 lines (126 loc) · 4.37 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Prepare and Publish Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version without v prefix (example: 1.0.0)"
required: true
type: string
ref:
description: "Git ref to release (branch, tag, or commit SHA)"
required: false
default: "main"
type: string
prerelease:
description: "Mark GitHub Release as prerelease"
required: false
default: false
type: boolean
confirm:
description: "Type RELEASE to confirm publish"
required: true
type: string
permissions:
contents: write
concurrency:
group: release-${{ github.event.inputs.version }}
cancel-in-progress: false
jobs:
gate:
name: Gate / P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
php: ["8.5", "8.4", "8.3", "8.2"]
stability: [prefer-lowest, prefer-stable]
steps:
- name: Validate release request
if: matrix.os == 'ubuntu-latest' && matrix.php == '8.5' && matrix.stability == 'prefer-stable'
shell: bash
run: |
test "${{ inputs.confirm }}" = "RELEASE" || {
echo "confirm input must be exactly RELEASE"
exit 1
}
[[ "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]] || {
echo "version must be semver-like (for example: 1.0.0)"
exit 1
}
- name: Checkout code
uses: actions/checkout@v7
with:
ref: ${{ inputs.ref }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, xdebug
coverage: xdebug
- name: Composer validate (strict)
run: composer validate --strict
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Security audit (canonical job only)
if: matrix.os == 'ubuntu-latest' && matrix.php == '8.5' && matrix.stability == 'prefer-stable'
run: composer audit --format=plain
- name: Execute tests
run: vendor/bin/phpunit --coverage-clover coverage.xml
publish:
name: Publish Tag and GitHub Release
runs-on: ubuntu-latest
needs: gate
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
ref: ${{ inputs.ref }}
- name: Verify tag does not already exist
shell: bash
run: |
TAG="v${{ inputs.version }}"
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
echo "Tag ${TAG} already exists on origin"
exit 1
fi
- name: Extract release notes from CHANGELOG
env:
VERSION: ${{ inputs.version }}
shell: bash
run: |
# Extract the section for this version from CHANGELOG.md
# Matches from "## vX.Y.Z" until the next "## v" or "---" or end of file
awk -v ver="$VERSION" '
/^## v'"$VERSION"'/ { found=1; next }
found && /^## v[0-9]/ { exit }
found && /^---$/ { exit }
found { print }
' CHANGELOG.md > release-notes.md
# Verify we extracted something
if [ ! -s release-notes.md ]; then
echo "ERROR: Could not extract release notes for v${VERSION} from CHANGELOG.md"
exit 1
fi
echo "=== Extracted release notes ==="
cat release-notes.md
- name: Create and publish release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ inputs.version }}
TARGET_REF: ${{ inputs.ref }}
IS_PRERELEASE: ${{ inputs.prerelease }}
shell: bash
run: |
TAG="v${VERSION}"
FLAGS=""
if [ "$IS_PRERELEASE" = "true" ]; then
FLAGS="${FLAGS} --prerelease"
fi
gh release create "${TAG}" \
--target "${TARGET_REF}" \
--title "Version ${VERSION}" \
--notes-file release-notes.md \
${FLAGS}