Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support 1.n.x and 1.x version format #38 #39

Merged
merged 55 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2e64c72
add empty functions
jiro4989 Jan 5, 2021
0342590
fix
jiro4989 Jan 5, 2021
94d7560
install compare-versions
jiro4989 Jan 5, 2021
902e49b
install node-fetch
jiro4989 Jan 5, 2021
b6c4261
wip
jiro4989 Jan 5, 2021
ec8582f
wip
jiro4989 Jan 5, 2021
214eb1c
wip
jiro4989 Jan 5, 2021
df9bf74
add test code
jiro4989 Jan 5, 2021
36e6eee
wip
jiro4989 Jan 5, 2021
6e2ac3d
wip
jiro4989 Jan 6, 2021
75ee0bf
wip
jiro4989 Jan 6, 2021
c7394ba
remove node-fetch
jiro4989 Jan 6, 2021
3d4e454
implements patch version
jiro4989 Jan 6, 2021
137a7e2
format
jiro4989 Jan 6, 2021
62fb9e5
tsc
jiro4989 Jan 6, 2021
5c652f3
add typescript test job
jiro4989 Jan 6, 2021
1587946
add 'v' prefix
jiro4989 Jan 6, 2021
3f02bdf
format
jiro4989 Jan 6, 2021
3d912fd
tsc
jiro4989 Jan 6, 2021
8b01250
add test case
jiro4989 Jan 6, 2021
18242fa
format
jiro4989 Jan 6, 2021
f7d8c39
implements minor version
jiro4989 Jan 6, 2021
73980d0
add test case
jiro4989 Jan 6, 2021
d36caac
tsc
jiro4989 Jan 6, 2021
ba3924e
update validations
jiro4989 Jan 6, 2021
6158537
format
jiro4989 Jan 6, 2021
4fd7340
add test case
jiro4989 Jan 6, 2021
f2d2f47
tsc
jiro4989 Jan 6, 2021
c242f36
update test case
jiro4989 Jan 6, 2021
7c7162a
add export
jiro4989 Jan 6, 2021
df5d1d7
add test case
jiro4989 Jan 6, 2021
e8b5b9f
tsc
jiro4989 Jan 6, 2021
34a036a
update test description
jiro4989 Jan 6, 2021
e5b0f54
update test code position
jiro4989 Jan 6, 2021
5037d4d
format
jiro4989 Jan 6, 2021
a336ef0
add match version functions
jiro4989 Jan 7, 2021
2b645da
format
jiro4989 Jan 7, 2021
02b1d56
tsc
jiro4989 Jan 7, 2021
928563e
add test cases
jiro4989 Jan 7, 2021
cf6ebc3
implements glob
jiro4989 Jan 7, 2021
24ced8d
tsc
jiro4989 Jan 7, 2021
f145efd
add test case
jiro4989 Jan 7, 2021
212eda7
add info message
jiro4989 Jan 7, 2021
4db97ef
tsc
jiro4989 Jan 7, 2021
a4db434
add request header
jiro4989 Jan 7, 2021
b241762
format
jiro4989 Jan 7, 2021
8c9173e
tscv
jiro4989 Jan 7, 2021
bdeff6f
fix code
jiro4989 Jan 7, 2021
32586e3
format
jiro4989 Jan 7, 2021
9cc0c80
tsc
jiro4989 Jan 7, 2021
bd8023a
fix
jiro4989 Jan 7, 2021
d0d38de
tsc
jiro4989 Jan 7, 2021
5c5a022
fix
jiro4989 Jan 7, 2021
16bb1f2
format
jiro4989 Jan 7, 2021
d0551ad
tsc
jiro4989 Jan 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ jobs:
steps:
- run: echo "not contains '[skip ci]'"

test-typescript:
runs-on: ubuntu-latest
needs: before
steps:
- uses: actions/checkout@v2
- name: Run test
run: npm test

test:
runs-on: ${{ matrix.os }}
needs: before
Expand Down Expand Up @@ -53,6 +61,29 @@ jobs:
- name: Run command
run: nimjson -h

test-glob-version:
runs-on: ubuntu-latest
needs: before
strategy:
matrix:
version:
- 1.2.x
- 1.x
steps:
- uses: actions/checkout@v2
- uses: ./
with:
nim-version: ${{ matrix.version }}

