Skip to content

Commit adbdbd4

Browse files
fix: do not report user input errors to Blacksmith backend
A missing required cache-key input (common for workflows still on the v1 invocation style) was reported to /stickydisks/report-failed as a STICKYDISK_SETUP failure, polluting platform failure metrics and paging alerts with what is a user configuration error. Introduce UserInputError, throw it from our own cache-key validation (replacing the @actions/core required-input throw), and have reportBuildPushActionFailure skip reporting any UserInputError. User-facing behavior is unchanged: the action still warns and falls back to a local builder (or fails with nofallback), now with a clearer migration message. Also add the update-dist workflow so pushes to feature branches rebuild and commit dist automatically (dist cannot be built outside CI because the @buf registry packages require BUF_TOKEN). Co-authored-by: Codesmith Staging <codesmith-bot@users.noreply.github.com>
1 parent 33803e6 commit adbdbd4

6 files changed

Lines changed: 176 additions & 4 deletions

File tree

‎.github/workflows/update-dist.yml‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Update dist
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- main
7+
- master
8+
- release/v2
9+
paths:
10+
- "src/**"
11+
- "package.json"
12+
- "pnpm-lock.yaml"
13+
- "tsconfig.json"
14+
15+
concurrency:
16+
group: update-dist-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
permissions:
20+
contents: write
21+
22+
jobs:
23+
update-dist:
24+
runs-on: blacksmith-4vcpu-ubuntu-2404
25+
steps:
26+
- uses: actions/checkout@v6
27+
with:
28+
ref: ${{ github.ref }}
29+
30+
- uses: actions/setup-node@v6
31+
with:
32+
node-version: "20"
33+
34+
- uses: pnpm/action-setup@v4
35+
with:
36+
version: 10.33.0
37+
38+
- uses: bufbuild/buf-setup-action@v1
39+
with:
40+
github_token: ${{ github.token }}
41+
42+
- name: Configure npm for buf registry
43+
env:
44+
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
45+
run: |
46+
npm config set @buf:registry https://buf.build/gen/npm/v1/
47+
npm config set //buf.build/gen/npm/v1/:_authToken $BUF_TOKEN
48+
49+
- name: Install dependencies
50+
run: pnpm install
51+
52+
- name: Build
53+
run: pnpm run build
54+
55+
- name: Check for dist changes
56+
id: diff
57+
run: |
58+
if [[ -n "$(git status --porcelain dist/)" ]]; then
59+
echo "changed=true" >> $GITHUB_OUTPUT
60+
fi
61+
62+
- name: Commit and push updated dist
63+
if: steps.diff.outputs.changed == 'true'
64+
run: |
65+
git config user.name "github-actions[bot]"
66+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
67+
git add dist/
68+
git commit -m "chore: rebuild dist"
69+
git pull --rebase
70+
git push

‎src/reporter.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { describe, it, expect, vi, beforeEach } from "vitest";
2+
import axios from "axios";
3+
import * as reporter from "./reporter";
4+
import { UserInputError } from "./user-input-error";
5+
6+
vi.mock("@actions/core", () => ({
7+
debug: vi.fn(),
8+
warning: vi.fn(),
9+
info: vi.fn(),
10+
error: vi.fn(),
11+
}));
12+
13+
vi.mock("axios", () => ({
14+
default: {
15+
create: vi.fn(),
16+
},
17+
}));
18+
19+
vi.mock("axios-retry", () => {
20+
const axiosRetry = vi.fn() as unknown as {
21+
(): void;
22+
exponentialDelay: unknown;
23+
isNetworkOrIdempotentRequestError: unknown;
24+
};
25+
axiosRetry.exponentialDelay = vi.fn();
26+
axiosRetry.isNetworkOrIdempotentRequestError = vi.fn();
27+
return { default: axiosRetry };
28+
});
29+
30+
describe("reportBuildPushActionFailure", () => {
31+
beforeEach(() => {
32+
vi.clearAllMocks();
33+
});
34+
35+
it("does not report user input errors to the backend", async () => {
36+
await reporter.reportBuildPushActionFailure(
37+
"STICKYDISK_SETUP",
38+
new UserInputError("The 'cache-key' input is required"),
39+
"sticky disk setup",
40+
);
41+
42+
expect(axios.create).not.toHaveBeenCalled();
43+
});
44+
45+
it("reports other errors to the backend", async () => {
46+
const post = vi.fn().mockResolvedValue({ data: { status: "recorded" } });
47+
vi.mocked(axios.create).mockReturnValue({ post } as never);
48+
49+
await reporter.reportBuildPushActionFailure(
50+
"STICKYDISK_SETUP",
51+
new Error("qemu-nbd timed out"),
52+
"sticky disk setup",
53+
);
54+
55+
expect(post).toHaveBeenCalledWith(
56+
"/stickydisks/report-failed",
57+
expect.objectContaining({
58+
type: "STICKYDISK_SETUP",
59+
message: "sticky disk setup: qemu-nbd timed out",
60+
}),
61+
);
62+
});
63+
});

