Skip to content

Commit dd7aa03

Browse files
committed
feat(continuous-integration): supports build artifact
Signed-off-by: Emilien Escalle <[email protected]>
1 parent 883c417 commit dd7aa03

File tree

1 file changed

+69
-2
lines changed

1 file changed

+69
-2
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646
code-ql:
4747
name: 🛡️ CodeQL Analysis
4848
if: inputs.checks == true && inputs.code-ql != ''
49+
permissions:
50+
security-events: write
4951
runs-on: "ubuntu-latest"
5052
steps:
5153
- uses: hoverkraft-tech/ci-github-common/actions/[email protected]
@@ -61,6 +63,9 @@ jobs:
6163
permissions:
6264
contents: read
6365
id-token: write
66+
outputs:
67+
build-commands: ${{ steps.build-variables.outputs.commands }}
68+
build-artifact: ${{ steps.build-variables.outputs.artifact }}
6469
steps:
6570
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
6671
# jscpd:ignore-start
@@ -78,6 +83,54 @@ jobs:
7883
- id: setup-node
7984
uses: ./self-workflow/actions/setup-node
8085

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+
81134
lint:
82135
name: 👕 Lint
83136
if: inputs.checks == true && inputs.lint != false
@@ -186,7 +239,7 @@ jobs:
186239
${{ runner.os }}-cache-storybook-
187240
188241
- run: |
189-
BUILD_COMMANDS="${{ inputs.build }}"
242+
BUILD_COMMANDS="${{ needs.setup.outputs.build-commands }}"
190243
191244
echo "$BUILD_COMMANDS" | while IFS= read -r COMMAND ; do
192245
# Trim whitespace
@@ -201,11 +254,19 @@ jobs:
201254
yarn "$COMMAND"
202255
done
203256
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+
204263
test:
205264
name: 🧪 Test
206265
if: inputs.checks == true && inputs.test == true
207266
runs-on: "ubuntu-latest"
208-
needs: setup
267+
needs:
268+
- setup
269+
- build
209270
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
210271
permissions:
211272
contents: read
@@ -214,6 +275,12 @@ jobs:
214275
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
215276
- uses: hoverkraft-tech/ci-github-common/actions/[email protected]
216277

278+
- if: needs.setup.outputs.build-artifact
279+
uses: actions/download-artifact@v4
280+
with:
281+
name: build
282+
path: '/'
283+
217284
- id: oidc
218285
uses: ChristopherHX/oidc@v3
219286
- uses: actions/checkout@v4 # checks out called workflow

0 commit comments

Comments
 (0)