-
Notifications
You must be signed in to change notification settings - Fork 0
255 lines (230 loc) · 9.4 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
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: 8.0
required: false
type: number
node_version:
description: 'Node version used during build (Default 14.x)'
default: 20
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
plugin_composer_install:
description: 'Run composer install on the functionality plugin'
default: false
required: false
type: boolean
build_theme_js:
description: 'Build the theme JS'
default: false
required: false
type: boolean
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@v4
with:
path: 'build'
- name: Authenticate Packagist
run: echo '${{ secrets.packagist_auth }}' > ./build/auth.json
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Composer Install
run: composer install --no-dev --no-interaction --no-progress --no-suggest --optimize-autoloader
- name: Remove Packagist Authentication
run: rm -f ./build/auth.json
- name: Upload Dependencies
uses: actions/upload-artifact@v4
with:
name: composer
path: |
./build/
!./build/**/node_modules
retention-days: 1 # since we keep a release we do not need to store an artifact too long
overwrite: true
include-hidden-files: true
compression-level: 9
theme_setup:
name: Build WordPress Theme(s)
runs-on: ubuntu-latest
strategy:
matrix:
theme: ${{ fromJSON( inputs.themes ) }}
steps:
- name: Theme Setup Confirmation
id: theme-setup-confirmation
if: ${{ matrix.theme == 'none' }}
run: |
echo "::warning::Skipping Theme Build, no theme defined"
- name: Composer Update for ${{ matrix.theme }} theme
id: theme-composer-update
# Make sure we have a theme, the theme uses composer and the composer.json exists
if: ${{ matrix.theme != 'none' && inputs.theme_composer_install && hashFiles('themes/${{ matrix.theme }}/composer.json') != '' }} # skip this step if no themes are included.
run: composer update --working-dir=themes/${{ matrix.theme }}
- name: Setup Node for ${{ matrix.theme }} theme
id: theme-node-setup
# Make sure we have a theme, the theme uses npm and the composer.json exists
if: ${{ matrix.theme != 'none' && hashFiles( 'themes/${{ matrix.theme }}/package-lock.json' ) != '' }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}
cache: 'npm'
cache-dependency-path: themes/${{ matrix.theme }}/package-lock.json
- name: Build WordPress Theme (${{ matrix.theme }}) using npm
if: ${{ matrix.theme != 'none' && inputs.build_theme_js != 'false' && hashFiles( 'themes/${{ matrix.theme }}/package-lock.json' ) != '' }}
id: build-theme-npm
run: |
cd themes/${{ matrix.theme }}
npm config set cache $(npm config get cache)
npm install --production
npm run build
- name: Upload WordPress Theme (${{ matrix.theme }}) Artifact
uses: actions/upload-artifact@v4
if: ${{ matrix.theme != 'none' }} # skip this step if no themes are included.
with:
path: |
themes/${{ matrix.theme }}/
!themes/${{ matrix.theme }}/**/node_modules
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: WordPress Plugin(s) Setup
runs-on: ubuntu-latest
strategy:
matrix:
plugin: ${{ fromJSON( inputs.plugins ) }}
steps:
# check if we have a plugin to build. If None output and skip the rest of the steps.
- name: Plugin Setup Confirmation
id: individual_plugin
if: ${{ matrix.plugin == 'none' }}
run: |
echo "::warning::Skipping Plugin Build, no plugin defined"
- name: Composer Update for ${{ matrix.plugin }} plugin
id: composer-plugin-update
# Make sure we have a plugin, the plugin uses composer and the composer.json exists
if: ${{ matrix.plugin != 'none' && inputs.plugin_composer_install && hashFiles( 'plugins/${{ matrix.plugin }}composer.json ' ) != '' }} # skip this step if no themes are included.
run: composer update --working-dir=plugins/${{ matrix.plugin }}
- name: Setup Node for ${{ matrix.plugin }} WordPress plugin
if: ${{ matrix.plugin != 'none' && hashFiles( 'themes/${{ matrix.theme }}/package-lock.json' ) != '' }} # skip this step if no themes are included.
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}
cache: 'npm'
cache-dependency-path: themes/${{ matrix.plugin }}/package-lock.json
- name: Build WordPress Plugin (${{ matrix.plugin }}) using npm
if: ${{ matrix.plugin != 'none' }} # skip this step if no plugins are included.
id: build-plugin-npm
run: |
cd plugins/${{ matrix.plugin }}
npm install --production
npm run build
- name: Upload WordPress Theme (${{ matrix.plugin }}) Artifact
uses: actions/upload-artifact@v4
if: ${{ matrix.plugin != 'none' }} # skip this step if no themes are included.
with:
path: |
plugins/${{ matrix.plugin }}/
!plugins/${{ matrix.plugin }}/**/node_modules
retention-days: 1 # since we keep a release we do not need to store an artifact too long
build:
name: Build Release Zip
runs-on: ubuntu-latest
needs: [ dependency_setup, theme_setup, plugin_setup ]
steps:
- name: Download All Artifacts
uses: actions/[email protected]
with:
path: ./build
merge-multiple: true # Download all artifacts into the same directory
- 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/v3/.deployment/cleanup.sh
chmod +x ./cleanup.sh
sh ./cleanup.sh
cd ../../
rm -rf ./build/.deployment/
- name: Get Current Version
id: version
run: echo "tag=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Combine Assets for Release
id: compression
run: |
zip -r release.zip ./temp_archive
- name: Upload Release Artifact
uses: actions/upload-artifact@v4
with:
name: release
path: release.zip
retention-days: 1 # since we keep a release we do not need to store an artifact too long
# 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.outputs.tag }}
path: ./build/CHANGELOG.md
- name: Create Release
id: create_release
if: ${{ ! inputs.skip_github_release && startsWith( github.ref, 'refs/tags/' ) }}
uses: softprops/action-gh-release@v2
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