2525
2626 - `commands`: Array of commands to run during the build step.
2727 - `env`: Object of environment variables to set during the build step.
28+ - `artifact`: String or array of strings specifying paths to artifacts to upload after the build.
2829
2930 Example:
3031 ```json
3536 ],
3637 "env": {
3738 "NODE_ENV": "production"
38- }
39+ },
40+ "artifact": [
41+ "dist/",
42+ "packages/package-a/build/"
43+ ]
3944 }
4045 ```
4146 type : string
154159 package-name :
155160 description : " The name of the published package."
156161 value : ${{ jobs.release.outputs.package-name }}
162+ build-artifact-id :
163+ description : " ID of the build artifact (if uploaded)."
164+ value : ${{ jobs.release.outputs.build-artifact-id }}
157165 docs-artifact-id :
158166 description : " ID of the documentation artifact (if uploaded)."
159167 value : ${{ jobs.release.outputs.docs-artifact-id }}
@@ -170,6 +178,7 @@ jobs:
170178 registry-scope : ${{ steps.parse-registry.outputs.registry-scope }}
171179 build-commands : ${{ steps.parse-build.outputs.commands }}
172180 build-env : ${{ steps.parse-build.outputs.env }}
181+ build-artifact : ${{ steps.parse-build.outputs.artifact }}
173182 docs-command : ${{ steps.parse-docs.outputs.command }}
174183 docs-output : ${{ steps.parse-docs.outputs.output }}
175184 docs-artifact : ${{ steps.parse-docs.outputs.artifact }}
@@ -226,9 +235,13 @@ jobs:
226235 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
227236 env :
228237 BUILD_INPUT : ${{ inputs.build }}
238+ WORKING_DIRECTORY : ${{ inputs.working-directory }}
229239 with :
230240 script : |
241+ const path = require('node:path');
242+
231243 const buildInput = process.env.BUILD_INPUT.trim();
244+ const workingDirectory = process.env.WORKING_DIRECTORY || '.';
232245
233246 if (!buildInput) {
234247 core.info('Build step disabled');
@@ -258,6 +271,42 @@ jobs:
258271 else {
259272 commands = build.commands ?? ['build'];
260273 env = build.env ?? {};
274+
275+ if (build.artifact) {
276+ let buildArtifact = build.artifact;
277+
278+ if (typeof buildArtifact === 'string' || Array.isArray(buildArtifact)) {
279+ buildArtifact = {
280+ paths: buildArtifact
281+ };
282+ }
283+
284+ if (typeof buildArtifact.paths === 'string') {
285+ buildArtifact.paths = buildArtifact.paths.split('\n');
286+ } else if (!Array.isArray(buildArtifact.paths)) {
287+ return core.setFailed('Build artifact paths must be a string or an array of strings');
288+ }
289+
290+ buildArtifact.paths = buildArtifact.paths
291+ .map(artifact => artifact.trim())
292+ .filter(Boolean)
293+ .map(artifact => {
294+ // FIXME: Workaround to preserve full path to artifact
295+ const fullpath = artifact.startsWith('/') ? artifact : path.join(workingDirectory, artifact);
296+
297+ // Add a wildcard to the first folder of the path
298+ return fullpath.replace(/\/([^/]+)/, '/*$1');
299+ }).join('\n');
300+
301+ if (!buildArtifact.paths) {
302+ return core.setFailed('No valid build artifact paths found');
303+ }
304+
305+ // Generate a unique name for the artifact
306+ buildArtifact.name = `${process.env.GITHUB_JOB}-build-${process.env.GITHUB_RUN_ID}-${Math.random().toString(36).substring(2, 8)}`;
307+
308+ core.setOutput('artifact', JSON.stringify(buildArtifact));
309+ }
261310 }
262311 }
263312
@@ -327,6 +376,7 @@ jobs:
327376 outputs :
328377 version : ${{ steps.package-info.outputs.version }}
329378 package-name : ${{ steps.package-info.outputs.name }}
379+ build-artifact-id : ${{ steps.build.outputs.artifact-id }}
330380 docs-artifact-id : ${{ steps.upload-docs.outputs.artifact-id }}
331381 steps :
332382 - uses : hoverkraft-tech/ci-github-common/actions/checkout@5ac504609f6ef35c5ac94bd8199063aa32104721 # 0.31.3
@@ -383,13 +433,15 @@ jobs:
383433 core.setOutput('version', version);
384434
385435 - name : Build
436+ id : build
386437 if : needs.prepare.outputs.build-commands != ''
387438 uses : ./self-workflow/actions/build
388439 with :
389440 working-directory : ${{ inputs.working-directory }}
390441 build-commands : ${{ needs.prepare.outputs.build-commands }}
391442 build-env : ${{ needs.prepare.outputs.build-env || '{}' }}
392443 build-secrets : ${{ secrets.build-secrets }}
444+ build-artifact : ${{ needs.prepare.outputs.build-artifact }}
393445
394446 - name : Generate documentation
395447 if : needs.prepare.outputs.docs-command != ''
0 commit comments