-
Notifications
You must be signed in to change notification settings - Fork 6
183 lines (167 loc) · 6.83 KB
/
build-assets-compilation.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
name: Assets compilation
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 static code analysis is to be executed.
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
PHP_VERSION:
description: PHP version with which the assets compilation is to be executed.
default: '8.2'
required: false
type: string
COMPOSER_ARGS:
description: Set of arguments passed to Composer.
default: '--prefer-dist'
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
GITHUB_USER_EMAIL:
description: Email address for the GitHub user configuration.
required: false
GITHUB_USER_NAME:
description: Username for the GitHub user configuration.
required: false
GITHUB_USER_SSH_KEY:
description: Private SSH key associated with the GitHub user passed as `GITHUB_USER_NAME`.
required: false
ENV_VARS:
description: Additional environment variables as a JSON formatted object.
required: false
jobs:
assets-compilation:
timeout-minutes: 5
runs-on: ubuntu-latest
env:
COMPOSER_AUTH: '${{ secrets.COMPOSER_AUTH_JSON }}'
NODE_OPTIONS: ${{ inputs.NODE_OPTIONS }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
NODE_CACHE_MODE: ''
GITHUB_USER_EMAIL: ${{ secrets.GITHUB_USER_EMAIL }}
GITHUB_USER_NAME: ${{ secrets.GITHUB_USER_NAME }}
GITHUB_USER_SSH_KEY: ${{ secrets.GITHUB_USER_SSH_KEY }}
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: Checkout
uses: actions/checkout@v4
- name: Set up custom environment variables
env:
ENV_VARS: ${{ secrets.ENV_VARS }}
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 SSH
if: ${{ env.GITHUB_USER_SSH_KEY != '' }}
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ env.GITHUB_USER_SSH_KEY }}
- name: Set up Git
if: ${{ env.GITHUB_USER_EMAIL != '' && env.GITHUB_USER_NAME != '' }}
run: |
git config --global user.email "${{ env.GITHUB_USER_EMAIL }}"
git config --global user.name "${{ env.GITHUB_USER_NAME }}"
- 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
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}
cache: ${{ env.NODE_CACHE_MODE }}
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION }}
tools: composer
coverage: none
- name: Install Composer dependencies
uses: ramsey/composer-install@v3
with:
composer-options: ${{ inputs.COMPOSER_ARGS }}
- name: Set environment variables [DEV]
if: ${{ !contains(github.ref, 'refs/tags/') }}
run: |
echo "ASSETS_HASH=$(composer assets-hash)" >> $GITHUB_ENV
# We set "development" here to align with webpack's "mode"
# to be used in Composer Asset Compiler as a placeholder variable.
# @link https://webpack.js.org/configuration/mode/
echo "BUILD_ENV=development" >> $GITHUB_ENV
- name: Set environment variables [PROD]
if: ${{ contains(github.ref, 'refs/tags/') }}
run: |
echo "TAG_NAME=$(echo ${GITHUB_REF#refs/*/})" >> $GITHUB_ENV
echo "BUILD_ENV=production" >> $GITHUB_ENV
echo "::notice::The ENCORE_ENV variable is deprecated and will be removed soon. If you use it, please change it to BUILD_ENV."
echo "ENCORE_ENV=production" >> $GITHUB_ENV
- name: Compile assets
run: composer compile-assets ${{ inputs.COMPILE_ASSETS_ARGS }}
- name: Upload assets artifact [DEV]
uses: actions/upload-artifact@v4
if: ${{ !contains(github.ref, 'refs/tags/') }}
with:
name: assets-${{ env.ASSETS_HASH }}
path: assets
overwrite: true
include-hidden-files: true
- name: Zip assets folder [PROD]
uses: montudor/action-zip@v1
if: ${{ contains(github.ref, 'refs/tags/') }}
with:
args: zip -qq -r assets-${{ env.TAG_NAME }}.zip assets
- name: Upload release attachment [PROD]
if: ${{ contains(github.ref, 'refs/tags/') }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: assets-${{ env.TAG_NAME }}.zip
tag: ${{ github.ref }}
# Release description fallback which will not be enforced due "overwrite: false" (default).
body: |
# ${{ env.TAG_NAME }}
Compiled assets available in `assets-${{ env.TAG_NAME }}.zip`.