Repository navigation
93 lines (79 loc) · 3.02 KB
/
Copy pathrelease-plugin.yml
File metadata and controls
93 lines (79 loc) · 3.02 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
# Builds a plugin zip and attaches it to the GitHub Release that release-please created.
# Called by release-please.yml; can also be run by hand to rebuild a release's zip.
name: Release Plugin
on:
workflow_call:
inputs:
path:
description: 'Plugin path (e.g. plugins/hwp-previews)'
required: true
type: string
workflow_dispatch:
inputs:
path:
description: 'Plugin path (e.g. plugins/hwp-previews)'
required: true
type: string
tag:
description: 'Release tag to rebuild (e.g. @wpengine/hwp-previews-wordpress-plugin-1.0.2)'
required: true
type: string
permissions:
contents: write
jobs:
build:
name: Build and upload plugin archive
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag || github.sha }}
- name: Read package metadata
id: metadata
env:
PLUGIN_DIR: ${{ inputs.path }}
run: |
if [ ! -f "$PLUGIN_DIR/package.json" ]; then
echo "package.json not found in $PLUGIN_DIR"
exit 1
fi
package_name=$(jq -r '.name' "$PLUGIN_DIR/package.json")
package_version=$(jq -r '.version' "$PLUGIN_DIR/package.json")
# Matches the tag format in release-please-config.json
echo "tag=${package_name}-${package_version}" >> "$GITHUB_OUTPUT"
echo "version=$package_version" >> "$GITHUB_OUTPUT"
echo "slug=$(basename "$PLUGIN_DIR")" >> "$GITHUB_OUTPUT"
- name: Setup PHP and install production dependencies
uses: ./.github/actions/setup-php-composer
with:
php-version: '8.2' # Note: All plugins are compatible with PHP 8.2
working-directory: ${{ inputs.path }}
composer-options: '--no-progress --optimize-autoloader --no-dev'
- name: Validate composer setup
working-directory: ${{ inputs.path }}
run: composer validate --no-check-publish --no-check-lock
- name: Create plugin archive
working-directory: ${{ inputs.path }}
env:
SLUG: ${{ steps.metadata.outputs.slug }}
run: |
rm -f "plugin-build/$SLUG.zip"
composer archive -vvv --format=zip --file="plugin-build/$SLUG" --dir="."
if [ ! -f "plugin-build/$SLUG.zip" ]; then
echo "Failed to create plugin archive"
exit 1
fi
echo "Archive created successfully: $(ls -lh "plugin-build/$SLUG.zip")"
- name: Upload archive to GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.metadata.outputs.tag }}
VERSION: ${{ steps.metadata.outputs.version }}
ARCHIVE: ${{ inputs.path }}/plugin-build/${{ steps.metadata.outputs.slug }}.zip
run: |
gh release upload "$TAG" "$ARCHIVE" --clobber
# 0.x versions are pre-releases
if [[ "$VERSION" =~ ^0\. ]]; then
gh release edit "$TAG" --prerelease
fi