Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't require ARTIFACT_NAME with multiple specs #181

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
3 changes: 2 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicBuildOptions_, "artifactName">;
type Input = ProcessedInput["build"];
type ConfigOverride = Input["configOverride"]["gh" | "w3c"];
type BuildSuffix = "common" | "gh" | "w3c";
Expand Down
29 changes: 27 additions & 2 deletions src/prepare-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -35,14 +36,22 @@ 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 };
export type BasicBuildOptions = {
toolchain: "respec" | "bikeshed";
source: NormalizedPath;
destination: NormalizedPath;
artifactName: string;
};
function getBasicBuildOptions(inputs: Inputs): BasicBuildOptions {
let toolchain = inputs.TOOLCHAIN;
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down