Skip to content

Commit 6532719

Browse files
committed
Add WordPress.org deploy workflow
When a GitHub release is published, download the plugin zip from the release and deploy it to WordPress.org via SVN.
1 parent 53d9740 commit 6532719

5 files changed

Lines changed: 109 additions & 17 deletions

File tree

.github/workflows/release-prepare.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ jobs:
3333
run: |
3434
# Extract version from tag (strip leading "v" if present).
3535
VERSION="${RELEASE_TAG#v}"
36+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then
37+
echo "::error::Invalid version format: '$VERSION' (expected semver like '1.2.3')"
38+
exit 1
39+
fi
3640
echo "version=$VERSION" >> $GITHUB_OUTPUT
3741
3842
# Extract changelog, converting markdown list items to WP readme format.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Deploy to WordPress.org
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
concurrency:
8+
group: release-wporg-${{ github.event.release.tag_name }}
9+
cancel-in-progress: false
10+
11+
jobs:
12+
deploy:
13+
name: Deploy plugin to WordPress.org
14+
if: github.repository == 'WordPress/sqlite-database-integration'
15+
runs-on: ubuntu-latest
16+
environment: WordPress.org
17+
permissions:
18+
contents: read
19+
20+
steps:
21+
- name: Download plugin zip from release
22+
env:
23+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
RELEASE_TAG: ${{ github.event.release.tag_name }}
25+
run: |
26+
gh release download "$RELEASE_TAG" \
27+
--repo "${{ github.repository }}" \
28+
--pattern "sqlite-database-integration.zip" \
29+
--dir .
30+
unzip sqlite-database-integration.zip
31+
32+
- name: Verify release metadata
33+
env:
34+
RELEASE_TAG: ${{ github.event.release.tag_name }}
35+
run: |
36+
VERSION="${RELEASE_TAG#v}"
37+
bash bin/verify-release-metadata.sh sqlite-database-integration "$VERSION"
38+
39+
- name: Deploy to WordPress.org
40+
uses: 10up/action-wordpress-plugin-deploy@v2
41+
env:
42+
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
43+
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
44+
SLUG: sqlite-database-integration
45+
BUILD_DIR: sqlite-database-integration
Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
name: Verify plugin version
1+
name: Verify release metadata
22

33
on:
44
push:
55
branches:
6-
- main
6+
- trunk
77
pull_request:
88

99
jobs:
1010
verify-version:
11-
name: Assert the WordPress plugin header declares the same version as the SQLITE_DRIVER_VERSION constant
11+
name: Assert release metadata is internally consistent
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
@@ -19,17 +19,5 @@ jobs:
1919
VERSION=$(grep "Version:" packages/sqlite-database-integration/load.php | sed "s/.*Version: \([^ ]*\).*/\1/")
2020
echo "load_version=$VERSION" >> $GITHUB_OUTPUT
2121
22-
- name: Extract version from "version.php"
23-
id: const_version
24-
run: |
25-
VERSION=$(php -r "require 'packages/wp-mysql-on-sqlite/src/version.php'; echo SQLITE_DRIVER_VERSION;")
26-
echo "const_version=$VERSION" >> $GITHUB_OUTPUT
27-
28-
- name: Compare versions
29-
run: |
30-
if [ "${{ steps.load_version.outputs.load_version }}" != "${{ steps.const_version.outputs.const_version }}" ]; then
31-
echo "Version mismatch detected!"
32-
echo " load.php version: ${{ steps.load_version.outputs.load_version }}"
33-
echo " version.php constant: ${{ steps.const_version.outputs.const_version }}"
34-
exit 1
35-
fi
22+
- name: Verify release metadata
23+
run: bash bin/verify-release-metadata.sh packages/plugin-sqlite-database-integration

bin/build-plugin-zip.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ rm -rf "$PLUGIN_DIR/composer.json"
3131
rm -rf "$PLUGIN_DIR/vendor"
3232
rm -rf "$PLUGIN_DIR/node_modules"
3333

34+
# Verify release metadata in the built plugin.
35+
bash "$DIR/bin/verify-release-metadata.sh" "$PLUGIN_DIR"
36+
3437
# Create the zip archive.
3538
cd "$BUILD_DIR"
3639
zip -r "$ZIP_FILE" "sqlite-database-integration/" -x "*.DS_Store"

bin/verify-release-metadata.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Verify that plugin release metadata is internally consistent.
4+
#
5+
# Usage:
6+
# verify-release-metadata.sh <plugin-dir> # Check version consistency.
7+
# verify-release-metadata.sh <plugin-dir> <expected-version> # Also verify changelog entry.
8+
9+
set -euo pipefail
10+
11+
fail() {
12+
echo "::error::$1"
13+
exit 1
14+
}
15+
16+
PLUGIN_DIR="${1:?Usage: verify-release-metadata.sh <plugin-dir> [<expected-version>]}"
17+
EXPECTED_VERSION="${2:-}"
18+
19+
# Extract versions from the three source-of-truth files.
20+
PLUGIN_VERSION="$(sed -n 's/^ \* Version: \(.*\)$/\1/p' "$PLUGIN_DIR/load.php" | head -n 1 | tr -d '\r')"
21+
STABLE_TAG="$(sed -n 's/^Stable tag:[[:space:]]*//p' "$PLUGIN_DIR/readme.txt" | head -n 1 | tr -d '\r')"
22+
CONSTANT_VERSION="$(php -r "require '$PLUGIN_DIR/wp-includes/database/version.php'; echo SQLITE_DRIVER_VERSION;")"
23+
24+
[ -n "$PLUGIN_VERSION" ] || fail "Could not extract the plugin version from load.php."
25+
[ -n "$STABLE_TAG" ] || fail "Could not extract the Stable tag from readme.txt."
26+
[ -n "$CONSTANT_VERSION" ] || fail "Could not extract SQLITE_DRIVER_VERSION from version.php."
27+
28+
# All three must agree.
29+
[ "$PLUGIN_VERSION" = "$CONSTANT_VERSION" ] || fail "Version mismatch: load.php=$PLUGIN_VERSION, version.php=$CONSTANT_VERSION."
30+
[ "$PLUGIN_VERSION" = "$STABLE_TAG" ] || fail "Version mismatch: load.php=$PLUGIN_VERSION, readme.txt Stable tag=$STABLE_TAG."
31+
32+
# When an expected version is given, also verify it matches and that
33+
# the changelog contains a non-empty entry for that version.
34+
if [ -n "$EXPECTED_VERSION" ]; then
35+
[ "$PLUGIN_VERSION" = "$EXPECTED_VERSION" ] || fail "Version mismatch: expected $EXPECTED_VERSION, found $PLUGIN_VERSION."
36+
37+
grep -Fxq '== Changelog ==' "$PLUGIN_DIR/readme.txt" \
38+
|| fail "readme.txt is missing a == Changelog == section."
39+
40+
if ! awk -v version="$EXPECTED_VERSION" '
41+
BEGIN { in_changelog = 0; in_entry = 0; has_content = 0 }
42+
$0 == "== Changelog ==" { in_changelog = 1; next }
43+
in_changelog && $0 == "= " version " =" { in_entry = 1; next }
44+
in_entry && $0 ~ /^= / { exit has_content ? 0 : 1 }
45+
in_entry && $0 !~ /^[[:space:]]*$/ { has_content = 1 }
46+
END { if (!in_changelog || !in_entry || !has_content) exit 1 }
47+
' "$PLUGIN_DIR/readme.txt"; then
48+
fail "readme.txt must contain a changelog entry with content for version $EXPECTED_VERSION."
49+
fi
50+
fi
51+
52+
echo "Verified release metadata for version $PLUGIN_VERSION."

0 commit comments

Comments
 (0)