-
Notifications
You must be signed in to change notification settings - Fork 57
135 lines (116 loc) · 4.59 KB
/
release-publish.yml
File metadata and controls
135 lines (116 loc) · 4.59 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
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
outputs:
tag: ${{ steps.version.outputs.tag }}
prerelease: ${{ steps.version.outputs.prerelease }}
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: Get contributors from changelog PRs
id: contributors
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CHANGELOG: ${{ steps.changelog.outputs.body }}
run: |
# Extract PR numbers from changelog links like [#123](...).
PR_NUMBERS=$(echo "$CHANGELOG" | grep -oE '\[#[0-9]+\]' | tr -d '[]#' | sort -u)
CONTRIBUTORS=""
if [ -n "$PR_NUMBERS" ]; then
# Build a single GraphQL query to fetch all PR authors.
QUERY='{ repository(owner: "${{ github.repository_owner }}", name: "${{ github.event.repository.name }}") {'
while IFS= read -r PR; do
[ -n "$PR" ] && QUERY="$QUERY pr$PR: pullRequest(number: $PR) { author { login } }"
done <<< "$PR_NUMBERS"
QUERY="$QUERY } }"
CONTRIBUTORS=$(gh api graphql -f query="$QUERY" \
--jq '[.data.repository[].author.login] | unique | map("@" + .) | join(", ")')
fi
echo "list=$CONTRIBUTORS" >> $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 }}
CONTRIBUTORS: ${{ steps.contributors.outputs.list }}
run: |
PRERELEASE_FLAG=""
if [[ "${{ steps.version.outputs.prerelease }}" == "true" ]]; then
PRERELEASE_FLAG="--prerelease"
fi
NOTES="$(printf '## Changelog\n\n%s' "$BODY")"
if [ -n "$CONTRIBUTORS" ]; then
NOTES="$(printf '%s\n\n## Contributors\n\nThe following contributors merged PRs in this release:\n\n%s' "$NOTES" "$CONTRIBUTORS")"
fi
gh release create "$TAG" \
--target "$MERGE_SHA" \
--title "$TAG" \
--notes "$NOTES" \
$PRERELEASE_FLAG \
"build/plugin-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
deploy-wporg:
name: Deploy to WordPress.org
needs: publish-release
if: needs.publish-release.outputs.prerelease == 'false'
uses: ./.github/workflows/release-wporg.yml
with:
tag: ${{ needs.publish-release.outputs.tag }}
secrets: inherit