Skip to content

Commit d7e6e28

Browse files
committed
actions 2
1 parent 91b36bb commit d7e6e28

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# setup-protoc
1+
# setup-protoc-to-env
22

33
[![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)
44
![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:
2424

2525
```yaml
2626
- name: Install Protoc
27-
uses: arduino/setup-protoc@v3
27+
uses: actions-gw/setup-protoc-to-env@v3
2828
```
2929
3030
If you want to pin a major or minor version you can use the `.x` wildcard:
3131

3232
```yaml
3333
- name: Install Protoc
34-
uses: arduino/setup-protoc@v3
34+
uses: actions-gw/setup-protoc-to-env@v3
3535
with:
3636
version: "23.x"
3737
```
@@ -40,7 +40,7 @@ You can also require to include releases marked as `pre-release` in Github using
4040

4141
```yaml
4242
- name: Install Protoc
43-
uses: arduino/setup-protoc@v3
43+
uses: actions-gw/setup-protoc-to-env@v3
4444
with:
4545
version: "23.x"
4646
include-pre-releases: true
@@ -50,7 +50,7 @@ To pin the exact version:
5050

5151
```yaml
5252
- name: Install Protoc
53-
uses: arduino/setup-protoc@v3
53+
uses: actions-gw/setup-protoc-to-env@v3
5454
with:
5555
version: "23.2"
5656
```
@@ -60,7 +60,7 @@ pass the default token with the `repo-token` variable:
6060

6161
```yaml
6262
- name: Install Protoc
63-
uses: arduino/setup-protoc@v3
63+
uses: actions-gw/setup-protoc-to-env@v3
6464
with:
6565
repo-token: ${{ secrets.GITHUB_TOKEN }}
6666
```

action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 'Setup protoc'
2-
description: 'Download protoc compiler and add it to the PATH'
1+
name: 'Setup protoc to env'
2+
description: 'Download protoc compiler and add it to the PATH and PROTOC'
33
author: 'Arduino'
44
inputs:
55
version:

dist/index.js

+28-11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ function getProtoc(version, includePreReleases, repoToken) {
8888
// expose outputs
8989
core.setOutput("path", toolPath);
9090
core.setOutput("version", targetVersion);
91+
if (process.platform === "win32") {
92+
core.exportVariable("PROTOC", toolPath + "\\bin\\protoc.exe");
93+
}
94+
else {
95+
core.exportVariable("PROTOC", toolPath + "/bin/protoc");
96+
}
9197
// add the bin folder to the PATH
9298
core.addPath(path.join(toolPath, "bin"));
9399
});
@@ -174,7 +180,7 @@ function getFileName(version, osPlatf, osArc) {
174180
}
175181
exports.getFileName = getFileName;
176182
// Retrieve a list of versions scraping tags from the Github API
177-
function fetchVersions(includePreReleases, repoToken) {
183+
function fetchVersions(version, includePreReleases, repoToken) {
178184
return __awaiter(this, void 0, void 0, function* () {
179185
let rest;
180186
if (repoToken != "") {
@@ -186,17 +192,28 @@ function fetchVersions(includePreReleases, repoToken) {
186192
rest = new restm.RestClient("setup-protoc");
187193
}
188194
let tags = [];
189-
for (let pageNum = 1, morePages = true; morePages; pageNum++) {
190-
const p = yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
191-
pageNum);
192-
const nextPage = p.result || [];
193-
if (nextPage.length > 0) {
194-
tags = tags.concat(nextPage);
195-
}
196-
else {
197-
morePages = false;
195+
196+
if (version == "24" || version == "24.4" || version == "25.2" || version == "25" || version == "26.0")
197+
{
198+
//use cached response
199+
console.log("Using version " + version + " (cached info without using github api)");
200+
return ["24.4","25.2","26.0"];
201+
}
202+
else
203+
{
204+
for (let pageNum = 1, morePages = true; morePages; pageNum++) {
205+
const p = yield rest.get("https://api.github.com/repos/protocolbuffers/protobuf/releases?page=" +
206+
pageNum);
207+
const nextPage = p.result || [];
208+
if (nextPage.length > 0) {
209+
tags = tags.concat(nextPage);
210+
}
211+
else {
212+
morePages = false;
213+
}
198214
}
199215
}
216+
200217
return tags
201218
.filter((tag) => tag.tag_name.match(/v\d+\.[\w.]+/g))
202219
.filter((tag) => includePrerelease(tag.prerelease, includePreReleases))
@@ -214,7 +231,7 @@ function computeVersion(version, includePreReleases, repoToken) {
214231
if (version.endsWith(".x")) {
215232
version = version.slice(0, version.length - 2);
216233
}
217-
const allVersions = yield fetchVersions(includePreReleases, repoToken);
234+
const allVersions = yield fetchVersions(version, includePreReleases, repoToken);
218235
const validVersions = allVersions.filter((v) => v.match(semverRegex));
219236
const possibleVersions = validVersions.filter((v) => v.startsWith(version));
220237
const versionMap = new Map();

src/installer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ export async function getProtoc(
6666
// expose outputs
6767
core.setOutput("path", toolPath);
6868
core.setOutput("version", targetVersion);
69-
69+
if (process.platform === "win32") {
70+
core.exportVariable("PROTOC", toolPath + "\\bin\\protoc.exe");
71+
} else {
72+
core.exportVariable("PROTOC", toolPath + "/bin/protoc");
73+
}
7074
// add the bin folder to the PATH
7175
core.addPath(path.join(toolPath, "bin"));
7276
}

0 commit comments

Comments
 (0)