-
Notifications
You must be signed in to change notification settings - Fork 6
297 lines (264 loc) · 10.4 KB
/
build-plugin-archive.yml
File metadata and controls
297 lines (264 loc) · 10.4 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
name: [DEPRECATED] Create plugin archive
on:
workflow_call:
inputs:
NODE_OPTIONS:
description: Space-separated list of command-line Node options.
type: string
default: ''
required: false
NODE_VERSION:
description: Node version with which the assets will be compiled.
default: 18
required: false
type: string
NPM_REGISTRY_DOMAIN:
description: Domain of the private npm registry.
default: https://npm.pkg.github.com/
required: false
type: string
PACKAGE_MANAGER:
description: Package manager with which the dependencies should be installed (`npm` or `yarn`).
default: 'npm'
required: false
type: string
COMPOSER_ARGS:
description: Set of arguments passed to Composer when gathering production dependencies.
default: '--no-dev --prefer-dist --optimize-autoloader'
required: false
type: string
PHP_VERSION:
description: PHP version to use when gathering production dependencies.
default: '8.2'
required: false
type: string
PHP_VERSION_BUILD:
description: PHP version to use when executing build tools.
default: '8.2'
required: false
type: string
ARCHIVE_NAME:
description: The name of the zip archive (falls back to the repository name).
default: ''
required: false
type: string
PLUGIN_MAIN_FILE:
description: The name of the main plugin file.
required: false
default: 'index.php'
type: string
PLUGIN_FOLDER_NAME:
description: The name of the plugin folder (falls back to the archive name, if set, or the repository name).
required: false
default: ''
type: string
PLUGIN_VERSION:
description: The new plugin version.
required: true
type: string
PRE_SCRIPT:
description: Run custom shell code before creating the release archive.
default: ''
required: false
type: string
COMPILE_ASSETS_ARGS:
description: Set of arguments passed to Composer Asset Compiler.
default: '-v --env=root'
required: false
type: string
secrets:
COMPOSER_AUTH_JSON:
description: Authentication for privately hosted packages and repositories as a JSON formatted object.
required: false
NPM_REGISTRY_TOKEN:
description: Authentication for the private npm registry.
required: false
ENV_VARS:
description: Additional environment variables as a JSON formatted object.
required: false
outputs:
artifact:
description: The name of the generated release artifact
value: ${{ jobs.create-plugin-archive.outputs.artifact }}
jobs:
checkout-dependencies:
name: Install production dependencies
timeout-minutes: 5
runs-on: ubuntu-latest
outputs:
artifact: ${{ steps.set-artifact-name.outputs.artifact }}
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
# Disables symlinking of local path repositories.
# During development, symlinking is preferable.
# In resulting builds, you will likely want to ship the actual install location and remove the source directory.
COMPOSER_MIRROR_PATH_REPOS: 1
steps:
- name: Deprecation warning
run: echo "::warning::This workflow is deprecated and will be removed soon. Use .github/workflows/build-push.yml instead."
- name: Checkout
uses: actions/checkout@v4
- name: Set up custom environment variables
if: ${{ env.ENV_VARS }}
uses: actions/github-script@v7
with:
script: |
JSON
.parse(process.env.ENV_VARS)
.forEach(envVar => core.exportVariable(envVar.name, envVar.value));
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION }}
tools: wp-cli
- name: Install Composer dependencies without dev dependencies
uses: ramsey/composer-install@v3
env:
COMPOSER_AUTH: '${{ secrets.COMPOSER_AUTH_JSON }}'
with:
composer-options: ${{ inputs.COMPOSER_ARGS }}
- name: Set artifact name
id: set-artifact-name
run: echo "artifact=interim-deps" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-artifact-name.outputs.artifact }}
path: |
./*
!./.git
!./.ddev
!./.github
include-hidden-files: true
run-build-tools:
name: Process build steps
timeout-minutes: 10
runs-on: ubuntu-latest
needs: checkout-dependencies
env:
NODE_CACHE_MODE: ''
outputs:
artifact: ${{ steps.set-artifact-name.outputs.artifact }}
steps:
- name: PACKAGE_MANAGER deprecation warning
if: ${{ inputs.PACKAGE_MANAGER != '' }}
run: |
if [ "${{ inputs.PACKAGE_MANAGER }}" == 'npm' ]; then
echo "::warning::The PACKAGE_MANAGER input is deprecated and will be removed soon. Please remove it. The workflow already uses npm by default."
else
echo "::warning::The PACKAGE_MANAGER input is deprecated and will be removed soon. Please update your workflow to use npm."
fi
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.checkout-dependencies.outputs.artifact }}
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION_BUILD }}
tools: rector, php-scoper, sniccowp/php-scoper-wordpress-excludes, composer/installers, inpsyde/composer-assets-compiler, inpsyde/wp-translation-downloader
- name: Set up node cache mode
run: |
if [ "${{ inputs.PACKAGE_MANAGER }}" == 'npm' ] && { [ -f "${GITHUB_WORKSPACE}/package-lock.json" ] || [ -f "${GITHUB_WORKSPACE}/npm-shrinkwrap.json" ]; }; then
echo "NODE_CACHE_MODE=npm" >> $GITHUB_ENV
elif [ "${{ inputs.PACKAGE_MANAGER }}" == 'yarn' ] && [ -f "${GITHUB_WORKSPACE}/yarn.lock" ]; then
echo "NODE_CACHE_MODE=yarn" >> $GITHUB_ENV
else
echo "No lock files found or unknown package manager"
fi
- name: Set up node
uses: actions/setup-node@v4
env:
NODE_OPTIONS: ${{ inputs.NODE_OPTIONS }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}
cache: ${{ env.NODE_CACHE_MODE }}
- name: Run Composer Asset Compiler
run: |
composer compile-assets ${{ inputs.COMPILE_ASSETS_ARGS }}
- name: Run WordPress Translation Downloader
run: |
composer wp-translation-downloader:download
- name: Run Rector
if: ${{ hashFiles('rector.php') != '' }}
run: |
rector
- name: Run PHP-Scoper ensuring isolated file autoloading
if: ${{ hashFiles('scoper.inc.php') != '' }}
run: |
php-scoper add-prefix --force --output-dir=build
composer --working-dir=build dump-autoload -o
# Appends the Git commit SHA to the Composer autoload cache key to ensure unique identification for prefixed files.
# Prevents Composer from skipping autoloaded files due to hash collisions based on relative paths.
sed -i "s/'__composer_autoload_files'/\'__composer_autoload_files_${{ github.sha }}'/g" "build/vendor/composer/autoload_real.php"
- name: Move code to the `build/` directory
if: ${{ hashFiles('scoper.inc.php') == '' }}
run: |
shopt -s extglob dotglob
mkdir build
mv !(build) build
- name: Set artifact name
id: set-artifact-name
run: echo "artifact=interim-built" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-artifact-name.outputs.artifact }}
path: |
build/
!build/**/node_modules
include-hidden-files: true
create-plugin-archive:
name: Create build archive
timeout-minutes: 5
runs-on: ubuntu-latest
needs: run-build-tools
env:
ARCHIVE_NAME: ${{ inputs.ARCHIVE_NAME }}
PLUGIN_FOLDER_NAME: ${{ inputs.PLUGIN_FOLDER_NAME }}
GIT_SHA: ${{ github.sha }}
PLUGIN_VERSION: ${{ inputs.PLUGIN_VERSION }}
outputs:
artifact: ${{ steps.set-artifact-name.outputs.artifact }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.run-build-tools.outputs.artifact }}
- name: Set up plugin folder name
id: plugin-folder-name
run: echo "plugin-folder-name=${PLUGIN_FOLDER_NAME:-${ARCHIVE_NAME:-${{ github.event.repository.name }}}}" >> $GITHUB_OUTPUT
- name: Set up archive name
id: plugin-data
run: echo "archive-name=${ARCHIVE_NAME:-${{ github.event.repository.name }}}" >> $GITHUB_OUTPUT
- name: Add commit hash to plugin header
run: 'sed -Ei "s/SHA: .*/SHA: ${GIT_SHA}/g" ${{ inputs.PLUGIN_MAIN_FILE }}'
- name: Set plugin version header
run: 'sed -Ei "s/Version: .*/Version: ${PLUGIN_VERSION}/g" ${{ inputs.PLUGIN_MAIN_FILE }}'
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION_BUILD }}
tools: wp-cli
- name: Install dist-archive command
run: wp package install wp-cli/dist-archive-command
- name: Execute custom code before archive creation
run: |
${{ inputs.PRE_SCRIPT }}
- name: Run WP-CLI command
run: |
wp dist-archive . ./archive.zip --plugin-dirname=${{ steps.plugin-folder-name.outputs.plugin-folder-name }}
# GitHub Action artifacts would otherwise produce a zip within a zip
- name: Unzip archive to dist/
run: unzip archive.zip -d dist
- name: Set artifact name
id: set-artifact-name
run: echo "artifact=${{ steps.plugin-data.outputs.archive-name }}" >> $GITHUB_OUTPUT
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.set-artifact-name.outputs.artifact }}
path: ./dist/*
include-hidden-files: true