46
46
code-ql :
47
47
name : 🛡️ CodeQL Analysis
48
48
if : inputs.checks == true && inputs.code-ql != ''
49
+ permissions :
50
+ security-events : write
49
51
runs-on : " ubuntu-latest"
50
52
steps :
51
53
-
uses :
hoverkraft-tech/ci-github-common/actions/[email protected]
61
63
permissions :
62
64
contents : read
63
65
id-token : write
66
+ outputs :
67
+ build-commands : ${{ steps.build-variables.outputs.commands }}
68
+ build-artifact : ${{ steps.build-variables.outputs.artifact }}
64
69
steps :
65
70
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
66
71
# jscpd:ignore-start
78
83
- id : setup-node
79
84
uses : ./self-workflow/actions/setup-node
80
85
86
+ - id : build-variables
87
+ uses : actions/github-script@v7
88
+ with :
89
+ script : |
90
+ const buildInput = `${{ inputs.build }}`.trim();
91
+
92
+ let commands = [];
93
+
94
+ // Build input can be json or string
95
+ try {
96
+ const build = JSON.parse(buildInput);
97
+ if (Array.isArray(build)) {
98
+ commands = build;
99
+ } else {
100
+ commands = build.commands ?? ["build"];
101
+
102
+ if (build.artifact) {
103
+ if(typeof build.artifact === 'string') {
104
+ build.artifact = build.artifact.trim().split('\n');
105
+ }
106
+ const sanitizedArtifacts = build.artifact
107
+ .map(artifact => artifact.trim())
108
+ .filter(Boolean)
109
+ .map(artifact => {
110
+ if(!artifact.includes('*')) {
111
+ return artifact;
112
+ }
113
+
114
+ // FIXME: Workaround to preserve full path to artifact
115
+ // Add a wildcard to the first folder of the path
116
+ const workspace = `${{ github.workspace }}`.replace(/\/([^/]+)/, '/*$1');
117
+ return `${workspace}/${artifact}`;
118
+ });
119
+
120
+ core.setOutput('artifact', sanitizedArtifacts.join('\n'));
121
+ }
122
+ }
123
+ } catch (e) {
124
+ commands = buildInput.split('\n');
125
+ }
126
+
127
+ const sanitizedCommands = commands.map(command => command.trim()).filter(Boolean);
128
+ if(!sanitizedCommands.length) {
129
+ core.setFailed('No build commands found');
130
+ }
131
+
132
+ core.setOutput('commands', sanitizedCommands.join('\n'));
133
+
81
134
lint :
82
135
name : 👕 Lint
83
136
if : inputs.checks == true && inputs.lint != false
@@ -186,7 +239,7 @@ jobs:
186
239
${{ runner.os }}-cache-storybook-
187
240
188
241
- run : |
189
- BUILD_COMMANDS="${{ inputs. build }}"
242
+ BUILD_COMMANDS="${{ needs.setup.outputs. build-commands }}"
190
243
191
244
echo "$BUILD_COMMANDS" | while IFS= read -r COMMAND ; do
192
245
# Trim whitespace
@@ -201,11 +254,19 @@ jobs:
201
254
yarn "$COMMAND"
202
255
done
203
256
257
+ - if : needs.setup.outputs.build-artifact
258
+ uses : actions/upload-artifact@v4
259
+ with :
260
+ name : build
261
+ path : ${{ needs.setup.outputs.build-artifact }}
262
+
204
263
test :
205
264
name : 🧪 Test
206
265
if : inputs.checks == true && inputs.test == true
207
266
runs-on : " ubuntu-latest"
208
- needs : setup
267
+ needs :
268
+ - setup
269
+ - build
209
270
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
210
271
permissions :
211
272
contents : read
@@ -214,6 +275,12 @@ jobs:
214
275
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
215
276
-
uses :
hoverkraft-tech/ci-github-common/actions/[email protected]
216
277
278
+ - if : needs.setup.outputs.build-artifact
279
+ uses : actions/download-artifact@v4
280
+ with :
281
+ name : build
282
+ path : ' /'
283
+
217
284
- id : oidc
218
285
uses : ChristopherHX/oidc@v3
219
286
- uses : actions/checkout@v4 # checks out called workflow
0 commit comments