Skip to content

Commit 917bac4

Browse files
committed
Support inexact (prefix-based) version specifications
1 parent 2d611d0 commit 917bac4

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ jobs:
2020
- {shards: false}
2121
- {shards: true}
2222
- {shards: '0.12.0', crystal: '0.35.1'}
23+
- {shards: '0.14', crystal: '1.2'}
2324
- {shards: latest, crystal: latest}
2425
- {shards: nightly, crystal: nightly}
2526
exclude:
2627
- os: windows-latest
2728
config: {shards: '0.12.0', crystal: '0.35.1'}
29+
- os: windows-latest
30+
config: {shards: '0.14', crystal: '1.2'}
2831
- os: windows-latest
2932
config: {shards: latest, crystal: latest}
3033

@@ -51,11 +54,11 @@ jobs:
5154
ls '${{ steps.install.outputs.path }}/src/prelude.cr'
5255
- run: |
5356
v='${{ steps.install.outputs.crystal }}'
54-
crystal --version | grep "${v:0:9}"
57+
crystal --version | grep "${v:0:9}\\b"
5558
if: ${{ runner.os != 'Windows' }}
5659
- run: |
5760
v='${{ matrix.config.crystal }}'
58-
crystal --version | grep "$v"
61+
crystal --version | grep -E "${v}\\b"
5962
if: ${{ contains(matrix.config.crystal, '.') }}
6063
- run: |
6164
crystal eval 'require "yaml"; require "xml"; require "big"; require "openssl"'
@@ -66,11 +69,11 @@ jobs:
6669
- run: |
6770
v='${{ steps.install.outputs.shards }}'
6871
v="${v#v}"
69-
shards --version | grep "${v:0:9}"
72+
shards --version | grep -E "${v:0:9}\\b"
7073
if: ${{ !contains('true|false|nightly', matrix.config.shards) }}
7174
- run: |
7275
v='${{ matrix.config.shards }}'
73-
shards --version | grep "$v"
76+
shards --version | grep -E "${v}\\b"
7477
if: ${{ contains(matrix.config.shards, '.') }}
7578
- run: |
7679
! shards --version

.github/workflows/release.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ jobs:
2020
- {shards: false}
2121
- {shards: true}
2222
- {shards: '0.12.0', crystal: '0.35.1'}
23+
- {shards: '0.14', crystal: '1.2'}
2324
- {shards: latest, crystal: latest}
2425
- {shards: nightly, crystal: nightly}
2526
exclude:
2627
- os: windows-latest
2728
config: {shards: '0.12.0', crystal: '0.35.1'}
29+
- os: windows-latest
30+
config: {shards: '0.14', crystal: '1.2'}
2831
- os: windows-latest
2932
config: {shards: latest, crystal: latest}
3033

