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
30 changes: 13 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65629,6 +65629,7 @@ const TELEMETRY_RETRY = {
maxTimeout: 10000,
maxRetryTime: 10000,
};
const DEFAULT_CLI_VERSION = "0.11.8";
const FAILURE_PREVIOUS_STEP_CODE = 1;
class CliFetchError extends Error {
constructor(message, cause) {
Expand Down Expand Up @@ -65691,17 +65692,18 @@ const parseBoolean = (input) => {
return input.toLowerCase() === "true";
};
const downloadRelease = async (owner, repo, version, bin, tmpdir, platform) => {
// Get the GitHub token from the environment
const token = core.getInput("github-token");
if (!token) {
core.error("GITHUB_TOKEN is not set. Please ensure the job has the necessary permissions. Attempting to run unauthenticated.");
}
const octokit = new dist_src_Octokit({
auth: token,
});
const release = version === "latest"
? await octokit.repos.getLatestRelease({ owner, repo })
: await octokit.repos.getReleaseByTag({ owner, repo, tag: version });
const release = await octokit.repos.getReleaseByTag({
owner,
repo,
tag: version,
});
const assetName = platform === "win32"
? `trunk-analytics-cli-${bin}-experimental.zip`
: `trunk-analytics-cli-${bin}.tar.gz`;
Expand Down Expand Up @@ -65862,13 +65864,12 @@ const resolveCliVersion = async (version) => {
}
catch (error) {
if (error instanceof Error) {
core.warning(`Failed to resolve latest version: ${error.message}. Caching will be disabled.`);
core.warning(`Failed to resolve latest version: ${error.message}. Falling back to version ${DEFAULT_CLI_VERSION}.`);
}
else {
core.warning("Failed to resolve latest version. Caching will be disabled.");
core.warning(`Failed to resolve latest version. Falling back to version ${DEFAULT_CLI_VERSION}.`);
}
// Return null to indicate caching should be disabled
return null;
return DEFAULT_CLI_VERSION;
}
};
const restoreCache = async (bin, cliVersion, tmpdir) => {
Expand Down Expand Up @@ -65965,20 +65966,15 @@ const main = async (tmpdir) => {
: platform === "win32"
? executableName
: `./${executableName}`;
// Resolve "latest" to actual version for consistent cache keys
const resolvedCliVersion = await resolveCliVersion(cliVersion);
// Only use cache if version was successfully resolved (not null)
const shouldUseCache = parseBoolean(useCache) && resolvedCliVersion !== null;
const shouldUseCache = parseBoolean(useCache);
let cacheRestored = false;
if (shouldUseCache && resolvedCliVersion !== null) {
if (shouldUseCache) {
cacheRestored = await restoreCache(bin, resolvedCliVersion, tmpdir);
}
else if (parseBoolean(useCache) && resolvedCliVersion === null) {
core.info("Caching disabled due to inability to resolve CLI version");
}
if (!external_fs_.existsSync(downloadPath)) {
core.info("Downloading trunk-analytics-cli...");
const release = await downloadRelease("trunk-io", "analytics-cli", cliVersion, bin, tmpdir, platform);
const release = await downloadRelease("trunk-io", "analytics-cli", resolvedCliVersion, bin, tmpdir, platform);
core.info("Download complete, extracting...");
if (platform === "win32") {
// Extract zip file using PowerShell
Expand All @@ -65990,7 +65986,7 @@ const main = async (tmpdir) => {
}
core.info("Extraction complete");
// Save to cache if enabled and we didn't restore from cache
if (shouldUseCache && !cacheRestored && resolvedCliVersion !== null) {
if (shouldUseCache && !cacheRestored) {
await saveCache(bin, resolvedCliVersion, tmpdir);
}
}
Expand Down
30 changes: 13 additions & 17 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const TELEMETRY_RETRY = {
maxRetryTime: 10000,
} satisfies OperationOptions;

const DEFAULT_CLI_VERSION = "0.11.8";

export const FAILURE_PREVIOUS_STEP_CODE = 1;

export class CliFetchError extends Error {
Expand Down Expand Up @@ -108,7 +110,6 @@ const downloadRelease = async (
tmpdir?: string,
platform?: string,
): Promise<string> => {
// Get the GitHub token from the environment
const token = core.getInput("github-token");
if (!token) {
core.error(
Expand All @@ -120,10 +121,11 @@ const downloadRelease = async (
auth: token,
});

const release =
version === "latest"
? await octokit.repos.getLatestRelease({ owner, repo })
: await octokit.repos.getReleaseByTag({ owner, repo, tag: version });
const release = await octokit.repos.getReleaseByTag({
owner,
repo,
tag: version,
});

const assetName =
platform === "win32"
Expand Down Expand Up @@ -292,7 +294,7 @@ export const convertToTelemetry = (apiAddress: string): string => {
return "https://telemetry.api.trunk.io/v1/flakytests-uploader/upload-metrics";
};

const resolveCliVersion = async (version: string): Promise<string | null> => {
const resolveCliVersion = async (version: string): Promise<string> => {
if (version !== "latest") {
return version;
}
Expand All @@ -314,15 +316,14 @@ const resolveCliVersion = async (version: string): Promise<string | null> => {
} catch (error: unknown) {
if (error instanceof Error) {
core.warning(
`Failed to resolve latest version: ${error.message}. Caching will be disabled.`,
`Failed to resolve latest version: ${error.message}. Falling back to version ${DEFAULT_CLI_VERSION}.`,
);
} else {
core.warning(
"Failed to resolve latest version. Caching will be disabled.",
`Failed to resolve latest version. Falling back to version ${DEFAULT_CLI_VERSION}.`,
);
}
// Return null to indicate caching should be disabled
return null;
return DEFAULT_CLI_VERSION;
}
};

Expand Down Expand Up @@ -461,25 +462,20 @@ export const main = async (tmpdir?: string): Promise<string | null> => {
? executableName
: `./${executableName}`;

// Resolve "latest" to actual version for consistent cache keys
const resolvedCliVersion = await resolveCliVersion(cliVersion);

// Only use cache if version was successfully resolved (not null)
const shouldUseCache =
parseBoolean(useCache) && resolvedCliVersion !== null;
const shouldUseCache = parseBoolean(useCache);
let cacheRestored = false;
if (shouldUseCache) {
cacheRestored = await restoreCache(bin, resolvedCliVersion, tmpdir);
} else if (parseBoolean(useCache) && resolvedCliVersion === null) {
core.info("Caching disabled due to inability to resolve CLI version");
}

if (!fs.existsSync(downloadPath)) {
core.info("Downloading trunk-analytics-cli...");
const release = await downloadRelease(
"trunk-io",
"analytics-cli",
cliVersion,
resolvedCliVersion,
bin,
tmpdir,
platform,
Expand Down
Loading