Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Create Project.toml
- name: Create Project.toml and Manifest.toml
shell: bash
run: |
echo -e '[compat]\njulia = "1.6"' >Project.toml
echo -e '[compat]\njulia = "1.7"' >Project.toml
echo -e 'julia_version = "1.7.3"' >Manifest.toml

- name: Test julia-version
id: julia-version
uses: ./
with:
versions: |
- min
- manifest
- lts
- 1
- ~1.10
Expand All @@ -63,10 +65,11 @@ jobs:
shell: bash
run: |
set -x
[[ "$(jq -r 'length' <<<"$unique_json")" -eq 3 ]] || exit 1
[[ "$(jq -r '.[0]' <<<"$unique_json")" == "1.6.0" ]] || exit 1
[[ "$(jq -r '.[1]' <<<"$unique_json")" =~ ^1\.10\.([8-9]|[1-9][0-9]*)$ ]] || exit 1 # [1.10.8, 1.11.0)
[[ "$(jq -r '.[2]' <<<"$unique_json")" =~ ^1\.(1[1-9]|2[0-9]+)\.[0-9]+$ ]] || exit 1 # [1.11.0, ∞)
[[ "$(jq -r 'length' <<<"$unique_json")" -eq 4 ]] || exit 1
[[ "$(jq -r '.[0]' <<<"$unique_json")" == "1.7.0" ]] || exit 1
[[ "$(jq -r '.[1]' <<<"$unique_json")" == "1.7.3" ]] || exit 1
[[ "$(jq -r '.[2]' <<<"$unique_json")" =~ ^1\.10\.(9|[1-9][0-9]*)$ ]] || exit 1 # [1.10.9, 1.11.0)
[[ "$(jq -r '.[3]' <<<"$unique_json")" =~ ^1\.(1[1-9]|2[0-9]+)\.[0-9]+$ ]] || exit 1 # [1.11.0, ∞)

[[ "$version" == "" ]] || exit 1
env:
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ Resolves to the lowest Julia version compatible with the Julia project. Using
this alias requires that the `project` input refers to a directory containing a
`Project.toml` (or `JuliaProject.toml`) and a `julia` compat entry exist.

### `manifest` Alias

Resolves to the Julia version as specified in the Julia manifest file. Using
this alias requires that the `project` input refers to a directory containing a
`Manifest.toml` (or `JuliaManifest.toml`).

### Grammar

Here is the complete Backus-Naur grammar for a version specifier:
Expand All @@ -177,7 +183,7 @@ Here is the complete Backus-Naur grammar for a version specifier:
<caret> ::= "^" <partial>
<partial> ::= <n> | <n> "." <n> | <n> "." <n> "." <n>
<nightly> ::= <n> "." <n> "-nightly" | "nightly"
<alias> ::= "lts" | "min"
<alias> ::= "lts" | "min" | "manifest"
<n> ::= "0" | <positive> <digits>
<digits> ::= <digit> | <digit> <digits>
<digit> ::= "0" | <positive>
Expand Down
14 changes: 14 additions & 0 deletions __fixtures__/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ export const versionsJsonFile = path.join(
"versions.json"
)

export const projectDirV1 = path.join(
__dirname,
"..",
"__fixtures__",
"julia-manifest-v1"
)

export const projectDirV2 = path.join(
__dirname,
"..",
"__fixtures__",
"julia-manifest-v2"
)

export const testVersions = Object.keys(
JSON.parse(fs.readFileSync(versionsJsonFile).toString())
)
6 changes: 6 additions & 0 deletions __fixtures__/julia-manifest-v1/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file is machine-generated - editing it directly is not advised

[[Example]]
git-tree-sha1 = "e1f0e1a832ccd8e97d6d0348dec33ee139a5aeaf"
uuid = "7876af07-990d-54b4-ab0e-23690620f79a"
version = "0.5.5"
6 changes: 6 additions & 0 deletions __fixtures__/julia-manifest-v1/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[deps]
Example = "7876af07-990d-54b4-ab0e-23690620f79a"

[compat]
Example = "0.5"
julia = "~1.3, ~1.4, ~1.5, ~1.6"
10 changes: 10 additions & 0 deletions __fixtures__/julia-manifest-v2/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.11.4"
manifest_format = "2.0"
project_hash = "ae137bb0503e2e53b12ee5d9b6701e2c1539a0cf"

[[deps.Example]]
git-tree-sha1 = "e1f0e1a832ccd8e97d6d0348dec33ee139a5aeaf"
uuid = "7876af07-990d-54b4-ab0e-23690620f79a"
version = "0.5.5"
6 changes: 6 additions & 0 deletions __fixtures__/julia-manifest-v2/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[deps]
Example = "7876af07-990d-54b4-ab0e-23690620f79a"

