diff --git a/README.md b/README.md index e384a57e..b15c2d41 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# setup-protoc +# setup-protoc-to-env [![Check npm Dependencies status](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-dependencies-task.yml/badge.svg)](https://github.com/arduino/setup-protoc/actions/workflows/check-npm-dependencies-task.yml) ![test](https://github.com/arduino/setup-protoc/workflows/test/badge.svg) @@ -24,14 +24,14 @@ To get the latest stable version of `protoc` just add this step: ```yaml - name: Install Protoc - uses: arduino/setup-protoc@v3 + uses: actions-gw/setup-protoc-to-env@v3 ``` If you want to pin a major or minor version you can use the `.x` wildcard: ```yaml - name: Install Protoc - uses: arduino/setup-protoc@v3 + uses: actions-gw/setup-protoc-to-env@v3 with: version: "23.x" ``` @@ -40,7 +40,7 @@ You can also require to include releases marked as `pre-release` in Github using ```yaml - name: Install Protoc - uses: arduino/setup-protoc@v3 + uses: actions-gw/setup-protoc-to-env@v3 with: version: "23.x" include-pre-releases: true @@ -50,7 +50,7 @@ To pin the exact version: ```yaml - name: Install Protoc - uses: arduino/setup-protoc@v3 + uses: actions-gw/setup-protoc-to-env@v3 with: version: "23.2" ``` @@ -60,7 +60,7 @@ pass the default token with the `repo-token` variable: ```yaml - name: Install Protoc - uses: arduino/setup-protoc@v3 + uses: actions-gw/setup-protoc-to-env@v3 with: repo-token: ${{ secrets.GITHUB_TOKEN }} ``` diff --git a/action.yml b/action.yml index 1eaff061..36a9739f 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ -name: 'Setup protoc' -description: 'Download protoc compiler and add it to the PATH' +name: 'Setup protoc to env' +description: 'Download protoc compiler and add it to the PATH and PROTOC' author: 'Arduino' inputs: version: diff --git a/dist/index.js b/dist/index.js index 5988a2b1..49fd46cf 100644 --- a/dist/index.js +++ b/dist/index.js @@ -88,6 +88,12 @@ function getProtoc(version, includePreReleases, repoToken) { // expose outputs core.setOutput("path", toolPath); core.setOutput("version", targetVersion); + if (process.platform === "win32") { + core.exportVariable("PROTOC", toolPath + "\\bin\\protoc.exe"); + } + else { + core.exportVariable("PROTOC", toolPath + "/bin/protoc"); + } // add the bin folder to the PATH core.addPath(path.join(toolPath, "bin")); }); @@ -174,7 +180,7 @@ function getFileName(version, osPlatf, osArc) { } exports.getFileName = getFileName; // Retrieve a list of versions scraping tags from the Github API -function fetchVersions(includePreReleases, repoToken) { +function fetchVersions(version, includePreReleases, repoToken) { return __awaiter(this, void 0, void 0, function* () { let rest; if (repoToken != "") { @@ -186,17 +192,28 @@ function fetchVersions(includePreReleases, repoToken) { rest = new restm.RestClient("setup-protoc"); } let tags = []; - for (let pageNum = 1, morePages = true; morePages; pageNum++) { - const p = yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + - pageNum); - const nextPage = p.result || []; - if (nextPage.length > 0) { - tags = tags.concat(nextPage); - } - else { - morePages = false; + + if (version == "24" || version == "24.4" || version == "25.2" || version == "25" || version == "26.0") + { + //use cached response + console.log("Using version " + version + " (cached info without using github api)"); + return ["24.4","25.2","26.0"]; + } + else + { + for (let pageNum = 1, morePages = true; morePages; pageNum++) { + const p = yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" + + pageNum); + const nextPage = p.result || []; + if (nextPage.length > 0) { + tags = tags.concat(nextPage); + } + else { + morePages = false; + } } } + return tags .filter((tag) => tag.tag_name.match(/v\d+\.[\w.]+/g)) .filter((tag) => includePrerelease(tag.prerelease, includePreReleases)) @@ -214,7 +231,7 @@ function computeVersion(version, includePreReleases, repoToken) { if (version.endsWith(".x")) { version = version.slice(0, version.length - 2); } - const allVersions = yield fetchVersions(includePreReleases, repoToken); + const allVersions = yield fetchVersions(version, includePreReleases, repoToken); const validVersions = allVersions.filter((v) => v.match(semverRegex)); const possibleVersions = validVersions.filter((v) => v.startsWith(version)); const versionMap = new Map(); diff --git a/src/installer.ts b/src/installer.ts index 487238d8..83978449 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -66,7 +66,11 @@ export async function getProtoc( // expose outputs core.setOutput("path", toolPath); core.setOutput("version", targetVersion); - + if (process.platform === "win32") { + core.exportVariable("PROTOC", toolPath + "\\bin\\protoc.exe"); + } else { + core.exportVariable("PROTOC", toolPath + "/bin/protoc"); + } // add the bin folder to the PATH core.addPath(path.join(toolPath, "bin")); }