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
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @egym/sre
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function getProtoc(version, includePreReleases, repoToken) {
toolPath = tc.find("protoc", version);
// if not: download, extract and cache
if (!toolPath) {
toolPath = yield downloadRelease(version);
toolPath = yield downloadRelease(version, repoToken);
process.stdout.write("Protoc cached under " + toolPath + os.EOL);
}
// expose outputs
Expand All @@ -93,15 +93,17 @@ function getProtoc(version, includePreReleases, repoToken) {
});
}
exports.getProtoc = getProtoc;
function downloadRelease(version) {
function downloadRelease(version, repoToken) {
return __awaiter(this, void 0, void 0, function* () {
// Download
const fileName = getFileName(version, osPlat, osArch);
const downloadUrl = util.format("https://github.com/protocolbuffers/protobuf/releases/download/%s/%s", version, fileName);
process.stdout.write("Downloading archive: " + downloadUrl + os.EOL);
let downloadPath = null;
try {
downloadPath = yield tc.downloadTool(downloadUrl);
// Pass authentication token to avoid rate limiting
const auth = repoToken ? `token ${repoToken}` : undefined;
downloadPath = yield tc.downloadTool(downloadUrl, undefined, auth);
}
catch (err) {
if (err instanceof tc.HTTPError) {
Expand Down
11 changes: 8 additions & 3 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function getProtoc(

// if not: download, extract and cache
if (!toolPath) {
toolPath = await downloadRelease(version);
toolPath = await downloadRelease(version, repoToken);
process.stdout.write("Protoc cached under " + toolPath + os.EOL);
}

Expand All @@ -71,7 +71,10 @@ export async function getProtoc(
core.addPath(path.join(toolPath, "bin"));
}

async function downloadRelease(version: string): Promise<string> {
async function downloadRelease(
version: string,
repoToken: string,
): Promise<string> {
// Download
const fileName: string = getFileName(version, osPlat, osArch);
const downloadUrl: string = util.format(
Expand All @@ -83,7 +86,9 @@ async function downloadRelease(version: string): Promise<string> {

let downloadPath: string | null = null;
try {
downloadPath = await tc.downloadTool(downloadUrl);
// Pass authentication token to avoid rate limiting
const auth = repoToken ? `token ${repoToken}` : undefined;
downloadPath = await tc.downloadTool(downloadUrl, undefined, auth);
} catch (err) {
if (err instanceof tc.HTTPError) {
core.debug(err.message);
Expand Down