From 355fe3a07024485c250675653a9a0710bc222ef7 Mon Sep 17 00:00:00 2001 From: Jesse Dijkstra Date: Thu, 11 Apr 2024 14:15:36 +0200 Subject: [PATCH 01/16] Add .tool-versions and .dvmrc support --- README.md | 14 ++++++++++++++ action.yml | 2 ++ main.js | 18 +++++++++++++----- src/version.js | 28 +++++++++++++++++++++++++--- 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4d9a6048..915c375a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,20 @@ Set up your GitHub Actions workflow with a specific version of Deno. ## Usage +### Version from file + +```yaml +- uses: denoland/setup-deno@v1 + with: + deno-version-file: .dvmrc +``` + +```yaml +- uses: denoland/setup-deno@v1 + with: + deno-version-file: .tool-versions +``` + ### Latest stable for a major ```yaml diff --git a/action.yml b/action.yml index dd4bef05..c89bd9ba 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,8 @@ inputs: deno-version: description: The Deno version to install. Can be a semver version of a stable release, "canary" for the latest canary, or the Git hash of a specific canary release. default: "1.x" + deno-version-file: + description: File containing the Deno version to install such as .dvmrc or .tool-versions. Overridden by deno-version. outputs: deno-version: description: "The Deno version that was installed." diff --git a/main.js b/main.js index 9242d7da..08ceb39c 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,11 @@ const process = require("process"); const core = require("@actions/core"); -const { parseVersionRange, resolveVersion } = require("./src/version.js"); +const { + parseVersionRange, + getDenoVersionFromFile, + resolveVersion, +} = require("./src/version.js"); const { install } = require("./src/install.js"); /** @@ -15,7 +19,11 @@ function exit(message) { async function main() { try { - const range = parseVersionRange(core.getInput("deno-version")); + const denoVersionFile = core.getInput("deno-version-file"); + const range = parseVersionRange( + core.getInput("deno-version") || getDenoVersionFromFile(denoVersionFile) + ); + if (range === null) { exit("The passed version range is not valid."); } @@ -26,9 +34,9 @@ async function main() { } core.info( - `Going to install ${ - version.isCanary ? "canary" : "stable" - } version ${version.version}.`, + `Going to install ${version.isCanary ? "canary" : "stable"} version ${ + version.version + }.` ); await install(version); diff --git a/src/version.js b/src/version.js index f053db00..7748ce6a 100644 --- a/src/version.js +++ b/src/version.js @@ -1,5 +1,6 @@ const semver = require("semver"); const { fetch } = require("undici"); +const fs = require("fs"); const GIT_HASH_RE = /^[0-9a-fA-F]{40}$/; @@ -41,6 +42,26 @@ function parseVersionRange(version) { return null; } +/** + * Parses the version from the version file + * + * @param {string} versionFilePath + * @returns {string | undefined} + */ +function getDenoVersionFromFile(versionFilePath) { + if (!fs.existsSync(versionFilePath)) { + throw new Error( + `The specified node version file at: ${versionFilePath} does not exist` + ); + } + + const contents = fs.readFileSync(versionFilePath, "utf8"); + + const found = contents.match(/^(?:deno?\s+)?v?(?[^\s]+)$/m); + + return (found && found.groups && found.groups.version) || contents.trim(); +} + /** * @param {VersionRange} range * @returns {Promise} @@ -49,11 +70,11 @@ async function resolveVersion({ range, isCanary }) { if (isCanary) { if (range === "latest") { const res = await fetchWithRetries( - "https://dl.deno.land/canary-latest.txt", + "https://dl.deno.land/canary-latest.txt" ); if (res.status !== 200) { throw new Error( - "Failed to fetch canary version info from dl.deno.land. Please try again later.", + "Failed to fetch canary version info from dl.deno.land. Please try again later." ); } const version = (await res.text()).trim(); @@ -65,7 +86,7 @@ async function resolveVersion({ range, isCanary }) { const res = await fetchWithRetries("https://deno.com/versions.json"); if (res.status !== 200) { throw new Error( - "Failed to fetch stable version info from deno.com/versions.json. Please try again later.", + "Failed to fetch stable version info from deno.com/versions.json. Please try again later." ); } const versionJson = await res.json(); @@ -115,4 +136,5 @@ async function fetchWithRetries(url, maxRetries = 5) { module.exports = { parseVersionRange, resolveVersion, + getDenoVersionFromFile, }; From 6406ddf5d04ec2ee2a000685ad26655433048c9f Mon Sep 17 00:00:00 2001 From: Jesse Dijkstra Date: Tue, 23 Apr 2024 16:11:48 +0200 Subject: [PATCH 02/16] Fix indentation --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c89bd9ba..c300981b 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,7 @@ inputs: deno-version: description: The Deno version to install. Can be a semver version of a stable release, "canary" for the latest canary, or the Git hash of a specific canary release. default: "1.x" - deno-version-file: + deno-version-file: description: File containing the Deno version to install such as .dvmrc or .tool-versions. Overridden by deno-version. outputs: deno-version: From 90bb7b975c28bd5ed99af559d6cc3edbf6e5553e Mon Sep 17 00:00:00 2001 From: Jesse Dijkstra Date: Tue, 2 Jul 2024 15:02:44 +0200 Subject: [PATCH 03/16] Add .tool-versions and .dvmrc test cases Signed-off-by: Jesse Dijkstra --- .dvmrc | 1 + .github/workflows/test.yml | 56 +++++++++++++++++++++++++++++++++++++- .tool-versions | 1 + 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .dvmrc create mode 100644 .tool-versions diff --git a/.dvmrc b/.dvmrc new file mode 100644 index 00000000..503ae8b7 --- /dev/null +++ b/.dvmrc @@ -0,0 +1 @@ +v1.43.1 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97f7d365..f80b9c51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,13 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] deno: - [1.x, "1.33.1", canary, ~1.32, b31cf9fde6ad5398c20370c136695db77df6beeb] + [ + 1.x, + "1.33.1", + canary, + ~1.32, + b31cf9fde6ad5398c20370c136695db77df6beeb, + ] steps: - uses: actions/checkout@v3 @@ -38,3 +44,51 @@ jobs: - name: Lint if: runner.os == 'Linux' && matrix.deno == 'canary' run: npm run lint + + test-dvm-file: + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + deno: + [ + 1.x, + "1.33.1", + canary, + ~1.32, + b31cf9fde6ad5398c20370c136695db77df6beeb, + ] + steps: + - uses: actions/checkout@v3 + + - name: Setup Deno + uses: ./ + with: + deno-version-file: .dvmrc + + - name: Check version + run: deno -V | grep -q "deno 1\.43\.1" + + test-tool-versions-file: + runs-on: ${{matrix.os}} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + deno: + [ + 1.x, + "1.33.1", + canary, + ~1.32, + b31cf9fde6ad5398c20370c136695db77df6beeb, + ] + steps: + - uses: actions/checkout@v3 + + - name: Setup Deno + uses: ./ + with: + deno-version-file: .tool-versions + + - name: Check version + run: deno -V | grep -q "deno 1\.43\.1" diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 00000000..ac1e8923 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +deno 1.43.1 \ No newline at end of file From 188e7e84525ed816c57b4a22b4a363957a44a50b Mon Sep 17 00:00:00 2001 From: Jesse Dijkstra Date: Tue, 2 Jul 2024 15:08:29 +0200 Subject: [PATCH 04/16] Only run on ubuntu-latest Signed-off-by: Jesse Dijkstra --- .dvmrc | 2 +- .github/workflows/test.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.dvmrc b/.dvmrc index 503ae8b7..288fbe83 100644 --- a/.dvmrc +++ b/.dvmrc @@ -1 +1 @@ -v1.43.1 \ No newline at end of file +1.43.1 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f80b9c51..e7cde9ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,7 +46,7 @@ jobs: run: npm run lint test-dvm-file: - runs-on: ${{matrix.os}} + runs-on: ubuntu-latest strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] @@ -70,7 +70,7 @@ jobs: run: deno -V | grep -q "deno 1\.43\.1" test-tool-versions-file: - runs-on: ${{matrix.os}} + runs-on: ubuntu-latest strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] From 4ad93eed32e2075777d8e631bde5188ec8cf3cb5 Mon Sep 17 00:00:00 2001 From: Jesse Dijkstra Date: Tue, 2 Jul 2024 15:10:38 +0200 Subject: [PATCH 05/16] Check for deno-version-file before defaulting to deno-version Signed-off-by: Jesse Dijkstra --- action.yml | 1 - main.js | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index c300981b..e7685800 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,6 @@ branding: inputs: deno-version: description: The Deno version to install. Can be a semver version of a stable release, "canary" for the latest canary, or the Git hash of a specific canary release. - default: "1.x" deno-version-file: description: File containing the Deno version to install such as .dvmrc or .tool-versions. Overridden by deno-version. outputs: diff --git a/main.js b/main.js index 08ceb39c..10a1ecd5 100644 --- a/main.js +++ b/main.js @@ -21,7 +21,9 @@ async function main() { try { const denoVersionFile = core.getInput("deno-version-file"); const range = parseVersionRange( - core.getInput("deno-version") || getDenoVersionFromFile(denoVersionFile) + denoVersionFile + ? getDenoVersionFromFile(denoVersionFile) + : core.getInput("deno-version") ); if (range === null) { From 63b821882fb959a73b1a5aefefc3ae010ec0a4e9 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 14:38:04 +0900 Subject: [PATCH 06/16] fmt --- main.js | 8 ++++---- src/version.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index 10a1ecd5..33574a03 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,7 @@ async function main() { const range = parseVersionRange( denoVersionFile ? getDenoVersionFromFile(denoVersionFile) - : core.getInput("deno-version") + : core.getInput("deno-version"), ); if (range === null) { @@ -36,9 +36,9 @@ async function main() { } core.info( - `Going to install ${version.isCanary ? "canary" : "stable"} version ${ - version.version - }.` + `Going to install ${ + version.isCanary ? "canary" : "stable" + } version ${version.version}.`, ); await install(version); diff --git a/src/version.js b/src/version.js index 7748ce6a..460788e6 100644 --- a/src/version.js +++ b/src/version.js @@ -51,7 +51,7 @@ function parseVersionRange(version) { function getDenoVersionFromFile(versionFilePath) { if (!fs.existsSync(versionFilePath)) { throw new Error( - `The specified node version file at: ${versionFilePath} does not exist` + `The specified node version file at: ${versionFilePath} does not exist`, ); } @@ -70,11 +70,11 @@ async function resolveVersion({ range, isCanary }) { if (isCanary) { if (range === "latest") { const res = await fetchWithRetries( - "https://dl.deno.land/canary-latest.txt" + "https://dl.deno.land/canary-latest.txt", ); if (res.status !== 200) { throw new Error( - "Failed to fetch canary version info from dl.deno.land. Please try again later." + "Failed to fetch canary version info from dl.deno.land. Please try again later.", ); } const version = (await res.text()).trim(); @@ -86,7 +86,7 @@ async function resolveVersion({ range, isCanary }) { const res = await fetchWithRetries("https://deno.com/versions.json"); if (res.status !== 200) { throw new Error( - "Failed to fetch stable version info from deno.com/versions.json. Please try again later." + "Failed to fetch stable version info from deno.com/versions.json. Please try again later.", ); } const versionJson = await res.json(); From 9f5918782df362462502e0dbc16cc08aa44876bf Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 14:40:29 +0900 Subject: [PATCH 07/16] remove unused params --- .github/workflows/test.yml | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7cde9ae..f69ea963 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,14 +12,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - deno: - [ - 1.x, - "1.33.1", - canary, - ~1.32, - b31cf9fde6ad5398c20370c136695db77df6beeb, - ] + deno: [1.x, "1.33.1", canary, ~1.32, b31cf9fde6ad5398c20370c136695db77df6beeb] steps: - uses: actions/checkout@v3 @@ -47,17 +40,6 @@ jobs: test-dvm-file: runs-on: ubuntu-latest - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - deno: - [ - 1.x, - "1.33.1", - canary, - ~1.32, - b31cf9fde6ad5398c20370c136695db77df6beeb, - ] steps: - uses: actions/checkout@v3 @@ -71,17 +53,6 @@ jobs: test-tool-versions-file: runs-on: ubuntu-latest - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - deno: - [ - 1.x, - "1.33.1", - canary, - ~1.32, - b31cf9fde6ad5398c20370c136695db77df6beeb, - ] steps: - uses: actions/checkout@v3 From 6a2be7777a2339dda2b338b6457a442e418bb172 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 14:41:12 +0900 Subject: [PATCH 08/16] add new line at the end --- .dvmrc | 2 +- .tool-versions | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.dvmrc b/.dvmrc index 288fbe83..3987c472 100644 --- a/.dvmrc +++ b/.dvmrc @@ -1 +1 @@ -1.43.1 \ No newline at end of file +1.43.1 diff --git a/.tool-versions b/.tool-versions index ac1e8923..b5aa10da 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -deno 1.43.1 \ No newline at end of file +deno 1.43.1 From dfaa2430e68e1e65ad77224133595ba2f14f839a Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 14:56:44 +0900 Subject: [PATCH 09/16] restore default version --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index e7685800..c300981b 100644 --- a/action.yml +++ b/action.yml @@ -7,6 +7,7 @@ branding: inputs: deno-version: description: The Deno version to install. Can be a semver version of a stable release, "canary" for the latest canary, or the Git hash of a specific canary release. + default: "1.x" deno-version-file: description: File containing the Deno version to install such as .dvmrc or .tool-versions. Overridden by deno-version. outputs: From fae684ccb01004e87b1c77f4110bf37f359510e5 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 14:56:57 +0900 Subject: [PATCH 10/16] reduce unnecessary format change --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f69ea963..656707a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,8 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] - deno: [1.x, "1.33.1", canary, ~1.32, b31cf9fde6ad5398c20370c136695db77df6beeb] + deno: + [1.x, "1.33.1", canary, ~1.32, b31cf9fde6ad5398c20370c136695db77df6beeb] steps: - uses: actions/checkout@v3 From 196407751a4e27eb3cd26326d9ec391c1d8b5633 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 15:01:03 +0900 Subject: [PATCH 11/16] add more entries in .tool-versions --- .tool-versions | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.tool-versions b/.tool-versions index b5aa10da..5d7d2f58 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1,7 @@ +nodejs 20.5.1 +bun 1.1.4 +ruby 3.3.0 +lua 5.4.4 deno 1.43.1 +rust 1.65.0 +python 3.11.0 From ad38253190e5fcd225a8018f127c435998e2010d Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 15:17:09 +0900 Subject: [PATCH 12/16] fix canary sha1 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 656707a3..07cab26a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] deno: - [1.x, "1.33.1", canary, ~1.32, b31cf9fde6ad5398c20370c136695db77df6beeb] + [1.x, "1.33.1", canary, ~1.32, b290fd01f3f5d32f9d010fc719ced0240759c049] steps: - uses: actions/checkout@v3 From 709440311db3ae1f99671ddefe344458eaf78cfb Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 15:19:55 +0900 Subject: [PATCH 13/16] refactor --- .github/workflows/test.yml | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07cab26a..9af77059 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,28 +39,18 @@ jobs: if: runner.os == 'Linux' && matrix.deno == 'canary' run: npm run lint - test-dvm-file: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Setup Deno - uses: ./ - with: - deno-version-file: .dvmrc - - - name: Check version - run: deno -V | grep -q "deno 1\.43\.1" - - test-tool-versions-file: + test-version-file: runs-on: ubuntu-latest + strategy: + matrix: + deno-version-file: [.dvmrc, .tool-versions] steps: - uses: actions/checkout@v3 - name: Setup Deno uses: ./ with: - deno-version-file: .tool-versions + deno-version-file: ${{ matrix.deno-version-file }} - name: Check version run: deno -V | grep -q "deno 1\.43\.1" From 2b693fd8bf5a132bfe4a96afd1cac624b0dc822d Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 15:27:43 +0900 Subject: [PATCH 14/16] fix regexp, add comments --- src/version.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/version.js b/src/version.js index 460788e6..763b560e 100644 --- a/src/version.js +++ b/src/version.js @@ -57,9 +57,16 @@ function getDenoVersionFromFile(versionFilePath) { const contents = fs.readFileSync(versionFilePath, "utf8"); - const found = contents.match(/^(?:deno?\s+)?v?(?[^\s]+)$/m); - - return (found && found.groups && found.groups.version) || contents.trim(); + // .tool-versions typically looks like + // ``` + // ruby 2.6.5 + // deno 1.43.1 + // node 20.0.0 + // ``` + // This parses the version of Deno from the file + const denoVersionInToolVersions = contents.match(/^deno\s+v?(?[^\s]+)$/m); + + return denoVersionInToolVersions?.groups?.version || contents.trim(); } /** From 2184bc85efa520ccbebb1a10134ab9fb547ea39d Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 15:29:56 +0900 Subject: [PATCH 15/16] fmt --- src/version.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/version.js b/src/version.js index 763b560e..b39bfe76 100644 --- a/src/version.js +++ b/src/version.js @@ -64,7 +64,9 @@ function getDenoVersionFromFile(versionFilePath) { // node 20.0.0 // ``` // This parses the version of Deno from the file - const denoVersionInToolVersions = contents.match(/^deno\s+v?(?[^\s]+)$/m); + const denoVersionInToolVersions = contents.match( + /^deno\s+v?(?[^\s]+)$/m, + ); return denoVersionInToolVersions?.groups?.version || contents.trim(); } From 3c2648311ef2f1c990ac76df08fb8b3ebf43e2b9 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Fri, 5 Jul 2024 15:32:16 +0900 Subject: [PATCH 16/16] update docs --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index c300981b..74d15ef0 100644 --- a/action.yml +++ b/action.yml @@ -9,7 +9,7 @@ inputs: description: The Deno version to install. Can be a semver version of a stable release, "canary" for the latest canary, or the Git hash of a specific canary release. default: "1.x" deno-version-file: - description: File containing the Deno version to install such as .dvmrc or .tool-versions. Overridden by deno-version. + description: File containing the Deno version to install such as .dvmrc or .tool-versions. outputs: deno-version: description: "The Deno version that was installed."