-
Notifications
You must be signed in to change notification settings - Fork 6
275 lines (252 loc) · 9.74 KB
/
build-plugin-archive.yml
File metadata and controls
275 lines (252 loc) · 9.74 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
name: 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: 'yarn'
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.0"
required: false
type: string
PHP_VERSION_BUILD:
description: PHP version to use when executing build tools.
default: "8.0"
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
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
COMPOSER_AUTH: '${{ secrets.COMPOSER_AUTH_JSON }}'
# 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
outputs:
artifact: ${{ steps.set-artifact-name.outputs.artifact }}
steps:
- 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
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
run-build-tools:
name: Process build steps
timeout-minutes: 5
runs-on: ubuntu-latest
needs: checkout-dependencies
env:
NODE_OPTIONS: ${{ inputs.NODE_OPTIONS }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
NODE_CACHE_MODE: ''
outputs:
artifact: ${{ steps.set-artifact-name.outputs.artifact }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.checkout-dependencies.outputs.artifact }}
- name: Check optional Composer build tools
id: composer-tools
run: |
hasAssetConfig(){
test -f assets-compiler.json
local EXIT=$?
if [ ! $EXIT ]; then
echo "$EXIT"
exit 0
fi
jq '.extra | has("composer-asset-compiler")' < composer.json >/dev/null 2>&1
local EXIT=$?
echo "$EXIT"
}
hasTranslateConfig(){
jq '.extra | has("wp-translation-downloader")' < composer.json >/dev/null 2>&1
local EXIT=$?
echo "$EXIT"
}
echo "assets-compiler=$( hasAssetConfig )" >> $GITHUB_OUTPUT
echo "translation-downloader=$( hasTranslateConfig )" >> $GITHUB_OUTPUT
- 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
if: steps.composer-tools.outputs.assets-compiler == '0'
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}
cache: ${{ env.NODE_CACHE_MODE }}
- name: Install and run Composer Asset Compiler
if: steps.composer-tools.outputs.assets-compiler == '0'
run: |
composer global config --no-plugins --no-interaction allow-plugins.inpsyde/composer-assets-compiler true
composer global require inpsyde/composer-assets-compiler
composer compile-assets ${{ inputs.COMPILE_ASSETS_ARGS }}
- name: Install and run WordPress Translation Downloader
if: steps.composer-tools.outputs.translation-downloader == '0'
run: |
composer global config --no-plugins --no-interaction allow-plugins.composer/installers true
composer global config --no-plugins --no-interaction allow-plugins.inpsyde/wp-translation-downloader true
composer global require inpsyde/wp-translation-downloader
composer wp-translation-downloader:download
- 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: |
.
!**/node_modules
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 }}
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/*