[compat]
Example = "0.5"
julia = "1.7"
514 changes: 440 additions & 74 deletions __fixtures__/versions.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions __tests__/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("parseVersionSpecifiers", () => {
it("Handle alias scalar", () => {
expect(parseVersionSpecifiers("lts")).toEqual(["lts"])
expect(parseVersionSpecifiers("min")).toEqual(["min"])
expect(parseVersionSpecifiers("manifest")).toEqual(["manifest"])

expect(() => parseVersionSpecifiers("pre")).toThrow(
"Invalid version specifier"
Expand Down
59 changes: 57 additions & 2 deletions __tests__/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { tmpdir } from "node:os"
import {
getJuliaCompatRange,
getJuliaProjectFile,
getJuliaManifestFile,
validJuliaCompatRange,
} from "../src/project.js"

Expand All @@ -26,10 +27,10 @@ describe("getJuliaProjectFile tests", () => {

it("Can determine project file is missing", () => {
expect(() => getJuliaProjectFile("DNE.toml")).toThrow(
"Unable to locate project file"
"Unable to locate Julia project file"
)
expect(() => getJuliaProjectFile(".")).toThrow(
"Unable to locate project file"
"Unable to locate Julia project file"
)
})

Expand Down Expand Up @@ -70,6 +71,60 @@ describe("getJuliaProjectFile tests", () => {
})
})

describe("getJuliaManifestFile tests", () => {
let orgWorkingDir: string

beforeEach(() => {
orgWorkingDir = process.cwd()
})

afterEach(() => {
process.chdir(orgWorkingDir)
})

it("Can determine manifest file is missing", () => {
expect(() => getJuliaManifestFile(".")).toThrow(
"Unable to locate Julia manifest file"
)
})

it("Can determine project file from a directory", () => {
fs.mkdtemp(path.join(tmpdir(), "julia-version-"), (err, projectDir) => {
const manifestFile = path.join(projectDir, "Manifest.toml")
fs.closeSync(fs.openSync(manifestFile, "w"))
expect(getJuliaManifestFile(projectDir)).toEqual(manifestFile)
})

fs.mkdtemp(path.join(tmpdir(), "julia-version-"), (err, projectDir) => {
const manifestFile = path.join(projectDir, "JuliaManifest.toml")
fs.closeSync(fs.openSync(manifestFile, "w"))
expect(getJuliaManifestFile(projectDir)).toEqual(manifestFile)
})
})

it("Prefers using JuliaManifest.toml over Manifest.toml", () => {
fs.mkdtemp(path.join(tmpdir(), "julia-version-"), (err, projectDir) => {
const manifestFile = path.join(projectDir, "Manifest.toml")
fs.closeSync(fs.openSync(manifestFile, "w"))

const juliaManifestFile = path.join(projectDir, "JuliaManifest.toml")
fs.closeSync(fs.openSync(juliaManifestFile, "w"))

expect(getJuliaManifestFile(projectDir)).toEqual(juliaManifestFile)
})
})

it("Can determine project from the current working directory", () => {
fs.mkdtemp(path.join(tmpdir(), "julia-version-"), (err, projectDir) => {
const projectFile = path.join(projectDir, "Manifest.toml")
fs.closeSync(fs.openSync(projectFile, "w"))

process.chdir(projectDir)
expect(getJuliaManifestFile(".")).toEqual("Manifest.toml")
})
})
})

describe("validJuliaCompatRange tests", () => {
it("Handles default caret specifier", () => {
expect(validJuliaCompatRange("1")).toEqual(semver.validRange("^1"))
Expand Down
35 changes: 32 additions & 3 deletions __tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import semver from "semver"

import * as core from "../__fixtures__/core.js"
import { testVersions, versionsJsonFile } from "../__fixtures__/constants.js"
import {
testVersions,
versionsJsonFile,
projectDirV1,
projectDirV2,
} from "../__fixtures__/constants.js"

// Mocks should be declared before the module being tested is imported.
jest.unstable_mockModule("@actions/core", () => core)
Expand Down Expand Up @@ -67,6 +72,18 @@
])
})

it("Handles alias: manifest", async () => {
await expect(resolveVersions(["manifest"], projectDirV2)).resolves.toEqual([
"1.11.4",
])
await expect(resolveVersions(["manifest"], projectDirV1)).rejects.toThrow(
"No Julia version exists matching specifier"
)
await expect(resolveVersions(["manifest"], ".")).rejects.toThrow(
"Unable to locate Julia manifest file"
)
})

it("Respects ifMissing error", async () => {
await expect(
resolveVersions(["1.9-nightly"], ".", { ifMissing: "error" })
Expand All @@ -90,8 +107,8 @@

describe("resolveVersion tests", () => {
// Will need to update these values if `__fixtures__/versions.json` is updated.
const latestRelease = "1.11.3"
const latestLts = "1.10.8"
const latestRelease = "1.11.4"
const latestLts = "1.10.9"

describe("specific versions", () => {
it("Must return an available version", () => {
Expand Down Expand Up @@ -124,6 +141,18 @@
it("version alias: lts", () => {
expect(resolveVersion("lts", testVersions)).toEqual(latestLts)
})

it("version alias: manifest", () => {
expect(resolveVersion("manifest", testVersions)).toBeNull()
expect(resolveVersion("manifest", testVersions, null, "1.11.3")).toEqual(
"1.11.3"
)

// An unofficial build of say `1.12.0-DEV.850` is recorded as `1.12.0-DEV` in the manifest
expect(
resolveVersion("manifest", testVersions, null, "1.12.0-DEV")
).toEqual("1.12.0-DEV")
})
})

describe("version ranges", () => {
Expand All @@ -136,7 +165,7 @@
})

// https://github.com/julia-actions/julia-version/issues/5
it.skip.failing("prereleases", () => {

Check warning on line 168 in __tests__/version.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Disabled test
expect(resolveVersion("~1.1-", ["1.0.0", "1.1.0-rc1"])).toEqual(
"1.1.0-rc1"
)
Expand All @@ -160,7 +189,7 @@

describe("node-semver behavior", () => {
describe("Windows installer change", () => {
it.skip.failing("Correctly understands >1.4.0", () => {

Check warning on line 192 in __tests__/version.test.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

Disabled test
const options = { includePrerelease: true }
expect(semver.gtr("1.4.0-rc1", "1.3", options)).toBeTruthy()
expect(semver.gtr("1.4.0-DEV", "1.3", options)).toBeTruthy()
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 46 additions & 6 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading