From e690b1b4f72daeaf23bbf408753b58f10e63dcf9 Mon Sep 17 00:00:00 2001 From: Sid Vishnoi <8426945+sidvishnoi@users.noreply.github.com> Date: Wed, 17 Apr 2024 19:01:09 +0530 Subject: [PATCH] fix: don't require `ARTIFACT_NAME` with multiple specs (#181) --- action.yml | 7 +++---- docs/examples.md | 10 +++------- docs/options.md | 16 ++++++++-------- src/build.ts | 3 ++- src/prepare-build.ts | 29 +++++++++++++++++++++++++++-- src/prepare.ts | 1 + 6 files changed, 44 insertions(+), 22 deletions(-) diff --git a/action.yml b/action.yml index 9d6d801..295e4bf 100644 --- a/action.yml +++ b/action.yml @@ -13,9 +13,6 @@ inputs: description: Source file path. DESTINATION: description: Destination path, relative to repository root. - ARTIFACT_NAME: - description: Name for build artifact. Required when building multiple documents in same job. - default: "spec-prod-result" BUILD_FAIL_ON: description: Exit behaviour on errors. default: fatal @@ -49,6 +46,8 @@ inputs: description: Override Bikeshed's metadata or ReSpec's respecConfig for W3C deployment and validations. W3C_NOTIFICATIONS_CC: description: Comma separated list of email addresses to CC + ARTIFACT_NAME: + description: Name for build artifact runs: using: composite @@ -126,7 +125,7 @@ runs: path: |- ${{ steps.build.outputs.gh && fromJson(steps.build.outputs.gh).dest }} ${{ steps.build.outputs.w3c && fromJson(steps.build.outputs.w3c).dest }} - name: ${{ inputs.ARTIFACT_NAME }} + name: ${{ steps.prepare.outputs.build && fromJson(steps.prepare.outputs.build).artifactName }} retention-days: 5 - name: Validate hyperlinks diff --git a/docs/examples.md b/docs/examples.md index a8e8845..98f4cb0 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -184,23 +184,19 @@ jobs: max-parallel: 1 matrix: include: - - name: spec-0 - source: spec.html + - source: spec.html destination: index.html echidna_token: ECHIDNA_TOKEN_SPEC - - name: spec-1 - source: spec-1 + - source: spec-1 destination: the-spec echidna_token: ECHIDNA_TOKEN_SPEC1 - - name: spec-2 - source: spec-2 + - source: spec-2 # destination defaults to spec-2/index.html # echidna_token defaults to no publication to w3.org/TR steps: - uses: actions/checkout@v4 - uses: w3c/spec-prod@v2 with: - ARTIFACT_NAME: ${{ matrix.name }} # required when building multiple documents in same job SOURCE: ${{ matrix.source }} DESTINATION: ${{ matrix.destination }} GH_PAGES_BRANCH: gh-pages diff --git a/docs/options.md b/docs/options.md index 8b59e4a..11e79f3 100644 --- a/docs/options.md +++ b/docs/options.md @@ -32,14 +32,6 @@ Location of generated HTML document and other assets. This is useful when you've | `my-spec-src` | `my-spec-out` | `./my-spec-out/index.html` | `./my-spec-out/` | | `index.html` | `index.html` | `./index.html` | `./` | -## `ARTIFACT_NAME` - -Name for artifact which will be uploaded to workflow run. Required when building multiple documents in same job. - -**Possible values:** Any valid artifact name. - -**Default:** `"spec-prod-result"`. - ## `BUILD_FAIL_ON` 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 Comma separated list of email addresses to CC. This field is optional. **Default:** None. + +## `ARTIFACT_NAME` + +Name for artifact which will be uploaded to workflow run. Required to be unique when building multiple documents in same job. + +**Possible values:** Any valid artifact name. + +**Default:** `"spec-prod-result"` or inferred from `SOURCE`. diff --git a/src/build.ts b/src/build.ts index 72f4464..a9b34e3 100644 --- a/src/build.ts +++ b/src/build.ts @@ -6,8 +6,9 @@ import { env, exit, setOutput, sh, unique } from "./utils.js"; import { deepEqual, StaticServer } from "./utils.js"; import { PUPPETEER_ENV } from "./constants.js"; -import { BasicBuildOptions } from "./prepare-build.js"; +import { BasicBuildOptions as BasicBuildOptions_ } from "./prepare-build.js"; import { ProcessedInput } from "./prepare.js"; +type BasicBuildOptions = Omit; type Input = ProcessedInput["build"]; type ConfigOverride = Input["configOverride"]["gh" | "w3c"]; type BuildSuffix = "common" | "gh" | "w3c"; diff --git a/src/prepare-build.ts b/src/prepare-build.ts index 9482e8c..f6d4753 100644 --- a/src/prepare-build.ts +++ b/src/prepare-build.ts @@ -12,7 +12,8 @@ export async function buildOptions( inputs: Inputs, githubContext: GitHubContext, ) { - const { toolchain, source, destination } = getBasicBuildOptions(inputs); + const { toolchain, source, destination, artifactName } = + getBasicBuildOptions(inputs); const configOverride = { gh: getConfigOverride(inputs.GH_PAGES_BUILD_OVERRIDE), @@ -35,7 +36,14 @@ export async function buildOptions( const flags = []; flags.push(...getFailOnFlags(toolchain, inputs.BUILD_FAIL_ON)); - return { toolchain, source, destination, flags, configOverride }; + return { + toolchain, + source, + destination, + artifactName, + flags, + configOverride, + }; } type NormalizedPath = { dir: string; file: string; path: string }; @@ -43,6 +51,7 @@ export type BasicBuildOptions = { toolchain: "respec" | "bikeshed"; source: NormalizedPath; destination: NormalizedPath; + artifactName: string; }; function getBasicBuildOptions(inputs: Inputs): BasicBuildOptions { let toolchain = inputs.TOOLCHAIN; @@ -107,6 +116,21 @@ function getBasicBuildOptions(inputs: Inputs): BasicBuildOptions { return { dir, file, path: path.join(dir, file) }; }; + const getArtifactNameFromSource = (source: string): string => { + source = source.toLowerCase().trim(); + const sourceSlug = source + .replace(/\//g, "-") + .replace(/\s+/g, "-") + .replace(/index\.(html|bs)$/, "") + .replace(/[^\w-]+/g, "") + .replace(/--+/g, "-") + .replace(/-$/g, ""); + if (sourceSlug) { + return "spec-prod-result" + "-" + sourceSlug; + } + return "spec-prod-result"; + }; + destination = (() => { const dest = path.parse(destination || source); dest.ext = ".html"; @@ -116,6 +140,7 @@ function getBasicBuildOptions(inputs: Inputs): BasicBuildOptions { return { toolchain, + artifactName: inputs.ARTIFACT_NAME || getArtifactNameFromSource(source), source: getNormalizedPath(source), destination: getNormalizedPath(destination), } as BasicBuildOptions; diff --git a/src/prepare.ts b/src/prepare.ts index 17c6bb5..12c64a2 100644 --- a/src/prepare.ts +++ b/src/prepare.ts @@ -25,6 +25,7 @@ export interface Inputs { W3C_BUILD_OVERRIDE: string; W3C_WG_DECISION_URL: string; W3C_NOTIFICATIONS_CC: string; + ARTIFACT_NAME?: string; } export interface GitHubContext {