‎src/reporter.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from "@actions/core";
2+
import { UserInputError } from "./user-input-error";
23
import axios from "axios";
34
import axiosRetry from "axios-retry";
45
import { create } from "@bufbuild/protobuf";
@@ -112,6 +113,12 @@ export async function reportBuildPushActionFailure(
112113
error?: Error,
113114
event?: string,
114115
) {
116+
if (error instanceof UserInputError) {
117+
core.debug(
118+
`Not reporting user input error to Blacksmith: ${error.message}`,
119+
);
120+
return;
121+
}
115122
const requestOptions = {
116123
stickydisk_key: process.env.GITHUB_REPO_NAME || "",
117124
repo_name: process.env.GITHUB_REPO_NAME || "",

‎src/setup-builder.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
22
import * as core from "@actions/core";
33
import * as fs from "fs";
44
import * as setupBuilder from "./setup_builder";
5+
import { UserInputError } from "./user-input-error";
56
// import * as reporter from "./reporter";
67

78
// Mock the modules
@@ -11,6 +12,7 @@ vi.mock("@actions/core", () => ({
1112
info: vi.fn(),
1213
error: vi.fn(),
1314
setFailed: vi.fn(),
15+
getInput: vi.fn(() => ""),
1416
}));
1517

1618
vi.mock("./reporter", () => ({
@@ -48,6 +50,18 @@ describe("setup_builder", () => {
4850
process.env.BLACKSMITH_VM_ID = "test-vm-id";
4951
});
5052

53+
describe("getStickyDisk", () => {
54+
it("throws UserInputError without contacting the agent when cache-key is missing", async () => {
55+
vi.mocked(core.getInput).mockReturnValue("");
56+
const reporter = await import("./reporter");
57+
58+
await expect(setupBuilder.getStickyDisk()).rejects.toThrow(
59+
UserInputError,
60+
);
61+
expect(reporter.createBlacksmithAgentClient).not.toHaveBeenCalled();
62+
});
63+
});
64+
5165
describe("getNumCPUs", () => {
5266
it("should return the number of CPUs", async () => {
5367
const exec = (await import("child_process")).exec as unknown as {

‎src/setup_builder.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { exec } from "child_process";
44
import { promisify } from "util";
55
import * as TOML from "@iarna/toml";
66
import * as reporter from "./reporter";
7+
import { UserInputError } from "./user-input-error";
78
import { execa } from "execa";
89
import * as stateHelper from "./state-helper";
910
import { BOLT_CHECK_MAX_FILE_BYTES } from "./exec-utils";
@@ -408,6 +409,15 @@ export async function getStickyDisk(options?: {
408409
parent_snapshot_name: string;
409410
clone_name: string;
410411
}> {
412+
const cacheKey = core.getInput("cache-key");
413+
if (cacheKey === "") {
414+
throw new UserInputError(
415+
"The 'cache-key' input is required as of setup-docker-builder v2. " +
416+
"Add it to your workflow step, e.g. 'cache-key: my-repo/my-image'. " +
417+
"See https://github.com/useblacksmith/setup-docker-builder#readme for details.",
418+
);
419+
}
420+
411421
const client = await reporter.createBlacksmithAgentClient();
412422
core.info(`Created Blacksmith agent client`);
413423

@@ -419,10 +429,6 @@ export async function getStickyDisk(options?: {
419429
throw new Error(`grpc connection test failed: ${(error as Error).message}`);
420430
}
421431

422-
const cacheKey = core.getInput("cache-key", { required: true });
423-
if (cacheKey === "") {
424-
throw new Error("cache-key input is required but was empty");
425-
}
426432
const stickyDiskKey = cacheKey;
427433
core.info(`Getting sticky disk for cache-key: ${stickyDiskKey}`);
428434

‎src/user-input-error.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* A misconfiguration in the user's workflow (e.g. a missing required input),
3+
* as opposed to a Blacksmith platform failure. These errors still fail or
4+
* degrade the action as usual, but are never reported to the Blacksmith
5+
* backend, so they cannot pollute platform failure metrics and alerts.
6+
*/
7+
export class UserInputError extends Error {
8+
constructor(message: string) {
9+
super(message);
10+
this.name = "UserInputError";
11+
}
12+
}

0 commit comments

Comments
 (0)