@@ -51,11 +54,11 @@ jobs:
5154
ls '${{ steps.install.outputs.path }}/src/prelude.cr'
5255
- run: |
5356
v='${{ steps.install.outputs.crystal }}'
54-
crystal --version | grep "${v:0:9}"
57+
crystal --version | grep "${v:0:9}\\b"
5558
if: ${{ runner.os != 'Windows' }}
5659
- run: |
5760
v='${{ matrix.config.crystal }}'
58-
crystal --version | grep "$v"
61+
crystal --version | grep -E "${v}\\b"
5962
if: ${{ contains(matrix.config.crystal, '.') }}
6063
- run: |
6164
crystal eval 'require "yaml"; require "xml"; require "big"; require "openssl"'
@@ -66,11 +69,11 @@ jobs:
6669
- run: |
6770
v='${{ steps.install.outputs.shards }}'
6871
v="${v#v}"
69-
shards --version | grep "${v:0:9}"
72+
shards --version | grep -E "${v:0:9}\\b"
7073
if: ${{ !contains('true|false|nightly', matrix.config.shards) }}
7174
- run: |
7275
v='${{ matrix.config.shards }}'
73-
shards --version | grep "$v"
76+
shards --version | grep -E "${v}\\b"
7477
if: ${{ contains(matrix.config.shards, '.') }}
7578
- run: |
7679
! shards --version

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ steps:
2222
- uses: actions/checkout@v2
2323
- uses: crystal-lang/install-crystal@v1
2424
with:
25-
crystal: 0.35.1
25+
crystal: 1.2
2626
- run: shards install
2727
- run: crystal spec
2828
```
@@ -56,9 +56,9 @@ Alternatively, you can use the container-based approach [as in the starter workf
5656
5757
### Inputs
5858
59-
* * **`crystal: 0.35.1`** (not supported on Windows)
59+
* * **`crystal: 1.1.0`**, **`crystal: 1.2`** (not supported on Windows)
6060

61-
Install a particular release of Crystal.
61+
Install a particular release of Crystal (if the full version is specified), or the latest patch version of a release series.
6262

6363
* **`crystal: latest`** (default; not supported on Windows)
6464

@@ -81,9 +81,9 @@ Alternatively, you can use the container-based approach [as in the starter workf
8181

8282
Build and install the latest released version of Shards.
8383

84-
* **`shards: 0.13.0`**
84+
* **`shards: 0.14.0`**, **`shards: 0.16`**
8585

86-
Build and install a particular release of Shards.
86+
Build and install a particular release of Shards (if the full version is specified), or the latest patch version of a release series.
8787

8888
* **`shards: nightly`**
8989

docs/configurator.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- os: ubuntu-latest
5757
{%- if crystal_ver %}
5858
- os: ubuntu-latest
59-
crystal: 1.0.0
59+
crystal: 1.2
6060
{%- endif %}
6161
{%- if crystal_nightly %}
6262
- os: ubuntu-latest
@@ -73,7 +73,7 @@ jobs:
7373
os: [ubuntu-latest{% if os_mac %}, macos-latest{% endif %}{% if os_win %}, windows-latest{% endif %}]
7474
{%- endif %}
7575
{%- if crystal_nightly or crystal_ver %}
76-
crystal: [{% if crystal_ver %}1.0.0, {% endif %}latest{% if crystal_nightly %}, nightly{% endif %}]
76+
crystal: [{% if crystal_ver %}1.2, {% endif %}latest{% if crystal_nightly %}, nightly{% endif %}]
7777
{%- endif %}
7878
{%- endif %}
7979
{%- endif %}

index.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const Latest = "latest";
8787
const Nightly = "nightly";
8888
const Any = "true";
8989
const None = "false";
90-
const NumericVersion = /^\d[.\d]+\d$/;
90+
const NumericVersion = /^\d([.\d]*\d)?$/;
9191

9292
function checkVersion(version, allowed) {
9393
const numericVersion = NumericVersion.test(version) && version;
@@ -272,15 +272,45 @@ const RepoShards = {owner: "crystal-lang", repo: "shards"};
272272
const CircleApiBase = "https://circleci.com/api/v1.1/project/github/crystal-lang/crystal";
273273

274274
async function findRelease({name, repo, tag}) {
275-
Core.info(`Looking for ${name} release (${tag || "latest"})`);
276-
const releasesResp = await (tag
277-
? github.rest.repos.getReleaseByTag({...repo, tag})
278-
: github.rest.repos.getLatestRelease(repo));
275+
if (!(/^\d+\.\d+\.\d\w*$/.test(tag))) {
276+
tag = await getLatestTag({repo, prefix: tag});
277+
}
278+
Core.info(`Getting ${name} release (${tag})`);
279+
const releasesResp = await github.rest.repos.getReleaseByTag({...repo, tag});
279280
const release = releasesResp.data;
280281
Core.info(`Found ${name} release ${release["html_url"]}`);
281282
return release;
282283
}
283284

285+
async function getLatestTag({repo, prefix}) {
286+
Core.info(`Looking for ${repo.owner}/${repo.owner} release (${prefix || "latest"})`);
287+
const pages = github.repos.listReleases.endpoint.merge({
288+
...repo, "per_page": 50,
289+
});
290+
291+
const tags = [];
292+
let assurance = 25;
293+
for await (const item of getItemsFromPages(pages)) {
294+
const tag = item["tag_name"];
295+
if (!prefix || tag === prefix || tag.startsWith(prefix + ".")) {
296+
tags.push(tag);
297+
}
298+
if (tags.length) {
299+
if (--assurance <= 0) {
300+
break;
301+
}
302+
}
303+
}
304+
if (tags.length === 0) {
305+
let error = `The repository "${repo.owner}/${repo.repo}" has no releases matching "${prefix}.*"`;
306+
throw error;
307+
}
308+
tags.sort(cmpTags);
309+
tags.reverse();
310+
Core.debug(`Considered tags ${tags.join("|")}`);
311+
return tags[0];
312+
}
313+
284314
async function findLatestCommit({name, repo, branch = "master"}) {
285315
Core.info(`Looking for latest ${name} commit`);
286316
const commitsResp = await github.rest.repos.getCommit({
@@ -312,11 +342,14 @@ async function downloadCrystalRelease(suffix, version = null) {
312342
}
313343

314344
async function findRef({name, repo, version}) {
345+
const v = version.replace(/^v/, "");
315346
if (version === Nightly) {
316347
return findLatestCommit({name, repo});
317348
} else if (version === Latest) {
318349
const release = await findRelease({name, repo});
319350
return release["tag_name"];
351+
} else if (NumericVersion.test(v) && !(/^\d+\.\d+\.\d\w*$/.test(v))) {
352+
return getLatestTag({repo, prefix: version});
320353
}
321354
return version;
322355
}

0 commit comments

Comments
 (0)