Skip to content

Commit 838fc71

Browse files
committed
ci: add release workflow with release-please
Adds a release-please-driven workflow on push to main: opens a release PR with version bumps and a generated CHANGELOG, creates the GitHub release and tag on merge, then builds a self-installable plugin zip and attaches it as a release asset. - release-please-config.json + .release-please-manifest.json track the version. plugin.php gets release-please block markers around the Version: header so the generic updater bumps it (block style rather than inline so WP's plugin header parser doesn't capture the marker into the version string). - Release zip is built via `git archive` filtered through .gitattributes (export-ignore for tests, agent docs, dev configs, etc.), with a copy of vendor/ from `composer install --no-dev --optimize-autoloader --classmap-authoritative`. - plugin.php has a `// @bundle-autoload` marker that's sed-replaced with `require_once __DIR__ . '/vendor/autoload.php';` only in the release zip, so the source stays clean for Composer-managed installs (Bedrock-style) while the zip works as a drop-in plugin for vanilla WP. - Tags are emitted without the `v` prefix.
1 parent 3f7cd32 commit 838fc71

5 files changed

Lines changed: 109 additions & 3 deletions

File tree

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Files and directories to omit from `git archive` output (release zips).
2+
# Anything tracked but not needed at runtime in a distributed plugin.
3+
4+
/.claude export-ignore
5+
/.github export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.release-please-manifest.json export-ignore
9+
/assets export-ignore
10+
/docs export-ignore
11+
/package.json export-ignore
12+
/pnpm-lock.yaml export-ignore
13+
/release-please-config.json export-ignore
14+
/tests export-ignore
15+
/*.dist export-ignore

.github/workflows/release.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions: {}
9+
10+
concurrency:
11+
group: release-${{ github.ref }}
12+
cancel-in-progress: false
13+
14+
jobs:
15+
release-please:
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 5
18+
permissions:
19+
contents: write
20+
pull-requests: write
21+
outputs:
22+
release_created: ${{ steps.rp.outputs.release_created }}
23+
tag_name: ${{ steps.rp.outputs.tag_name }}
24+
version: ${{ steps.rp.outputs.version }}
25+
steps:
26+
- id: rp
27+
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
28+
29+
build:
30+
needs: release-please
31+
if: needs.release-please.outputs.release_created == 'true'
32+
runs-on: ubuntu-latest
33+
timeout-minutes: 15
34+
permissions:
35+
contents: write
36+
steps:
37+
- uses: actions/checkout@v6
38+
39+
- uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
40+
with:
41+
php-version: '8.2'
42+
coverage: none
43+
44+
- uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
45+
with:
46+
composer-options: '--no-dev --optimize-autoloader --classmap-authoritative'
47+
48+
- name: Build release zip
49+
env:
50+
VERSION: ${{ needs.release-please.outputs.version }}
51+
run: |
52+
mkdir -p dist
53+
# Tracked files only, with .gitattributes export-ignore filtering applied.
54+
git archive --prefix=page-for-custom-post-type/ HEAD | tar -x -C dist
55+
# vendor/ is gitignored, so git archive doesn't include it. Copy it in.
56+
cp -r vendor dist/page-for-custom-post-type/vendor
57+
# Inject the bundled-only autoload require.
58+
sed -i "s|// @bundle-autoload|require_once __DIR__ . '/vendor/autoload.php';|" dist/page-for-custom-post-type/plugin.php
59+
grep -q "require_once __DIR__ . '/vendor/autoload.php';" dist/page-for-custom-post-type/plugin.php \
60+
|| { echo "::error::bundle autoload marker replacement failed"; exit 1; }
61+
php -l dist/page-for-custom-post-type/plugin.php
62+
(cd dist && zip -rq "../page-for-custom-post-type-${VERSION}.zip" page-for-custom-post-type)
63+
64+
- name: Upload zip to release
65+
env:
66+
GH_TOKEN: ${{ github.token }}
67+
TAG: ${{ needs.release-please.outputs.tag_name }}
68+
VERSION: ${{ needs.release-please.outputs.version }}
69+
run: gh release upload "$TAG" "page-for-custom-post-type-${VERSION}.zip" --clobber

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.5.0"
3+
}

plugin.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
* Plugin Name: Page for custom post type
55
* Plugin URI: https://github.com/nlemoine/page-for-custom-post-type
66
* Description: Allows you to set pages for any custom post type archive
7+
* x-release-please-start-version
78
* Version: 0.5.0
9+
* x-release-please-end
810
* Author: Nicolas Lemoine
911
* Author URI: https://n5s.dev/
1012
* Requires PHP: 8.2
@@ -14,13 +16,13 @@
1416

1517
namespace n5s\PageForCustomPostType;
1618

17-
use n5s\PageForCustomPostType\Integration\IntegrationInterface;
18-
1919
// Prevent direct access
20-
if (!defined('ABSPATH')) {
20+
if (!\defined('ABSPATH')) {
2121
exit;
2222
}
2323

24+
// @bundle-autoload
25+
2426
// Load translations on init (plugin is not on wordpress.org, so the
2527
// auto-loading introduced in WP 4.6 doesn't apply).
2628
add_action('init', static function (): void {

release-please-config.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3+
"include-v-in-tag": false,
4+
"packages": {
5+
".": {
6+
"release-type": "node",
7+
"package-name": "page-for-custom-post-type",
8+
"include-component-in-tag": false,
9+
"extra-files": [
10+
{
11+
"type": "generic",
12+
"path": "plugin.php"
13+
}
14+
]
15+
}
16+
}
17+
}

0 commit comments

Comments
 (0)