Skip to content
Open
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
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ inputs:
description: "Token with permissions to do repo things"
required: false
default: "${{ github.token }}"
max-retries:
description: "Maximum number of retry attempts for HTTP requests"
required: false
default: "3"

runs:
using: "node20"
Expand Down
22 changes: 14 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,21 @@ const io = __nccwpck_require__(4994);
const osPlat = os.platform();
const osArch = os.arch();
// Retrieve a list of versions scraping tags from the Github API
function fetchVersions(repoToken) {
function fetchVersions(repoToken, maxRetries) {
return __awaiter(this, void 0, void 0, function* () {
let rest;
if (repoToken !== "") {
rest = new restm.RestClient("setup-task", "", [], {
headers: { Authorization: `Bearer ${repoToken}` },
allowRetries: true,
maxRetries,
});
}
else {
rest = new restm.RestClient("setup-task");
rest = new restm.RestClient("setup-task", "", [], {
allowRetries: true,
maxRetries,
});
}
const tags = (yield rest.get("https://api.github.com/repos/go-task/task/releases?per_page=100")).result || [];
return tags.map((tag) => tag.tag_name.replace(/^v/, ""));
Expand Down Expand Up @@ -122,7 +127,7 @@ function normalizeVersion(version) {
return version;
}
// Compute an actual version starting from the `version` configuration param.
function computeVersion(version, repoToken) {
function computeVersion(version, repoToken, maxRetries) {
return __awaiter(this, void 0, void 0, function* () {
// return if passed version is a valid semver
if (semver.valid(version)) {
Expand All @@ -138,7 +143,7 @@ function computeVersion(version, repoToken) {
if (versionPrefix.endsWith(".x")) {
versionPrefix = versionPrefix.slice(0, versionPrefix.length - 2);
}
const allVersions = yield fetchVersions(repoToken);
const allVersions = yield fetchVersions(repoToken, maxRetries);
const possibleVersions = allVersions.filter((v) => v.startsWith(versionPrefix));
const versionMap = new Map();
possibleVersions.forEach((v) => versionMap.set(normalizeVersion(v), v));
Expand Down Expand Up @@ -200,10 +205,10 @@ function downloadRelease(version) {
return tc.cacheDir(extPath, "task", version);
});
}
function getTask(version, repoToken) {
return __awaiter(this, void 0, void 0, function* () {
function getTask(version_1, repoToken_1) {
return __awaiter(this, arguments, void 0, function* (version, repoToken, maxRetries = 3) {
// resolve the version number
const targetVersion = yield computeVersion(version, repoToken);
const targetVersion = yield computeVersion(version, repoToken, maxRetries);
// look if the binary is cached
let toolPath;
toolPath = tc.find("task", targetVersion);
Expand Down Expand Up @@ -287,7 +292,8 @@ function run() {
try {
const version = core.getInput("version", { required: true });
const repoToken = core.getInput("repo-token");
yield installer.getTask(version, repoToken);
const maxRetries = parseInt(core.getInput("max-retries") || "3", 10);
yield installer.getTask(version, repoToken, maxRetries);
}
catch (error) {
if (error instanceof Error) {
Expand Down
23 changes: 18 additions & 5 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ interface ITaskRelease {
}

// Retrieve a list of versions scraping tags from the Github API
async function fetchVersions(repoToken: string): Promise<string[]> {
async function fetchVersions(
repoToken: string,
maxRetries: number,
): Promise<string[]> {
let rest: restm.RestClient;
if (repoToken !== "") {
rest = new restm.RestClient("setup-task", "", [], {
headers: { Authorization: `Bearer ${repoToken}` },
allowRetries: true,
maxRetries,
});
} else {
rest = new restm.RestClient("setup-task");
rest = new restm.RestClient("setup-task", "", [], {
allowRetries: true,
maxRetries,
});
}

const tags: ITaskRelease[] =
Expand Down Expand Up @@ -91,6 +99,7 @@ function normalizeVersion(version: string): string {
async function computeVersion(
version: string,
repoToken: string,
maxRetries: number,
): Promise<string> {
// return if passed version is a valid semver
if (semver.valid(version)) {
Expand All @@ -109,7 +118,7 @@ async function computeVersion(
versionPrefix = versionPrefix.slice(0, versionPrefix.length - 2);
}

const allVersions = await fetchVersions(repoToken);
const allVersions = await fetchVersions(repoToken, maxRetries);
const possibleVersions = allVersions.filter((v) =>
v.startsWith(versionPrefix),
);
Expand Down Expand Up @@ -183,9 +192,13 @@ async function downloadRelease(version: string): Promise<string> {
return tc.cacheDir(extPath, "task", version);
}

export async function getTask(version: string, repoToken: string) {
export async function getTask(
version: string,
repoToken: string,
maxRetries: number = 3,
) {
// resolve the version number
const targetVersion = await computeVersion(version, repoToken);
const targetVersion = await computeVersion(version, repoToken, maxRetries);

// look if the binary is cached
let toolPath: string;
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ async function run() {
try {
const version = core.getInput("version", { required: true });
const repoToken = core.getInput("repo-token");
const maxRetries = parseInt(core.getInput("max-retries") || "3", 10);

await installer.getTask(version, repoToken);
await installer.getTask(version, repoToken, maxRetries);
} catch (error) {
if (error instanceof Error) {
core.setFailed(error.message);
Expand Down
Loading