344 lines (308 loc) · 12.5 KB
/
create-release.yml
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
name: Create Release
on:
workflow_call:
inputs:
themes: # A JSON formatted array of theme folder name(s) we need to build
description: 'A JSON formatted array of plugin folder name(s) to build. Example: ["linchpin-mmxxii"]'
default: '["none"]'
required: false
type: string
plugins: # A JSON formatted array of plugins folder name(s) we need to build
description: 'A JSON formatted array of plugin folder name(s) to build. Example: ["linchpin-functionality"]'
default: '["none"]'
required: false
type: string
php_version:
description: 'PHP version used during build (Default 7.4.x)'
default: 7.4
required: false
type: number
node_version:
description: 'Node version used during build (Default 14.x)'
default: 14
required: false
type: number
skip_create_release:
description: 'If we only need our release built for staging, we can skip creating an official github release'
default: false
required: false
type: boolean
theme_composer_install:
description: 'Run composer install on the theme level'
default: false
required: false
type: boolean
composer_install:
description: 'Run composer install on the project level to install plugins'
default: false
required: false
type: boolean
theme_package_manager:
description: 'Package manager npm/yarn'
default: 'yarn'
type: string
plugin_package_manager:
description: 'Package manager npm/yarn'
default: 'yarn'
type: string
plugin_composer_install:
description: 'Run composer install on the functionality level'
default: false
required: false
type: boolean
package_manager:
description: 'Package manager npm/yarn'
default: 'yarn'
type: string
secrets:
packagist_auth:
description: 'Authentication for private satis/packagist'
required: true
bot_token:
description: 'Override Bot Token'
required: false
jobs:
dependency_setup:
name: Composer Dependency Setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
path: 'build'
- name: Authenticate Packagist
run: echo '${{ secrets.packagist_auth }}' > ./build/auth.json
- name: Cache Composer dependencies
uses: actions/cache@v3
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Composer Install
uses: php-actions/composer@v6
with:
working_dir: ./build
dev: no
php_version: ${{ inputs.php_version }}
- name: Remove Packagist Authentication
run: rm -f ./build/auth.json
- name: Compress Composer Artifact
id: composer_compression_artifact
run: |
tar -zcf composer.tar.gz ./build
- name: Upload Dependencies
uses: actions/upload-artifact@v3
with:
path: composer.tar.gz
retention-days: 1 # since we keep a release we do not need to store an artifact too long
theme_setup:
name: Build WordPress Theme(s)
runs-on: ubuntu-latest
strategy:
matrix:
theme: ${{ fromJSON( inputs.themes ) }}
steps:
- name: Theme Setup
id: individal_theme
if: ${{ matrix.theme == 'none' }}
run: |
echo "::warning::Skipping Theme Build"
- name: Checkout code
if: ${{ matrix.theme != 'none' }} # skip this step if no themes are included.
uses: actions/checkout@v3
- name: Composer Theme Update
id: composer-theme-update
if: ${{ matrix.theme != 'none' && inputs.theme_composer_install }} # skip this step if no themes are included.
run: |
cd themes/${{ matrix.theme }}
test -f composer.json && composer update
- name: Setup Node.js
if: ${{ matrix.theme != 'none' }} # skip this step if no themes are included.
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ inputs.node_version }}
- name: Get yarn cache directory path
if: ${{ matrix.theme != 'none' && inputs.theme_package_manager == 'yarn' }} # skip this step if no themes are included.
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Get npm cache directory
id: npm-cache-dir
if: ${{ matrix.theme != 'none' && inputs.theme_package_manager == 'npm' }} # skip this step if no themes are included.
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Cache yarn cache
if: ${{ matrix.theme != 'none' && inputs.theme_package_manager == 'yarn' }} # skip this step if no themes are included.
uses: actions/cache@v3
id: cache-yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Build Theme with yarn
if: ${{ matrix.theme != 'none' && inputs.build_theme_js != 'false' && inputs.theme_package_manager == 'yarn' }} # skip this step if no themes are included or we tell it to skip
id: build-theme
run: |
cd themes/${{ matrix.theme }}
yarn install # @todo exclude dev libraries (make initial non cached build faster)
yarn build
- name: Build Theme with npm
if: ${{ matrix.theme != 'none' && inputs.build_theme_js != 'false' && inputs.theme_package_manager == 'npm' }} # skip this step if no themes are included or we tell it to skip
id: build-theme-npm
run: |
cd themes/${{ matrix.theme }}
npm install # @todo exclude dev libraries (make initial non cached build faster)
npm run build
- name: Compress Theme Artifact
id: compress_theme_artifact
if: ${{ matrix.theme != 'none' }} # skip this step if no themes are included.
run: |
tar -zcf theme-${{ matrix.theme }}.tar.gz --exclude "node_modules" themes/${{ matrix.theme }}
- name: Upload Theme
uses: actions/upload-artifact@v3
if: ${{ matrix.theme != 'none' }} # skip this step if no themes are included.
with:
path: theme-${{ matrix.theme }}.tar.gz
retention-days: 1 # since we keep a release we do not need to store an artifact too long
# Loop through all plugins passed from inputs.plugins
plugin_setup:
name: Plugin(s)
runs-on: ubuntu-latest
strategy:
matrix:
plugin: ${{ fromJSON( inputs.plugins ) }}
steps:
# check if we have a theme to build. If None output and skip the rest of the steps.
- name: Plugin Setup
id: individual_plugin
if: ${{ matrix.plugin == 'none' }}
run: |
echo "::warning::Skipping Plugin Build"
- name: Checkout code
if: ${{ matrix.plugin != 'none' }} # skip this step if no plugins are included.
uses: actions/checkout@v3
- name: Composer Theme Update
id: composer-theme-update
if: ${{ matrix.plugin != 'none' && inputs.plugin_composer_install }} # skip this step if no themes are included.
run: |
cd plugins/${{ matrix.plugin }}
test -f composer.json && composer update
- name: Setup Node.js
if: ${{ matrix.plugin != 'none' }} # skip this step if no plugins are included.
uses: actions/setup-node@v3.6.0
with:
node-version: ${{ inputs.node_version }}
- name: Get yarn cache directory path
if: ${{ matrix.plugin != 'none' && inputs.plugin_package_manager == 'yarn' }} # skip this step if no plugins are included.
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Get npm cache directory
id: npm-cache-dir
if: ${{ matrix.plugin != 'none' && inputs.plugin_package_manager == 'npm' }} # skip this step if no plugins are included.
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Cache yarn cache
if: ${{ matrix.plugin != 'none' && inputs.plugin_package_manager == 'yarn' }} # skip this step if no plugins are included.
uses: actions/cache@v3
id: cache-yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Build Plugin with yarn
if: ${{ matrix.plugin != 'none' && inputs.plugin_package_manager == 'yarn' }} # skip this step if no plugins are included.
id: build-plugin
run: |
cd plugins/${{ matrix.plugin }}
yarn install # @todo exclude dev libraries (make initial non cached build faster)
yarn build
- name: Build Plugin with npm
if: ${{ matrix.plugin != 'none' && inputs.plugin_package_manager == 'npm' }} # skip this step if no plugins are included.
id: build-plugin-npm
run: |
cd plugins/${{ matrix.plugin }}
npm install # @todo exclude dev libraries (make initial non cached build faster)
npm run build
- name: Compress Plugin Artifact
if: ${{ matrix.plugin != 'none' }} # skip this step if no plugins are included.
id: compress_plugin_artifact
run:
tar -zcf plugin-${{ matrix.plugin }}.tar.gz --exclude "node_modules" plugins/${{ matrix.plugin }}
- name: Upload Plugin
if: ${{ matrix.plugin != 'none' }} # skip this step if no themes are included.
uses: actions/upload-artifact@v3
with:
path: plugin-${{ matrix.plugin }}.tar.gz
build:
name: Build Release Zip
runs-on: ubuntu-latest
needs: [dependency_setup,theme_setup,plugin_setup]
steps:
- name: Download All Artifacts
uses: actions/download-artifact@v3
with:
path: ./
- name: Decompress Composer Artifacts
id: decompress_composer_artifacts
run: |
tar -xzf ./artifact/composer.tar.gz -C ./
- name: Decompress Theme Artifacts
if: ${{ inputs.themes != '["none"]' }} # skip this step if no themes are included.
id: decompress_theme_artifacts
run: |
cd ./artifact
cat theme-*.tar.gz | tar -xzf - -i -C ../build/
cd ../
- name: Decompress Plugin Artifacts
if: ${{ inputs.plugins != '["none"]' }} # skip this step if no themes are included.
id: decompress_plugin_artifacts
run: |
cd ./artifact
cat plugin-*.tar.gz | tar -xzf - -i -C ../build/
cd ../
- name: Clean Build Files/Folders
id: clean_build_ff
run: |
mkdir -p ./build/.deployment/
cd ./build/.deployment/
wget -O cleanup.sh https://raw.githubusercontent.com/linchpin/actions/main/.deployment/cleanup.sh
chmod +x ./cleanup.sh
sh ./cleanup.sh
cd ../../
rm -rf ./build/.deployment/
- name: Get Current Version
id: version
run: |
echo ::set-output name=tag::${GITHUB_REF#refs/tags/v}
# Latest changelog entry is based on version. If not found, fall back to the last version
- name: Get Latest CHANGELOG.md Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
with:
validation_depth: 10
version: ${{ steps.version.current }}
path: ./build/CHANGELOG.md
- name: Combine Assets for Release
id: compression
run: |
zip -r release.zip ./temp_archive
- name: Upload Release Artifact
uses: actions/upload-artifact@v3
with:
name: release
path: release.zip
retention-days: 1 # since we keep a release we do not need to store an artifact too long
- name: Create Release
id: create_release
if: ${{ ! inputs.skip_github_release }}
uses: softprops/action-gh-release@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag_name: ${{ github.ref }}
name: Release ${{ github.ref }}
generate_release_notes: true
body: |
${{ steps.changelog_reader.outputs.changes }}
draft: false
prerelease: false
files: release.zip