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
38 changes: 29 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 36 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,46 @@ async function installTailscaleLinux(

// Download and extract
const downloadUrl = `${baseUrl}/tailscale_${config.resolvedVersion}_${config.arch}.tgz`;
logInfo(config.logMode, `Downloading ${downloadUrl}`);
const expectedSha = config.sha256Sum.trim().toLowerCase();

const tarDest = path.join(xdgCacheDir(), "tailscale.tgz");
fs.mkdirSync(path.dirname(tarDest), { recursive: true });
const tarPath = await tc.downloadTool(downloadUrl, tarDest);

// Verify checksum
const actualSha = await calculateFileSha256(tarPath);
const expectedSha = config.sha256Sum.trim().toLowerCase();
logInfo(config.logMode, `Expected sha256: ${expectedSha}`);
logInfo(config.logMode, `Actual sha256: ${actualSha}`);
if (actualSha !== expectedSha) {
throw new Error("SHA256 checksum mismatch");
// Check if the tarball already exists with the correct checksum (for
// persistent self-hosted runners). tc.downloadTool refuses to overwrite an
// existing destination, so a tarball leaked by a previous job would
// otherwise fail with "Destination file path already exists" whenever the
// GitHub Actions cache backend doesn't return a hit.
let tarPath = tarDest;
let needsDownload = true;
if (fs.existsSync(tarDest)) {
const existingSha = await calculateFileSha256(tarDest);
if (existingSha === expectedSha) {
logInfo(
config.logMode,
`Using existing tarball at ${tarDest} (checksum verified)`,
);
needsDownload = false;
} else {
logInfo(
config.logMode,
`Existing tarball checksum mismatch, re-downloading`,
);
fs.unlinkSync(tarDest);
}
}

if (needsDownload) {
logInfo(config.logMode, `Downloading ${downloadUrl}`);
tarPath = await tc.downloadTool(downloadUrl, tarDest);

// Verify checksum
const actualSha = await calculateFileSha256(tarPath);
logInfo(config.logMode, `Expected sha256: ${expectedSha}`);
logInfo(config.logMode, `Actual sha256: ${actualSha}`);
if (actualSha !== expectedSha) {
throw new Error("SHA256 checksum mismatch");
}
}

// Extract to tool path
Expand Down
Loading