Skip to content

Commit 864ab9a

Browse files
committed
Add plugin initialization script and workflow template
1 parent 76a5138 commit 864ab9a

7 files changed

Lines changed: 158 additions & 22 deletions

File tree

.github/workflows/ci.template.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Continuous Integration
2+
3+
on:
4+
push:
5+
branches: [ '*' ]
6+
tags: [ '*' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
jobs:
11+
ci:
12+
name: Run Quality Checks
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout Repository
17+
uses: actions/checkout@v4
18+
19+
- name: Set up PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: '8.2'
23+
tools: composer, phpunit, xdebug
24+
coverage: xdebug
25+
26+
- name: Install Dependencies
27+
run: composer install --no-progress --no-suggest --prefer-dist
28+
29+
- name: Run PHPUnit Tests
30+
run: vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage/clover.xml --path-coverage
31+
32+
- uses: qltysh/qlty-action/coverage@v1
33+
with:
34+
token: ${{ secrets.QLTY_COVERAGE_TOKEN }}
35+
files: coverage/clover.xml
36+
37+
build:
38+
name: Package Plugin
39+
runs-on: ubuntu-latest
40+
needs: ci
41+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
42+
43+
steps:
44+
- name: Checkout Repository
45+
uses: actions/checkout@v4
46+
47+
- name: Set up PHP
48+
uses: shivammathur/setup-php@v2
49+
with:
50+
php-version: '8.2'
51+
52+
- name: Install Dependencies
53+
run: composer install --no-dev --no-progress --prefer-dist
54+
55+
- name: Generate Plugin Header
56+
run: composer generate-header
57+
58+
- name: Make build script executable
59+
run: chmod +x build/build.sh
60+
61+
- name: Run build script
62+
run: ./build/build.sh
63+
64+
- name: Upload Artifact
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: xpub
68+
path: build/dist
69+
70+
release:
71+
name: Create GitHub Release
72+
runs-on: ubuntu-latest
73+
needs: build
74+
if: startsWith(github.ref, 'refs/tags/')
75+
permissions:
76+
contents: write
77+
78+
steps:
79+
- name: Download Build Artifact
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: xpub
83+
path: release/
84+
85+
- name: Re-zip downloaded artifact for GitHub Release
86+
run: |
87+
cd release
88+
zip -r ../xpub-multi-channel-publisher.zip .
89+
90+
91+
- name: Create GitHub Release
92+
uses: softprops/action-gh-release@v1
93+
with:
94+
body_path: release/xpub-multi-channel-publisher/CHANGELOG.md
95+
files: xpub-multi-channel-publisher.zip
96+
env:
97+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98+

.github/workflows/ci.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ composer.lock
5252

5353
# Build artifacts
5454
/build/dist/
55-
\n.phpunit.result.cache
55+
.phpunit.result.cache

bin/init-plugin.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env php
2+
<?php
3+
declare(strict_types=1);
4+
5+
$template = __DIR__ . '/../plugin-skeleton.php.dist';
6+
if (!file_exists($template)) {
7+
fwrite(STDERR, "Template $template not found.\n");
8+
exit(1);
9+
}
10+
11+
$slug = readline('Plugin slug: ');
12+
$slug = trim($slug);
13+
if ($slug === '') {
14+
fwrite(STDERR, "Invalid plugin slug.\n");
15+
exit(1);
16+
}
17+
18+
$pluginFile = __DIR__ . '/../' . $slug . '.php';
19+
if (file_exists($pluginFile)) {
20+
fwrite(STDERR, "File $pluginFile already exists.\n");
21+
exit(1);
22+
}
23+
24+
if (!copy($template, $pluginFile)) {
25+
fwrite(STDERR, "Failed to create plugin file.\n");
26+
exit(1);
27+
}
28+
29+
echo "Created plugin file $pluginFile\n";
30+
31+
$workflowTemplate = __DIR__ . '/../.github/workflows/ci.template.yml';
32+
if (file_exists($workflowTemplate)) {
33+
$workflow = file_get_contents($workflowTemplate);
34+
$workflow = str_replace(
35+
['xpub-multi-channel-publisher', 'xpub'],
36+
[$slug, $slug],
37+
$workflow
38+
);
39+
$workflowDir = __DIR__ . '/../.github/workflows';
40+
if (!is_dir($workflowDir)) {
41+
mkdir($workflowDir, 0777, true);
42+
}
43+
file_put_contents($workflowDir . '/ci.yml', $workflow);
44+
echo "Generated workflow at .github/workflows/ci.yml\n";
45+
} else {
46+
fwrite(STDERR, "Workflow template not found.\n");
47+
}
48+

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"generate-header": [
2020
"php generate-header.php"
2121
],
22-
"test": "vendor/bin/phpunit --configuration phpunit.xml"
22+
"test": "vendor/bin/phpunit --configuration phpunit.xml",
23+
"init-plugin": [
24+
"php bin/init-plugin.php"
25+
]
2326
}
2427
}

generate-header.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
declare(strict_types=1);
44

5-
$file = __DIR__ . '/plugin-skeleton.php';
65
$composer = json_decode(file_get_contents(__DIR__ . '/composer.json'), true);
6+
$slug = basename($composer['name'] ?? 'plugin');
7+
8+
// try default plugin-skeleton.php first for backwards compatibility
9+
$file = __DIR__ . '/plugin-skeleton.php';
10+
if (!file_exists($file)) {
11+
$file = __DIR__ . '/' . $slug . '.php';
12+
}
713

814
exec('git describe --tags --abbrev=0 2>/dev/null', $out, $exit);
915
$version = $exit === 0 ? trim($out[0]) : '0.1.0';

0 commit comments

Comments
 (0)