11# Workflow to release Node.js packages:
22#
3- # - Build (optional)
43# - Generate documentation (optional)
54# - Publish to registry (npm, GitHub Packages)
65
1615 type : string
1716 default : ' ["ubuntu-latest"]'
1817 required : false
19- build :
20- description : |
21- Build parameters. Must be a string or a JSON object.
22- Set to empty string to disable build step.
23- For string, provide a list of commands to run during the build step, one per line.
24- For JSON object, provide the following properties:
25-
26- - `commands`: Array of commands to run during the build step.
27- - `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.
29-
30- Example:
31- ```json
32- {
33- "commands": [
34- "build",
35- "generate-artifacts"
36- ],
37- "env": {
38- "NODE_ENV": "production"
39- },
40- "artifact": [
41- "dist/",
42- "packages/package-a/build/"
43- ]
44- }
45- ```
46- type : string
47- required : false
48- default : " build"
4918 docs :
5019 description : |
5120 Documentation generation parameters.
@@ -143,25 +112,13 @@ on:
143112 For npm: Use an npm access token with publish permissions.
144113 For GitHub Packages: Use `GITHUB_TOKEN` or a PAT with `packages:write` permission.
145114 required : true
146- build-secrets :
147- description : |
148- Secrets to be used during the build step.
149- Must be a multi-line env formatted string.
150- Example:
151- ```txt
152- SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}
153- ```
154- required : false
155115 outputs :
156116 version :
157117 description : " The version of the published package."
158118 value : ${{ jobs.release.outputs.version }}
159119 package-name :
160120 description : " The name of the published package."
161121 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 }}
165122 docs-artifact-id :
166123 description : " ID of the documentation artifact (if uploaded)."
167124 value : ${{ jobs.release.outputs.docs-artifact-id }}
@@ -176,9 +133,6 @@ jobs:
176133 outputs :
177134 registry-url : ${{ steps.parse-registry.outputs.registry-url }}
178135 registry-scope : ${{ steps.parse-registry.outputs.registry-scope }}
179- build-commands : ${{ steps.parse-build.outputs.commands }}
180- build-env : ${{ steps.parse-build.outputs.env }}
181- build-artifact : ${{ steps.parse-build.outputs.artifact }}
182136 docs-command : ${{ steps.parse-docs.outputs.command }}
183137 docs-output : ${{ steps.parse-docs.outputs.output }}
184138 docs-artifact : ${{ steps.parse-docs.outputs.artifact }}
@@ -231,98 +185,6 @@ jobs:
231185 core.setOutput('registry-url', registryUrl);
232186 core.setOutput('registry-scope', registryScope);
233187
234- - id : parse-build
235- uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
236- env :
237- BUILD_INPUT : ${{ inputs.build }}
238- WORKING_DIRECTORY : ${{ inputs.working-directory }}
239- with :
240- script : |
241- const path = require('node:path');
242-
243- const buildInput = process.env.BUILD_INPUT.trim();
244- const workingDirectory = process.env.WORKING_DIRECTORY || '.';
245-
246- if (!buildInput) {
247- core.info('Build step disabled');
248- return;
249- }
250-
251- let commands = [];
252- let env = {};
253-
254- // Build commands is a list of command(s), one per line
255- const buildCommandsIsList = !buildInput.startsWith('{') && !buildInput.startsWith('[');
256- if (buildCommandsIsList) {
257- commands = buildInput.split('\n').map(command => command.trim()).filter(Boolean);
258- } else {
259- let build;
260- try {
261- build = JSON.parse(buildInput);
262- } catch (error) {
263- return core.setFailed(`Failed to parse build input as JSON: ${error.message}`);
264- }
265-
266- // Build commands is a JSON array of commands
267- if (Array.isArray(build)) {
268- commands = build;
269- }
270- // Build commands is a JSON object
271- else {
272- commands = build.commands ?? ['build'];
273- 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- }
310- }
311- }
312-
313- if (commands.some(command => typeof command !== 'string')) {
314- return core.setFailed('Build commands array must only contain strings');
315- }
316-
317- const sanitizedCommands = commands.map(command => command.trim()).filter(Boolean);
318- if (!sanitizedCommands.length) {
319- core.info('No build commands specified');
320- return;
321- }
322-
323- core.setOutput('commands', sanitizedCommands.join('\n'));
324- core.setOutput('env', JSON.stringify(env));
325-
326188 - id : parse-docs
327189 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
328190 env :
@@ -376,7 +238,6 @@ jobs:
376238 outputs :
377239 version : ${{ steps.package-info.outputs.version }}
378240 package-name : ${{ steps.package-info.outputs.name }}
379- build-artifact-id : ${{ steps.build.outputs.artifact-id }}
380241 docs-artifact-id : ${{ steps.upload-docs.outputs.artifact-id }}
381242 steps :
382243 - uses : hoverkraft-tech/ci-github-common/actions/checkout@5ac504609f6ef35c5ac94bd8199063aa32104721 # 0.31.3
@@ -432,17 +293,6 @@ jobs:
432293 core.setOutput('name', name);
433294 core.setOutput('version', version);
434295
435- - name : Build
436- id : build
437- if : needs.prepare.outputs.build-commands != ''
438- uses : ./self-workflow/actions/build
439- with :
440- working-directory : ${{ inputs.working-directory }}
441- build-commands : ${{ needs.prepare.outputs.build-commands }}
442- build-env : ${{ needs.prepare.outputs.build-env || '{}' }}
443- build-secrets : ${{ secrets.build-secrets }}
444- build-artifact : ${{ needs.prepare.outputs.build-artifact }}
445-
446296 - name : Generate documentation
447297 if : needs.prepare.outputs.docs-command != ''
448298 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
0 commit comments