Skip to content
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
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface Inputs {
'github-token': string;
nofallback: boolean;
setupOnly: boolean;
'buildx-version': string;
}

export async function getInputs(): Promise<Inputs> {
Expand Down Expand Up @@ -98,6 +99,7 @@ export async function getInputs(): Promise<Inputs> {
'github-token': core.getInput('github-token'),
nofallback: core.getBooleanInput('nofallback'),
setupOnly: core.getBooleanInput('setup-only'),
'buildx-version': core.getInput('buildx-version')
};
}

Expand Down
20 changes: 19 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import * as reporter from './reporter';
import {setupStickyDisk, startAndConfigureBuildkitd, getNumCPUs, leaveTailnet, pruneBuildkitCache} from './setup_builder';
import {Metric_MetricType} from '@buf/blacksmith_vm-agent.bufbuild_es/stickydisk/v1/stickydisk_pb';

const buildxVersion = 'v0.17.0';
const DEFAULT_BUILDX_VERSION = 'v0.23.0';

const mountPoint = '/var/lib/buildkit';
const execAsync = promisify(exec);

Expand Down Expand Up @@ -73,6 +74,12 @@ async function setupBuildx(version: string, toolkit: Toolkit): Promise<void> {
});
}

// Validates the version string to ensure it matches a basic expected pattern.
// Accepts versions of the form `v<MAJOR>.<MINOR>.<PATCH>` (e.g., v0.20.0) or the literal string `latest`.
function isValidBuildxVersion(version: string): boolean {
return version === 'latest' || /^v\d+\.\d+\.\d+$/.test(version);
}

/**
* Attempts to set up a Blacksmith builder for Docker builds.
*
Expand Down Expand Up @@ -159,6 +166,17 @@ actionsToolkit.run(
}
});

// Determine which Buildx version to install. If the user provided an input, validate it;
// otherwise, fall back to the default.
let buildxVersion = DEFAULT_BUILDX_VERSION;
if (inputs['buildx-version'] && inputs['buildx-version'].trim() !== '') {
if (isValidBuildxVersion(inputs['buildx-version'])) {
buildxVersion = inputs['buildx-version'];
} else {
core.warning(`Invalid buildx-version '${inputs['buildx-version']}'. ` + `Expected 'latest' or a version in the form v<MAJOR>.<MINOR>.<PATCH>. ` + `Falling back to default ${DEFAULT_BUILDX_VERSION}.`);
}
}

await core.group(`Setup buildx`, async () => {
await setupBuildx(buildxVersion, toolkit);

Expand Down