-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (82 loc) · 3.03 KB
/
release.yml
File metadata and controls
95 lines (82 loc) · 3.03 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
name: Release
# Cutting a release is just pushing a version tag:
#
# git tag 2.0.0 && git push origin 2.0.0
#
# Packagist picks up the new version automatically through its GitHub
# integration (no token needed). This workflow only validates the tag and
# publishes a GitHub Release, using the built-in GITHUB_TOKEN — there are no
# secrets to configure.
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-*'
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
permissions:
contents: write
jobs:
release:
name: Publish release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: curl, json, fileinfo
coverage: none
tools: composer:v2
- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress
- name: Validate composer.json
run: composer validate --strict
- name: Verify the tag matches Client::VERSION
run: |
tag="${GITHUB_REF_NAME#v}"
version="$(php -r 'require "src/Client.php"; echo TestingBot\Client::VERSION;')"
if [ "$tag" != "$version" ]; then
echo "::error::Tag '$tag' does not match Client::VERSION '$version'. Bump the VERSION constant before tagging."
exit 1
fi
echo "Tag and Client::VERSION agree: $version"
- name: Coding standards
run: composer cs-check
- name: Static analysis
run: composer phpstan
- name: Unit tests
run: composer test
- name: Extract release notes from CHANGELOG
run: |
version="${GITHUB_REF_NAME#v}"
awk -v ver="$version" '
$0 ~ "^## \\[" ver "\\]" {flag=1; next}
/^## / && flag {flag=0}
flag {print}
' CHANGELOG.md > release-notes.md
if [ ! -s release-notes.md ]; then
echo "No CHANGELOG section found for $version; GitHub will auto-generate notes."
fi
- name: Create or update GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# Idempotent: the tag may already have a Release (e.g. created from
# the GitHub UI, which both tags and releases in one step). In that
# case update its notes instead of failing on a duplicate create.
if gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1; then
echo "Release $GITHUB_REF_NAME already exists; updating notes."
if [ -s release-notes.md ]; then
gh release edit "$GITHUB_REF_NAME" --notes-file release-notes.md
fi
elif [ -s release-notes.md ]; then
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--notes-file release-notes.md
else
gh release create "$GITHUB_REF_NAME" \
--title "$GITHUB_REF_NAME" \
--generate-notes
fi