Skip to content

Commit e690b1b

Browse files
authored
fix: don't require ARTIFACT_NAME with multiple specs (#181)
1 parent 5cf6473 commit e690b1b

File tree

6 files changed

+44
-22
lines changed

6 files changed

+44
-22
lines changed

action.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ inputs:
1313
description: Source file path.
1414
DESTINATION:
1515
description: Destination path, relative to repository root.
16-
ARTIFACT_NAME:
17-
description: Name for build artifact. Required when building multiple documents in same job.
18-
default: "spec-prod-result"
1916
BUILD_FAIL_ON:
2017
description: Exit behaviour on errors.
2118
default: fatal
@@ -49,6 +46,8 @@ inputs:
4946
description: Override Bikeshed's metadata or ReSpec's respecConfig for W3C deployment and validations.
5047
W3C_NOTIFICATIONS_CC:
5148
description: Comma separated list of email addresses to CC
49+
ARTIFACT_NAME:
50+
description: Name for build artifact
5251

5352
runs:
5453
using: composite
@@ -126,7 +125,7 @@ runs:
126125
path: |-
127126
${{ steps.build.outputs.gh && fromJson(steps.build.outputs.gh).dest }}
128127
${{ steps.build.outputs.w3c && fromJson(steps.build.outputs.w3c).dest }}
129-
name: ${{ inputs.ARTIFACT_NAME }}
128+
name: ${{ steps.prepare.outputs.build && fromJson(steps.prepare.outputs.build).artifactName }}
130129
retention-days: 5
131130

132131
- name: Validate hyperlinks

docs/examples.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,23 +184,19 @@ jobs:
184184
max-parallel: 1
185185
matrix:
186186
include:
187-
- name: spec-0
188-
source: spec.html
187+
- source: spec.html
189188
destination: index.html
190189
echidna_token: ECHIDNA_TOKEN_SPEC
191-
- name: spec-1
192-
source: spec-1
190+
- source: spec-1
193191
destination: the-spec
194192
echidna_token: ECHIDNA_TOKEN_SPEC1
195-
- name: spec-2
196-
source: spec-2
193+
- source: spec-2
197194
# destination defaults to spec-2/index.html
198195
# echidna_token defaults to no publication to w3.org/TR
199196
steps:
200197
- uses: actions/checkout@v4
201198
- uses: w3c/spec-prod@v2
202199
with:
203-
ARTIFACT_NAME: ${{ matrix.name }} # required when building multiple documents in same job
204200
SOURCE: ${{ matrix.source }}
205201
DESTINATION: ${{ matrix.destination }}
206202
GH_PAGES_BRANCH: gh-pages

docs/options.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ Location of generated HTML document and other assets. This is useful when you've
3232
| `my-spec-src` | `my-spec-out` | `./my-spec-out/index.html` | `./my-spec-out/` |
3333
| `index.html` | `index.html` | `./index.html` | `./` |
3434

35-
## `ARTIFACT_NAME`
36-
37-
Name for artifact which will be uploaded to workflow run. Required when building multiple documents in same job.
38-
39-
**Possible values:** Any valid artifact name.
40-
41-
**Default:** `"spec-prod-result"`.
42-
4335
## `BUILD_FAIL_ON`
4436

4537
Define exit behaviour on build errors or warnings.
@@ -192,3 +184,11 @@ A URL to the working group decision to use auto-publish, usually from a w3c mail
192184
Comma separated list of email addresses to CC. This field is optional.
193185

194186
**Default:** None.
187+
188+
## `ARTIFACT_NAME`
189+
190+
Name for artifact which will be uploaded to workflow run. Required to be unique when building multiple documents in same job.
191+
192+
**Possible values:** Any valid artifact name.
193+
194+
**Default:** `"spec-prod-result"` or inferred from `SOURCE`.

src/build.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { env, exit, setOutput, sh, unique } from "./utils.js";
66
import { deepEqual, StaticServer } from "./utils.js";
77
import { PUPPETEER_ENV } from "./constants.js";
88

9-
import { BasicBuildOptions } from "./prepare-build.js";
9+
import { BasicBuildOptions as BasicBuildOptions_ } from "./prepare-build.js";
1010
import { ProcessedInput } from "./prepare.js";
11+
type BasicBuildOptions = Omit<BasicBuildOptions_, "artifactName">;
1112
type Input = ProcessedInput["build"];
1213
type ConfigOverride = Input["configOverride"]["gh" | "w3c"];
1314
type BuildSuffix = "common" | "gh" | "w3c";

src/prepare-build.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export async function buildOptions(
1212
inputs: Inputs,
1313
githubContext: GitHubContext,
1414
) {
15-
const { toolchain, source, destination } = getBasicBuildOptions(inputs);
15+
const { toolchain, source, destination, artifactName } =
16+
getBasicBuildOptions(inputs);
1617

1718
const configOverride = {
1819
gh: getConfigOverride(inputs.GH_PAGES_BUILD_OVERRIDE),
@@ -35,14 +36,22 @@ export async function buildOptions(
3536
const flags = [];
3637
flags.push(...getFailOnFlags(toolchain, inputs.BUILD_FAIL_ON));
3738

38-
return { toolchain, source, destination, flags, configOverride };
39+
return {
40+
toolchain,
41+
source,
42+
destination,
43+
artifactName,
44+
flags,
45+
configOverride,
46+
};
3947
}
4048

4149
type NormalizedPath = { dir: string; file: string; path: string };
4250
export type BasicBuildOptions = {
4351
toolchain: "respec" | "bikeshed";
4452
source: NormalizedPath;
4553
destination: NormalizedPath;
54+
artifactName: string;
4655
};
4756
function getBasicBuildOptions(inputs: Inputs): BasicBuildOptions {
4857
let toolchain = inputs.TOOLCHAIN;
@@ -107,6 +116,21 @@ function getBasicBuildOptions(inputs: Inputs): BasicBuildOptions {
107116
return { dir, file, path: path.join(dir, file) };
108117
};
109118

119+
const getArtifactNameFromSource = (source: string): string => {
120+
source = source.toLowerCase().trim();
121+
const sourceSlug = source
122+
.replace(/\//g, "-")
123+
.replace(/\s+/g, "-")
124+
.replace(/index\.(html|bs)$/, "")
125+
.replace(/[^\w-]+/g, "")
126+
.replace(/--+/g, "-")
127+
.replace(/-$/g, "");
128+
if (sourceSlug) {
129+
return "spec-prod-result" + "-" + sourceSlug;
130+
}
131+
return "spec-prod-result";
132+
};
133+
110134
destination = (() => {
111135
const dest = path.parse(destination || source);
112136
dest.ext = ".html";
@@ -116,6 +140,7 @@ function getBasicBuildOptions(inputs: Inputs): BasicBuildOptions {
116140

117141
return {
118142
toolchain,
143+
artifactName: inputs.ARTIFACT_NAME || getArtifactNameFromSource(source),
119144
source: getNormalizedPath(source),
120145
destination: getNormalizedPath(destination),
121146
} as BasicBuildOptions;

src/prepare.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface Inputs {
2525
W3C_BUILD_OVERRIDE: string;
2626
W3C_WG_DECISION_URL: string;
2727
W3C_NOTIFICATIONS_CC: string;
28+
ARTIFACT_NAME?: string;
2829
}
2930

3031
export interface GitHubContext {

0 commit comments

Comments
 (0)