-
Notifications
You must be signed in to change notification settings - Fork 0
322 lines (278 loc) · 18.9 KB
/
generate_plugins.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
####################################################################################
# GitHub Action:
# Whenever creating a new release of the source code,
# also create a release of the installable plugin,
# and downgrading it from PHP 8.1 to 7.4 to support more users.
####################################################################################
# Steps to execute:
# - Checkout the source code
# - Run "composer install" for development, to install dependencies for Rector
# - Run Rector to downgrade code from PHP 8.1 to 7.4
# - Run "composer install" for production (required dependencies are already under vendor/)
# - Create a .zip file, excluding:
# - All hidden files (.git, .gitignore, etc)
# - Rector file
# - All development files, ending in .dist
# - All composer files <= after installing dependencies, no need for them anymore
# - Markdown files concerning development
# - Folder build/ <= created only to store the .zip file
# - Folder dev-helpers/ <= not needed for the plugin
# - Upload the .zip file as an artifact to the action (this step is possibly optional)
# - Upload the .zip file as a release, for download
#
# You can filter what .zip files to generate by type, by setting variable
# `GENERATE_PLUGINS_FILTER` with any of these values:
# - extension
# - bundle
# - standalone-plugin
####################################################################################
name: Generate plugins
on:
release:
types: [published]
push:
branches:
- main
- versions/*
pull_request: null
env:
CHECKOUT_SUBMODULES: "recursive"
GENERATE_PLUGINS_FILTER: ""
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
COMPOSER_ROOT_VERSION: dev-main
jobs:
provide_data:
name: Provide configuration to generate plugins
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: ${{ env.CHECKOUT_SUBMODULES }}
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: ramsey/composer-install@v3
- id: output_data
run: |
quote=\'
filter_arg="--filter=$(echo '${{ env.GENERATE_PLUGINS_FILTER }}' | sed -e 's/ / --filter=/g')"
echo "plugin_config_entries=$(vendor/bin/monorepo-builder plugin-config-entries-json $(echo $filter_arg) --config=config/monorepo-builder/plugin-config-entries-json.php)" >> $GITHUB_OUTPUT
echo "retention_days_for_generated_plugins=$(vendor/bin/monorepo-builder env-var RETENTION_DAYS_FOR_GENERATED_PLUGINS --config=config/monorepo-builder/env-var.php)" >> $GITHUB_OUTPUT
echo "local_package_owners=$(vendor/bin/monorepo-builder local-package-owners --config=config/monorepo-builder/local-package-owners.php)" >> $GITHUB_OUTPUT
echo "git_base_branch=$(vendor/bin/monorepo-builder env-var GIT_BASE_BRANCH --config=config/monorepo-builder/env-var.php)" >> $GITHUB_OUTPUT
echo "git_user_name=$(vendor/bin/monorepo-builder env-var GIT_USER_NAME --config=config/monorepo-builder/env-var.php)" >> $GITHUB_OUTPUT
echo "git_user_email=$(vendor/bin/monorepo-builder env-var GIT_USER_EMAIL --config=config/monorepo-builder/env-var.php)" >> $GITHUB_OUTPUT
outputs:
plugin_config_entries: ${{ steps.output_data.outputs.plugin_config_entries }}
retention_days: ${{ steps.output_data.outputs.retention_days_for_generated_plugins }}
local_package_owners: ${{ steps.output_data.outputs.local_package_owners }}
git_base_branch: ${{ steps.output_data.outputs.git_base_branch }}
git_user_name: ${{ steps.output_data.outputs.git_user_name }}
git_user_email: ${{ steps.output_data.outputs.git_user_email }}
# Build plugin => downgrade => (maybe) scope => (maybe) upload to release and deploy to dist repo
process:
name: Generate plugin "${{ matrix.pluginConfig.plugin_slug }}"
needs: provide_data
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pluginConfig: ${{ fromJson(needs.provide_data.outputs.plugin_config_entries) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: ${{ env.CHECKOUT_SUBMODULES }}
- name: Create build folder
run: mkdir build && mkdir build/dist-plugin
- name: Install zip
uses: montudor/[email protected]
# pcre.jit=0 => @see https://github.com/composer/composer/issues/9595
- name: Use PHP 8.1
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none
ini-values: pcre.jit=0
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install root dependencies
uses: ramsey/composer-install@v3
###########################################################################
# Downgrade plugin
###########################################################################
# "custom-bump-interdependency" temporarily needed because of bug:
# https://github.com/symplify/symplify/issues/2773
- name: Localize package paths
run: |
vendor/bin/monorepo-builder custom-bump-interdependency --config=config/monorepo-builder/custom-bump-interdependency.php "dev-${{ needs.provide_data.outputs.git_base_branch }}"
vendor/bin/monorepo-builder localize-composer-paths --config=config/monorepo-builder/localize-composer-paths.php ${{ matrix.pluginConfig.path }}/composer.json --ansi
###########################################################################
# When building bundles (i.e. containing 2 or more extension plugins), if 2 extensions
# contain the same entry under "replace" in composer.json, then "require"ing both of
# them in the bundle fails.
#
# For instance, several plugins replace "pop-schema/schema-commons", producing
# the following error message:
#
# > Only one of these can be installed: pop-schema/schema-commons[dev-master], gatographql-pro/php-constants-and-environment-variables-via-schema[dev-master], gatographql-pro/helper-function-collection[dev-master]. [gatographql-pro/php-constants-and-environment-variables-via-schema, gatographql-pro/helper-function-collection] replace pop-schema/schema-commons and thus cannot coexist with it.
#
# As a solution, when generating the bundle plugin, remove all the "replace" entries
# in the composer.json for the included plugins, and move them to the bundle composer.json
###########################################################################
- name: "Bundles: Transfer the 'replace' entries in composer.json, from the contained plugins to the bundle"
run: |
vendor/bin/monorepo-builder transfer-composer-replace-entries-from-plugins-to-bundle --config=config/monorepo-builder/transfer-composer-replace-entries-from-plugins-to-bundle.php "${{ matrix.pluginConfig.path }}/composer.json" --exclude-replace="${{ matrix.pluginConfig.exclude_replace }}"
if: ${{ matrix.pluginConfig.is_bundle }}
###########################################################################
# When building standalone plugins, the "replace" entries from the bundled
# extensions must be ignored, as these must also be contained within the
# standalone plugin (which also contains Gato GraphQL).
#
# Because standalone plugins are bundles, in the previous step the
# "replace" entries have been moved up from the bundled extensions
# to the bundle's composer.json. Now, remove them.
###########################################################################
- name: "Standalone plugins: Remove the 'replace' entries in composer.json (originally from the contained plugins, now in the bundle)"
run: |
vendor/bin/monorepo-builder remove-composer-replace-entries --config=config/monorepo-builder/remove-composer-replace-entries.php "${{ matrix.pluginConfig.path }}/composer.json"
if: ${{ matrix.pluginConfig.is_standalone_plugin }}
- name: Install plugin dependencies, avoiding v2 platform check
run: |
composer config platform-check false --no-interaction --ansi
composer install --no-progress --no-interaction --ansi
working-directory: ${{ matrix.pluginConfig.path }}
# before_downgrade_code.sh => Hacks to fix the codebase in preparation of the Rector downgrade
- name: Custom bash script to fix items in the code in preparation for the Rector downgrade
run: "$GITHUB_WORKSPACE/${{ matrix.pluginConfig.bashScripts.before_downgrade_code }}"
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.bashScripts.before_downgrade_code }}
# additional_rector_after_configs => Hack to fix bug: https://github.com/rectorphp/rector/issues/5962
- name: Downgrade code for production (to PHP 7.4)
run: submodules/GatoGraphQL/ci/downgrade/downgrade_code.sh "${{ matrix.pluginConfig.rector_downgrade_config }}" "" "${{ matrix.pluginConfig.path }}" "${{ matrix.pluginConfig.additional_rector_before_configs }}" "${{ matrix.pluginConfig.additional_rector_after_configs }}" "${{ needs.provide_data.outputs.local_package_owners }}"
# after_downgrade_code.sh => Hacks to fix the codebase whenever Rector cannot handle it
- name: Custom bash script to fix items in the code that Rector cannot handle
run: "$GITHUB_WORKSPACE/${{ matrix.pluginConfig.bashScripts.after_downgrade_code }}"
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.bashScripts.after_downgrade_code }}
################################################################################
- name: Replace PHP version in plugin main file
run: |
sed -i 's/Requires PHP: 8.1/Requires PHP: 7.4/' ${{ matrix.pluginConfig.main_file }}
working-directory: ${{ matrix.pluginConfig.path }}
- name: Check if readme.txt exists
uses: andstor/file-existence-action@v3
id: check_readme_exists
with:
files: "${{ matrix.pluginConfig.path }}/readme.txt"
- name: Replace PHP version in plugin readme file
run: |
sed -i 's/Requires PHP: 8.1/Requires PHP: 7.4/' readme.txt
if: steps.check_readme_exists.outputs.files_exists == 'true'
working-directory: ${{ matrix.pluginConfig.path }}
# Add the commit hash to the plugin version, to regenerate the container when testing the generated plugin
- name: Append the the commit hash to the plugin/extension version
run: |
sed -i "s/$commitHash = null;/$commitHash = '${{ github.sha }}';/" ${{ matrix.pluginConfig.main_file }}
working-directory: ${{ matrix.pluginConfig.path }}
- name: Build project for production
run: composer install --no-dev --optimize-autoloader --no-progress --no-interaction --ansi
working-directory: ${{ matrix.pluginConfig.path }}
###########################################################################
# Scope plugin
# Only execute when enabled by configuration
###########################################################################
- name: Install PHP-Scoper
run: |
composer global config minimum-stability dev
composer global config prefer-stable true
composer global require humbug/php-scoper
if: ${{ matrix.pluginConfig.scoping }}
# (Current situation) If the scoped results correspond to vendor/ only, we must do "--output-dir ../prefixed-plugin/vendor"
# (Not happening now) If they also include src/, we must do "--output-dir ../prefixed-plugin"
- name: Scope code for 3rd-party dependencies into separate folder
run: ~/.composer/vendor/bin/php-scoper add-prefix --config=${{ matrix.pluginConfig.scoping.phpscoper_config.external }} --output-dir $GITHUB_WORKSPACE/build/prefixed-plugin/vendor --ansi --no-interaction
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.scoping.phpscoper_config.external }}
- name: Copy scoped 3rd-party dependencies code back to source folder
run: rsync -av build/prefixed-plugin/ ${{ matrix.pluginConfig.path }} --quiet
if: ${{ matrix.pluginConfig.scoping.phpscoper_config.external }}
# (Optional) Also scope own classes (eg: for creating a standalone plugin)
- name: Scope own code into separate folder
run: ~/.composer/vendor/bin/php-scoper add-prefix --config=${{ matrix.pluginConfig.scoping.phpscoper_config.internal }} --output-dir $GITHUB_WORKSPACE/build/prefixed-plugin-internal --ansi --no-interaction
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.scoping.phpscoper_config.internal }}
- name: Copy scoped own code back to source folder
run: rsync -av build/prefixed-plugin-internal/ ${{ matrix.pluginConfig.path }} --quiet
if: ${{ matrix.pluginConfig.scoping.phpscoper_config.internal }}
- name: Regenerate autoloader
run: composer dumpautoload --optimize --classmap-authoritative --ansi
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.scoping }}
- name: Use Scoper autoload in plugin main file
run: |
sed -i 's/autoload.php/scoper-autoload.php/' ${{ matrix.pluginConfig.main_file }}
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.scoping }}
- name: Remove all function aliases from scoper-autoload.php
run: |
sed -i -E 's/(if \(\!function_exists\(.+\)\) \{ function)/\/\/ \1/' vendor/scoper-autoload.php
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.scoping }}
###########################################################################
# Generate plugin, and Upload as artifact
###########################################################################
- name: Create plugin as zip
run: zip -X -r $GITHUB_WORKSPACE/build/${{ matrix.pluginConfig.zip_file }}.zip . -x *.git* node_modules/\* .* "*/\.*" *.md phpstan.neon *.dist composer.* vendor/**/phpstan.neon vendor/**/phpstan.neon.dist vendor/**/phpunit.xml.dist vendor/**/composer.json vendor/**/README.md vendor/**/LICENSE.md vendor/**/CHANGELOG.md tests/\* **/tests/\* ${{ matrix.pluginConfig.exclude_files }}
working-directory: ${{ matrix.pluginConfig.path }}
- name: Uncompress plugin zip contents into new folder
uses: montudor/[email protected]
with:
args: unzip -qq build/${{ matrix.pluginConfig.zip_file }}.zip -d build/dist-plugin/${{ matrix.pluginConfig.plugin_slug }}
- name: Upload plugin zip as artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.pluginConfig.zip_file }}
path: build/dist-plugin/
retention-days: ${{ needs.provide_data.outputs.retention_days }}
###########################################################################
# Upload and Deploy
# Only when doing a release
###########################################################################
- name: Create release folder
run: mkdir build/release-plugin
if: github.event_name == 'release'
- name: Create release plugin as .zip file (containing a root folder with the plugin name)
run: zip -X -r $GITHUB_WORKSPACE/build/release-plugin/${{ matrix.pluginConfig.zip_file }}.zip .
working-directory: build/dist-plugin
if: github.event_name == 'release'
- name: Upload to release
uses: softprops/action-gh-release@v2
with:
files: build/release-plugin/${{ matrix.pluginConfig.zip_file }}.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'release'
- id: previous_tag
uses: WyriHaximus/github-action-get-previous-tag@master
if: github.event_name == 'release'
- name: Include (previously excluded) folders for DIST repo
run: sudo rsync -av ${{ matrix.pluginConfig.include_folders_for_dist_repo }} $GITHUB_WORKSPACE/build/dist-plugin/${{ matrix.pluginConfig.plugin_slug }} --quiet
working-directory: ${{ matrix.pluginConfig.path }}
if: ${{ matrix.pluginConfig.include_folders_for_dist_repo != '' && github.event_name == 'release' && matrix.pluginConfig.dist_repo_organization && matrix.pluginConfig.dist_repo_name }}
- name: Publish to DIST repo
uses: symplify/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
with:
branch: ${{ matrix.pluginConfig.dist_repo_branch }}
package-directory: 'build/dist-plugin/${{ matrix.pluginConfig.plugin_slug }}'
split-repository-organization: ${{ matrix.pluginConfig.dist_repo_organization }}
split-repository-name: ${{ matrix.pluginConfig.dist_repo_name }}
tag: ${{ steps.previous_tag.outputs.tag }}
user-name: "${{ needs.provide_data.outputs.git_user_name }}"
user-email: "${{ needs.provide_data.outputs.git_user_email }}"
if: ${{ github.event_name == 'release' && matrix.pluginConfig.dist_repo_organization && matrix.pluginConfig.dist_repo_name }}