From d5f88d3f9e6ea5be5872779037f3d5b03d250a2c Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:14:34 +0200 Subject: [PATCH 01/14] test --- .github/workflows/test.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 255097ef..48cc1589 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,4 +30,10 @@ jobs: run: npm run format-check - name: npm test - run: npm test \ No newline at end of file + run: npm test + + - name: foo + uses: arduino/setup-protoc + + - name: bar + run: protoc --version \ No newline at end of file From a409938a3d3dcaa00c43d7b1e438ff81d085834a Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:16:12 +0200 Subject: [PATCH 02/14] fix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48cc1589..c6ab69a4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ on: push: branches: - master - pull_request: + pull_request: jobs: test: From 3833526a21e421532149d6e89b8090151495d0b6 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:17:13 +0200 Subject: [PATCH 03/14] fix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c6ab69a4..89b848bb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: run: npm test - name: foo - uses: arduino/setup-protoc + uses: arduino/setup-protoc@massi/test - name: bar run: protoc --version \ No newline at end of file From 7028ab700e367f675d06aabcd2c2b4994d11e563 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:27:50 +0200 Subject: [PATCH 04/14] debug --- src/installer.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/installer.ts b/src/installer.ts index 26866a0a..dfaab3a2 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -88,6 +88,8 @@ async function downloadRelease(version: string): Promise { version, fileName ); + core.warning("Downloading archive: " + downloadUrl); + let downloadPath: string | null = null; try { downloadPath = await tc.downloadTool(downloadUrl); From e78973f4174b32d14073b15b4a2eee3c622c4403 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:31:44 +0200 Subject: [PATCH 05/14] try --- .github/workflows/test.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89b848bb..473d27ef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,19 +18,19 @@ jobs: - name: Checkout uses: actions/checkout@master - - name: Set Node.js 10.x - uses: actions/setup-node@master - with: - version: 10.x + # - name: Set Node.js 10.x + # uses: actions/setup-node@master + # with: + # version: 10.x - - name: npm install - run: npm install + # - name: npm install + # run: npm install - - name: npm lint - run: npm run format-check + # - name: npm lint + # run: npm run format-check - - name: npm test - run: npm test + # - name: npm test + # run: npm test - name: foo uses: arduino/setup-protoc@massi/test From 5fcb87d8f9b4ace0ea3c6dbc5c594d7e9a44f6cd Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:40:18 +0200 Subject: [PATCH 06/14] log --- .github/workflows/test.yml | 2 +- src/installer.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 473d27ef..5b82f1c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,7 +21,7 @@ jobs: # - name: Set Node.js 10.x # uses: actions/setup-node@master # with: - # version: 10.x + # node-version: 10.x # - name: npm install # run: npm install diff --git a/src/installer.ts b/src/installer.ts index dfaab3a2..d2c27c23 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -49,7 +49,7 @@ export async function getProtoc(version: string, includePreReleases: boolean) { // if not: download, extract and cache if (!toolPath) { toolPath = await downloadRelease(version); - core.debug("Protoc cached under " + toolPath); + core.info("Protoc cached under " + toolPath); } // add the bin folder to the PATH @@ -88,7 +88,7 @@ async function downloadRelease(version: string): Promise { version, fileName ); - core.warning("Downloading archive: " + downloadUrl); + core.info("Downloading archive: " + downloadUrl); let downloadPath: string | null = null; try { From c529bafa77660d569effa124c58867d688e537d9 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:44:45 +0200 Subject: [PATCH 07/14] log --- src/installer.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/installer.ts b/src/installer.ts index d2c27c23..48fbfaf7 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -41,6 +41,7 @@ export async function getProtoc(version: string, includePreReleases: boolean) { if (targetVersion) { version = targetVersion; } + core.info("Getting protoc version: " + version) // look if the binary is cached let toolPath: string; From a81e7f161b8b16b599258bb66e77fc8e13fc2874 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:47:14 +0200 Subject: [PATCH 08/14] try --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5b82f1c1..a40bced4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: # run: npm test - name: foo - uses: arduino/setup-protoc@massi/test + uses: arduino/setup-protoc@c529baf - name: bar run: protoc --version \ No newline at end of file From b0382daf82f90b8c368d8316f2bc730713a4a872 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 15:53:49 +0200 Subject: [PATCH 09/14] revert --- .github/workflows/test.yml | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a40bced4..867969bf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,22 +18,16 @@ jobs: - name: Checkout uses: actions/checkout@master - # - name: Set Node.js 10.x - # uses: actions/setup-node@master - # with: - # node-version: 10.x + - name: Set Node.js 10.x + uses: actions/setup-node@master + with: + node-version: 10.x - # - name: npm install - # run: npm install + - name: npm install + run: npm install - # - name: npm lint - # run: npm run format-check + - name: npm lint + run: npm run format-check - # - name: npm test - # run: npm test - - - name: foo - uses: arduino/setup-protoc@c529baf - - - name: bar - run: protoc --version \ No newline at end of file + - name: npm test + run: npm test \ No newline at end of file From 61c54239f47f9086672b2455ae8b45ed0982c23e Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 16:33:41 +0200 Subject: [PATCH 10/14] fix --- lib/installer.js | 31 ++++++++++++++++--------------- lib/main.js | 3 ++- src/installer.ts | 32 +++++++++++++++++++++++--------- src/main.ts | 3 ++- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index 412c1003..a18c2427 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -44,20 +44,21 @@ const exc = __importStar(require("@actions/exec")); const io = __importStar(require("@actions/io")); let osPlat = os.platform(); let osArch = os.arch(); -function getProtoc(version, includePreReleases) { +function getProtoc(version, includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { // resolve the version number - const targetVersion = yield computeVersion(version, includePreReleases); + const targetVersion = yield computeVersion(version, includePreReleases, repoToken); if (targetVersion) { version = targetVersion; } + process.stdout.write("Getting protoc version: " + version + os.EOL); // look if the binary is cached let toolPath; toolPath = tc.find("protoc", version); // if not: download, extract and cache if (!toolPath) { toolPath = yield downloadRelease(version); - core.debug("Protoc cached under " + toolPath); + process.stdout.write("Protoc cached under " + toolPath + os.EOL); } // add the bin folder to the PATH toolPath = path.join(toolPath, "bin"); @@ -89,6 +90,7 @@ function downloadRelease(version) { // Download let fileName = getFileName(version); let 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); @@ -114,13 +116,17 @@ function getFileName(version) { return util.format("protoc-%s-win%s.zip", version, arch); } const arch = osArch == "x64" ? "x86_64" : "x86_32"; - const filename = util.format("protoc-%s-linux-%s.zip", version, arch); - return filename; + if (osPlat == "darwin") { + return util.format("protoc-%s-osx-%s.zip", version, arch); + } + return util.format("protoc-%s-linux-%s.zip", version, arch); } // Retrieve a list of versions scraping tags from the Github API -function fetchVersions(includePreReleases) { +function fetchVersions(includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { - let rest = new restm.RestClient("setup-protoc"); + let rest = new restm.RestClient("setup-protoc", "", [], { + headers: { Authorization: "Bearer " + repoToken } + }); let tags = (yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases")).result || []; return tags .filter(tag => tag.tag_name.match(/v\d+\.[\w\.]+/g)) @@ -129,7 +135,7 @@ function fetchVersions(includePreReleases) { }); } // Compute an actual version starting from the `version` configuration param. -function computeVersion(version, includePreReleases) { +function computeVersion(version, includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { // strip leading `v` char (will be re-added later) if (version.startsWith("v")) { @@ -139,7 +145,7 @@ function computeVersion(version, includePreReleases) { if (version.endsWith(".x")) { version = version.slice(0, version.length - 2); } - const allVersions = yield fetchVersions(includePreReleases); + const allVersions = yield fetchVersions(includePreReleases, repoToken); const validVersions = allVersions.filter(v => semver.valid(v)); const possibleVersions = validVersions.filter(v => v.startsWith(version)); const versionMap = new Map(); @@ -195,10 +201,5 @@ function normalizeVersion(version) { return version; } function includePrerelease(isPrerelease, includePrereleases) { - if (!includePrereleases) { - if (isPrerelease) { - return false; - } - } - return true; + return includePrereleases || !isPrerelease; } diff --git a/lib/main.js b/lib/main.js index 5b7c5472..ef1dbd5c 100644 --- a/lib/main.js +++ b/lib/main.js @@ -22,7 +22,8 @@ function run() { try { let version = core.getInput("version"); let includePreReleases = convertToBoolean(core.getInput("include-pre-releases")); - yield installer.getProtoc(version, includePreReleases); + let repoToken = core.getInput("repo-token"); + yield installer.getProtoc(version, includePreReleases, repoToken); } catch (error) { core.setFailed(error.message); diff --git a/src/installer.ts b/src/installer.ts index 48fbfaf7..370ab929 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -35,13 +35,21 @@ interface IProtocRelease { prerelease: boolean; } -export async function getProtoc(version: string, includePreReleases: boolean) { +export async function getProtoc( + version: string, + includePreReleases: boolean, + repoToken: string +) { // resolve the version number - const targetVersion = await computeVersion(version, includePreReleases); + const targetVersion = await computeVersion( + version, + includePreReleases, + repoToken + ); if (targetVersion) { version = targetVersion; } - core.info("Getting protoc version: " + version) + process.stdout.write("Getting protoc version: " + version + os.EOL); // look if the binary is cached let toolPath: string; @@ -50,7 +58,7 @@ export async function getProtoc(version: string, includePreReleases: boolean) { // if not: download, extract and cache if (!toolPath) { toolPath = await downloadRelease(version); - core.info("Protoc cached under " + toolPath); + process.stdout.write("Protoc cached under " + toolPath + os.EOL); } // add the bin folder to the PATH @@ -89,7 +97,7 @@ async function downloadRelease(version: string): Promise { version, fileName ); - core.info("Downloading archive: " + downloadUrl); + process.stdout.write("Downloading archive: " + downloadUrl + os.EOL); let downloadPath: string | null = null; try { @@ -128,8 +136,13 @@ function getFileName(version: string): string { } // Retrieve a list of versions scraping tags from the Github API -async function fetchVersions(includePreReleases: boolean): Promise { - let rest: restm.RestClient = new restm.RestClient("setup-protoc"); +async function fetchVersions( + includePreReleases: boolean, + repoToken: string +): Promise { + let rest: restm.RestClient = new restm.RestClient("setup-protoc", "", [], { + headers: { Authorization: "Bearer " + repoToken } + }); let tags: IProtocRelease[] = (await rest.get( "https://api.github.com/repos/protocolbuffers/protobuf/releases" @@ -144,7 +157,8 @@ async function fetchVersions(includePreReleases: boolean): Promise { // Compute an actual version starting from the `version` configuration param. async function computeVersion( version: string, - includePreReleases: boolean + includePreReleases: boolean, + repoToken: string ): Promise { // strip leading `v` char (will be re-added later) if (version.startsWith("v")) { @@ -156,7 +170,7 @@ async function computeVersion( version = version.slice(0, version.length - 2); } - const allVersions = await fetchVersions(includePreReleases); + const allVersions = await fetchVersions(includePreReleases, repoToken); const validVersions = allVersions.filter(v => semver.valid(v)); const possibleVersions = validVersions.filter(v => v.startsWith(version)); diff --git a/src/main.ts b/src/main.ts index 8b9d5903..b70341a4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,7 +7,8 @@ async function run() { let includePreReleases = convertToBoolean( core.getInput("include-pre-releases") ); - await installer.getProtoc(version, includePreReleases); + let repoToken = core.getInput("repo-token"); + await installer.getProtoc(version, includePreReleases, repoToken); } catch (error) { core.setFailed(error.message); } From b803f755556171448fc6414707ec461e4fcaae32 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 16:39:08 +0200 Subject: [PATCH 11/14] fix --- __tests__/main.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 55bb28f2..4801103e 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -14,7 +14,7 @@ process.env["RUNNER_TOOL_CACHE"] = toolDir; import * as installer from "../src/installer"; describe("installer tests", () => { - beforeEach(async function() { + beforeEach(async function () { await io.rmRF(toolDir); await io.rmRF(tempDir); await io.mkdirP(toolDir); @@ -31,7 +31,7 @@ describe("installer tests", () => { }); it("Downloads version of protoc if no matching version is installed", async () => { - await installer.getProtoc("3.9.0", true); + await installer.getProtoc("3.9.0", true, ""); const protocDir = path.join(toolDir, "protoc", "3.9.0", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); @@ -58,7 +58,7 @@ describe("installer tests", () => { }); it("Gets the latest 3.7.x version of protoc using 3.7 and no matching version is installed", async () => { - await installer.getProtoc("3.7", true); + await installer.getProtoc("3.7", true, ""); const protocDir = path.join(toolDir, "protoc", "3.7.1", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); @@ -72,7 +72,7 @@ describe("installer tests", () => { }, 100000); it("Gets latest version of protoc using 3.x and no matching version is installed", async () => { - await installer.getProtoc("3.x", true); + await installer.getProtoc("3.x", true, ""); const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); @@ -99,7 +99,7 @@ describe("installer tests", () => { }); it("Gets latest version of protoc using 3.x with a broken rc tag, filtering pre-releases", async () => { - await installer.getProtoc("3.x", false); + await installer.getProtoc("3.x", false, ""); const protocDir = path.join(toolDir, "protoc", "3.9.1", os.arch()); expect(fs.existsSync(`${protocDir}.complete`)).toBe(true); From 07b8e363a2f82db97e72082a478de0b4db4f11ad Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 16:46:06 +0200 Subject: [PATCH 12/14] fix --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 867969bf..385da08c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,8 @@ jobs: run: npm install - name: npm lint + # check style only once + if: matrix.operating-system == 'ubuntu-latest' run: npm run format-check - name: npm test From e3ec28a64640fe744ed7ef2abf4956a498cc6ea8 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 16:52:19 +0200 Subject: [PATCH 13/14] fix --- lib/installer.js | 12 +++++++++--- src/installer.ts | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/installer.js b/lib/installer.js index a18c2427..8894bcc2 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -124,9 +124,15 @@ function getFileName(version) { // Retrieve a list of versions scraping tags from the Github API function fetchVersions(includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { - let rest = new restm.RestClient("setup-protoc", "", [], { - headers: { Authorization: "Bearer " + repoToken } - }); + let rest; + if (repoToken != "") { + rest = new restm.RestClient("setup-protoc", "", [], { + headers: { Authorization: "Bearer " + repoToken } + }); + } + else { + rest = new restm.RestClient("setup-protoc"); + } let tags = (yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases")).result || []; return tags .filter(tag => tag.tag_name.match(/v\d+\.[\w\.]+/g)) diff --git a/src/installer.ts b/src/installer.ts index 370ab929..0487d6d3 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -140,9 +140,15 @@ async function fetchVersions( includePreReleases: boolean, repoToken: string ): Promise { - let rest: restm.RestClient = new restm.RestClient("setup-protoc", "", [], { - headers: { Authorization: "Bearer " + repoToken } - }); + let rest: restm.RestClient; + if (repoToken != "") { + rest = new restm.RestClient("setup-protoc", "", [], { + headers: { Authorization: "Bearer " + repoToken } + }); + } else { + rest = new restm.RestClient("setup-protoc"); + } + let tags: IProtocRelease[] = (await rest.get( "https://api.github.com/repos/protocolbuffers/protobuf/releases" From cd80deba3c89582a3cb7e02eebb9d54cc35cfb13 Mon Sep 17 00:00:00 2001 From: Massimiliano Pippi Date: Tue, 22 Oct 2019 17:02:15 +0200 Subject: [PATCH 14/14] fix --- __tests__/main.test.ts | 2 +- package-lock.json | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 4801103e..47bf198e 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -14,7 +14,7 @@ process.env["RUNNER_TOOL_CACHE"] = toolDir; import * as installer from "../src/installer"; describe("installer tests", () => { - beforeEach(async function () { + beforeEach(async function() { await io.rmRF(toolDir); await io.rmRF(tempDir); await io.mkdirP(toolDir); diff --git a/package-lock.json b/package-lock.json index c0c123ea..2fc0a746 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1135,9 +1135,9 @@ } }, "commander": { - "version": "2.20.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.0.tgz", - "integrity": "sha512-7j2y+40w61zy6YC2iRNpUe/NwhNyoXrYpHMrSunaMG64nRnaf96zO/KMQR4OyN/UnE5KLyEBnKHd4aG3rskjpQ==", + "version": "2.20.3", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "dev": true, "optional": true }, @@ -2369,9 +2369,9 @@ "dev": true }, "handlebars": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.1.2.tgz", - "integrity": "sha512-nvfrjqvt9xQ8Z/w0ijewdD/vvWDTOweBUm96NTr66Wfvo1mJenBLwcYmPs3TIBP5ruzYGD7Hx/DaM9RmhroGPw==", + "version": "4.4.5", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.4.5.tgz", + "integrity": "sha512-0Ce31oWVB7YidkaTq33ZxEbN+UDxMMgThvCe8ptgQViymL5DPis9uLdTA13MiRPhgvqyxIegugrP97iK3JeBHg==", "dev": true, "requires": { "neo-async": "^2.6.0", @@ -5089,13 +5089,13 @@ "dev": true }, "uglify-js": { - "version": "3.6.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.0.tgz", - "integrity": "sha512-W+jrUHJr3DXKhrsS7NUVxn3zqMOFn0hL/Ei6v0anCIMoKC93TjcflTagwIHLW7SfMFfiQuktQyFVCFHGUE0+yg==", + "version": "3.6.3", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.3.tgz", + "integrity": "sha512-KfQUgOqTkLp2aZxrMbCuKCDGW9slFYu2A23A36Gs7sGzTLcRBDORdOi5E21KWHFIfkY8kzgi/Pr1cXCh0yIp5g==", "dev": true, "optional": true, "requires": { - "commander": "~2.20.0", + "commander": "~2.20.3", "source-map": "~0.6.1" } },