-
Notifications
You must be signed in to change notification settings - Fork 57
94 lines (80 loc) · 2.87 KB
/
release-publish.yml
File metadata and controls
94 lines (80 loc) · 2.87 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
name: Publish release
on:
pull_request:
types: [closed]
branches: [trunk]
concurrency:
group: release-publish
cancel-in-progress: false
jobs:
publish-release:
name: Build plugin and create GitHub release
if: >-
github.repository == 'WordPress/sqlite-database-integration'
&& github.event.pull_request.merged == true
&& startsWith(github.event.pull_request.head.ref, 'release/')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract version from branch name
id: version
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
run: |
# Extract version from branch name (release/v2.3.0 → 2.3.0).
VERSION="${BRANCH#release/v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=v$VERSION" >> $GITHUB_OUTPUT
# Versions with a hyphen (e.g., 2.3.0-beta.1) are prereleases.
if [[ "$VERSION" == *-* ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
else
echo "prerelease=false" >> $GITHUB_OUTPUT
fi
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Build plugin zip
run: composer run build-sqlite-plugin-zip
- name: Extract changelog from readme.txt
id: changelog
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
README="packages/plugin-sqlite-database-integration/readme.txt"
# Extract the changelog entry for this version.
CHANGELOG=$(awk -v version="$VERSION" '
$0 == "= " version " =" { found = 1; next }
found && /^= / { exit }
found { print }
' "$README" | sed -e '/./,$!d' -e :a -e '/^\s*$/{ $d; N; ba; }') # Trim leading/trailing blank lines.
{
echo "body<<CHANGELOG_EOF"
echo "$CHANGELOG"
echo "CHANGELOG_EOF"
} >> $GITHUB_OUTPUT
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
BODY: ${{ steps.changelog.outputs.body }}
run: |
PRERELEASE_FLAG=""
if [[ "${{ steps.version.outputs.prerelease }}" == "true" ]]; then
PRERELEASE_FLAG="--prerelease"
fi
gh release create "$TAG" \
--target "$MERGE_SHA" \
--title "$TAG" \
--notes "$BODY" \
$PRERELEASE_FLAG \
"build/sqlite-database-integration.zip"
- name: Delete release branch
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
run: git push origin --delete "$BRANCH" 2>/dev/null || true