diff --git a/README.md b/README.md index 9c825ee..613e788 100644 --- a/README.md +++ b/README.md @@ -104,15 +104,42 @@ You can either specify specific Julia versions or version ranges. If you specify - `1.2.0` is a valid semver version. The action will try to download exactly this version. If it's not available, the build step will fail. - `1.0` is a version range that will match the highest available Julia version that starts with `1.0`, e.g. `1.0.5`, excluding pre-releases. -- `^1.3.0-rc1` is a **caret** version range that includes pre-releases starting at `rc1`. It matches all versions `≥ 1.3.0-rc1` and `< 2.0.0`. -- `~1.3.0-rc1` is a **tilde** version range that includes pre-releases starting at `rc1`. It matches all versions `≥ 1.3.0-rc1` and `< 1.4.0`. -- `^1.3.0-0` is a **caret** version range that includes _all_ pre-releases. It matches all versions `≥ 1.3.0-` and `< 2.0.0`. -- `~1.3.0-0` is a **tilde** version range that includes _all_ pre-releases. It matches all versions `≥ 1.3.0-` and `< 1.4.0`. +- `^1.3.0-rc1` is a **caret** version range that includes pre-releases of `1.3.0` starting at `rc1`. It matches all versions `≥ 1.3.0-rc1` and `< 2.0.0`. +- `~1.3.0-rc1` is a **tilde** version range that includes pre-releases of `1.3.0` starting at `rc1`. It matches all versions `≥ 1.3.0-rc1` and `< 1.4.0`. +- `^1.3.0-0` is a **caret** version range that includes _all_ pre-releases of `1.3.0`. It matches all versions `≥ 1.3.0-` and `< 2.0.0`. +- `~1.3.0-0` is a **tilde** version range that includes _all_ pre-releases of `1.3.0`. It matches all versions `≥ 1.3.0-` and `< 1.4.0`. - `nightly` will install the latest nightly build. - `1.7-nightly` will install the latest nightly build for the upcoming 1.7 release. This version will only be available during certain phases of the Julia release cycle. Internally the action uses node's semver package to resolve version ranges. Its [documentation](https://github.com/npm/node-semver#advanced-range-syntax) contains more details on the version range syntax. You can test what version will be selected for a given input in this JavaScript [REPL](https://repl.it/@SaschaMann/setup-julia-version-logic). +#### Prereleases + +There are two methods of including pre-releases in version matching: + +1. Including the pre-release tag in the version itself, e.g. `^1.3.0-rc1`. +2. Setting the input `include-all-prereleases` to `true`. + +These behave slightly differently. + +1. If the version `a.b.c` contains pre-release tag, all pre-releases of version `a.b.c` will be included in the version matching. +For example, `^1.3.0-rc1` would match `1.3.0-rc2` but would **not** match `1.4.0-rc1` once released. +2. If `include-preleases` is set to true, **all** pre-releases of all versions will be included in the version matching. In this case, `^1.3.0-rc1` would match `1.4.0-rc1` once released. + +**Example:** Without `include-all-prereleases: true`, the version `^1.3.0-rc1` would match `1.3.0-rc1`, `1.3.0-rc2`, `1.3.0`, `1.4.0` once they are released. +With `include-all-prereleases: true`, it would match `1.3.0-rc1`, `1.3.0-rc2`, `1.3.0`, `1.4.0-rc1`, `1.4.0`. + +If you want to run tests against the latest tagged version, no matter what version that is, you can use + +```yaml +- uses: julia-actions/setup-julia@v1 + with: + version: '1' + include-all-prereleases: true +``` + +#### Recently released versions + The available Julia versions are pulled from [`versions.json`](https://julialang-s3.julialang.org/bin/versions.json). This file is automatically updated once a day. Therefore it may take up to 24 hours until a newly released Julia version is available in the action. ### Matrix Testing diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 3a23c92..64d0e6b 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -66,6 +66,14 @@ describe('version matching tests', () => { }) }) + describe('include-prereleases', () => { + it('Chooses the highest available version that matches the input including prereleases', () => { + expect(installer.getJuliaVersion(testVersions, '^1.2.0-0', true)).toEqual('1.3.0-rc4') + expect(installer.getJuliaVersion(testVersions, '1', true)).toEqual('1.3.0-rc4') + expect(installer.getJuliaVersion(testVersions, '^1.2.0-0', false)).toEqual('1.2.0') + }) + }) + describe('node-semver behaviour', () => { describe('Windows installer change', () => { it('Correctly understands >1.4.0', () => { diff --git a/action.yml b/action.yml index 79105dd..f961da7 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,10 @@ inputs: version: description: 'The Julia version to download (if necessary) and use. Example: 1.0.4' default: '1' + include-all-prereleases: + description: 'Include prereleases when matching the Julia version to available versions.' + required: false + default: 'false' arch: description: 'Architecture of the Julia binaries. Defaults to the architecture of the runner executing the job.' required: false diff --git a/lib/installer.js b/lib/installer.js index 6b2a9d4..3996a42 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -87,13 +87,13 @@ function getJuliaVersions(versionInfo) { }); } exports.getJuliaVersions = getJuliaVersions; -function getJuliaVersion(availableReleases, versionInput) { +function getJuliaVersion(availableReleases, versionInput, includePrerelease = false) { if (semver.valid(versionInput) == versionInput || versionInput.endsWith('nightly')) { // versionInput is a valid version or a nightly version, use it directly return versionInput; } // Use the highest available version that matches versionInput - let version = semver.maxSatisfying(availableReleases, versionInput); + let version = semver.maxSatisfying(availableReleases, versionInput, { includePrerelease }); if (version == null) { throw new Error(`Could not find a Julia version that matches ${versionInput}`); } diff --git a/lib/setup-julia.js b/lib/setup-julia.js index e83f709..98680e7 100644 --- a/lib/setup-julia.js +++ b/lib/setup-julia.js @@ -49,6 +49,7 @@ function run() { } // Inputs const versionInput = core.getInput('version'); + const includePrereleases = core.getInput('include-all-prereleases') == 'true'; const originalArchInput = core.getInput('arch'); // It can easily happen that, for example, a workflow file contains an input `version: ${{ matrix.julia-version }}` // while the strategy matrix only contains a key `${{ matrix.version }}`. @@ -64,7 +65,7 @@ function run() { const arch = archSynonyms[originalArchInput]; const versionInfo = yield installer.getJuliaVersionInfo(); const availableReleases = yield installer.getJuliaVersions(versionInfo); - const version = installer.getJuliaVersion(availableReleases, versionInput); + const version = installer.getJuliaVersion(availableReleases, versionInput, includePrereleases); core.debug(`selected Julia version: ${arch}/${version}`); core.setOutput('julia-version', version); // Search in cache diff --git a/src/installer.ts b/src/installer.ts index 9307706..af402b3 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -75,14 +75,14 @@ export async function getJuliaVersions(versionInfo): Promise { return versions } -export function getJuliaVersion(availableReleases: string[], versionInput: string): string { +export function getJuliaVersion(availableReleases: string[], versionInput: string, includePrerelease: boolean = false): string { if (semver.valid(versionInput) == versionInput || versionInput.endsWith('nightly')) { // versionInput is a valid version or a nightly version, use it directly return versionInput } // Use the highest available version that matches versionInput - let version = semver.maxSatisfying(availableReleases, versionInput) + let version = semver.maxSatisfying(availableReleases, versionInput, {includePrerelease}) if (version == null) { throw new Error(`Could not find a Julia version that matches ${versionInput}`) } diff --git a/src/setup-julia.ts b/src/setup-julia.ts index d27d991..e91bd0e 100644 --- a/src/setup-julia.ts +++ b/src/setup-julia.ts @@ -39,6 +39,7 @@ async function run() { // Inputs const versionInput = core.getInput('version') + const includePrereleases = core.getInput('include-all-prereleases') == 'true' const originalArchInput = core.getInput('arch') // It can easily happen that, for example, a workflow file contains an input `version: ${{ matrix.julia-version }}` @@ -57,7 +58,7 @@ async function run() { const versionInfo = await installer.getJuliaVersionInfo() const availableReleases = await installer.getJuliaVersions(versionInfo) - const version = installer.getJuliaVersion(availableReleases, versionInput) + const version = installer.getJuliaVersion(availableReleases, versionInput, includePrereleases) core.debug(`selected Julia version: ${arch}/${version}`) core.setOutput('julia-version', version)