- name: Print Nim version
run: nim -v
- name: Print Nimble version
run: nimble -v
- name: Run build test
run: nimble install -Y nimjson
- name: Run command
run: nimjson -h

test_v1:
runs-on: ubuntu-latest
needs: before
Expand Down
6 changes: 6 additions & 0 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const fs = __importStar(require("fs"));
const process = __importStar(require("process"));
const path = __importStar(require("path"));
const proc = __importStar(require("child_process"));
const util = __importStar(require("./util"));
const request = require("request-promise");
function getNim(version, noColor, yes) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -69,6 +70,11 @@ function installNim(version, noColor, yes) {
});
fs.writeFileSync("init.sh", body);
process.env.CHOOSENIM_NO_ANALYTICS = "1";
// #38
if (util.isGlobPatchVersion(version) || util.isGlobMinorVersion(version)) {
core.info(`Fetch a latest versions with ${version}`);
version = yield util.getLatestVersion(version);
}
// #21
if (process.platform === "win32") {
process.env.CHOOSENIM_CHOOSE_VERSION = version;
Expand Down
91 changes: 91 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLatestVersion = exports.getLatestVersionWithTags = exports.fetchTagList = exports.isGlobMinorVersion = exports.isGlobPatchVersion = void 0;
const request = require("request-promise");
const compare_versions_1 = __importDefault(require("compare-versions"));
const patchVersionPattern = /^\d+\.\d+\.x$/;
function isGlobPatchVersion(version) {
return version.match(patchVersionPattern) != null;
}
exports.isGlobPatchVersion = isGlobPatchVersion;
const minorVersionPattern = /^\d+\.x$/;
function isGlobMinorVersion(version) {
return version.match(minorVersionPattern) != null;
}
exports.isGlobMinorVersion = isGlobMinorVersion;
/**
* fetchTagList returns Nim version tag list.
*/
function fetchTagList() {
const tagURL = "https://api.github.com/repos/nim-lang/Nim/tags";
return request({
url: tagURL,
method: "GET",
headers: {
"User-Agent": "setup-nim-action",
},
json: true,
}).then((obj) => {
return obj.map((v) => v.name);
});
}
exports.fetchTagList = fetchTagList;
/**
* getLatestVersionWithTags returns a latest version of `1.n.x`.
*/
function getLatestVersionWithTags(version, tags) {
const patchVersionPattern = /^\d+\.\d+\.x$/;
const minorVersionPattern = /^\d+\.x$/;
if (!isGlobPatchVersion(version) && !isGlobMinorVersion(version)) {
return "";
}
if (tags === null || tags === undefined || tags.length < 1) {
return version;
}
// patch version
// ex: 1.2.x
if (isGlobPatchVersion(version)) {
const versionPrefix = version.replace(/^(\d+\.\d+)\..*/, "$1");
const versionCols = versionPrefix.split(".");
const majorVersion = versionCols[0];
const minorVersion = versionCols[1];
const pattern = new RegExp(`^v${majorVersion}\\.${minorVersion}\\.\\d+`);
const sorted = tags
.filter((tag) => tag.match(pattern))
.map((tag) => tag.substring(1))
.sort(compare_versions_1.default);
if (sorted.length < 1) {
return "";
}
return sorted[sorted.length - 1];
}
// minor version
// ex: 1.x
if (isGlobMinorVersion(version)) {
const versionPrefix = version.replace(/^(\d+)\..*/, "$1");
const versionCols = versionPrefix.split(".");
const majorVersion = versionCols[0];
const pattern = new RegExp(`^v${majorVersion}\\.\\d+`);
const sorted = tags
.filter((tag) => tag.match(pattern))
.map((tag) => tag.substring(1))
.sort(compare_versions_1.default);
if (sorted.length < 1) {
return "";
}
return sorted[sorted.length - 1];
}
// not arrive
return "";
}
exports.getLatestVersionWithTags = getLatestVersionWithTags;
/**
* getLatestVersion returns a latest version of `1.n.x`.
*/
function getLatestVersion(version) {
return fetchTagList().then((tags) => getLatestVersionWithTags(version, tags));
}
exports.getLatestVersion = getLatestVersion;
70 changes: 48 additions & 22 deletions node_modules/@actions/core/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 47 additions & 22 deletions node_modules/@actions/exec/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading