Serve plugin updates from tagged Gitea releases
CI / Tests (PHP 8.1) (pull_request) Successful in 45s
CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m43s
CI / PHPStan (pull_request) Successful in 2m51s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m34s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.1) (pull_request) Successful in 45s
CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m43s
CI / PHPStan (pull_request) Successful in 2m51s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m34s
CI / Build Plugin Zip (pull_request) Skipped
Closes #65 Declare an Update URI header and answer core's update_plugins_{hostname} filter from a new Update\UpdateChecker that offers the latest published Gitea release's zip asset when it is newer than the installed version, with transient caching and silent degradation on API failures. Add a release workflow that fires on v* tag pushes: verifies the tag matches the plugin Version header, runs the tests, builds the plugin zip, and attaches it to the release (reusing a UI-created release, flagging hyphenated versions as pre-release so /releases/latest skips them). Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
name: Release
|
||||
|
||||
# Fires when a v* tag is pushed — including tags created through Gitea's
|
||||
# "New Release" UI. Builds the distributable plugin zip and attaches it to
|
||||
# the release for that tag (creating the release if only a bare tag was
|
||||
# pushed). The attached zip is what UpdateChecker serves to WordPress
|
||||
# sites as the update package.
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Build and Publish Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.3'
|
||||
tools: composer:v2
|
||||
|
||||
# A tag that disagrees with the plugin header would make sites see a
|
||||
# phantom update forever (or never see a real one), so fail fast.
|
||||
- name: Verify tag matches plugin version
|
||||
id: meta
|
||||
run: |
|
||||
tag_version="${GITHUB_REF_NAME#v}"
|
||||
header_version="$(sed -nE 's/^[[:space:]]*\*?[[:space:]]*Version:[[:space:]]*([^[:space:]]+).*/\1/p' unsupervised-schedular.php | head -1)"
|
||||
if [ "$tag_version" != "$header_version" ]; then
|
||||
echo "Tag ${GITHUB_REF_NAME} does not match plugin header Version: ${header_version}" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "version=${header_version}" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --prefer-dist --no-progress --no-interaction
|
||||
|
||||
- name: Run tests
|
||||
run: composer test
|
||||
|
||||
- name: Build plugin zip
|
||||
run: composer build
|
||||
|
||||
- name: Publish release with zip asset
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
|
||||
version="${{ steps.meta.outputs.version }}"
|
||||
zip="dist/unsupervised-schedular-${version}.zip"
|
||||
|
||||
# Pre-release versions (1.2.3-rc.1) are flagged so Gitea's
|
||||
# /releases/latest endpoint — and therefore the update checker —
|
||||
# skips them.
|
||||
prerelease=false
|
||||
case "$version" in *-*) prerelease=true ;; esac
|
||||
|
||||
# Reuse the release if the tag was created via Gitea's release UI.
|
||||
release_id="$(curl -sS -H "Authorization: token ${TOKEN}" \
|
||||
"${api}/releases/tags/${GITHUB_REF_NAME}" | jq -r '.id // empty' || true)"
|
||||
|
||||
if [ -z "$release_id" ]; then
|
||||
release_id="$(curl -fsS -X POST "${api}/releases" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\",\"prerelease\":${prerelease}}" \
|
||||
| jq -r '.id')"
|
||||
fi
|
||||
|
||||
echo "Attaching ${zip} to release ${release_id}"
|
||||
curl -fsS -X POST \
|
||||
"${api}/releases/${release_id}/assets?name=unsupervised-schedular-${version}.zip" \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-F "attachment=@${zip}" > /dev/null
|
||||
Reference in New Issue
Block a user