mirror of
https://gitea.com/actions/setup-deno.git
synced 2025-12-11 19:06:43 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa660b328d | ||
|
|
cce4306590 | ||
|
|
916edb9a40 | ||
|
|
b8a676db36 | ||
|
|
ba9dcf3bc3 | ||
|
|
2bca7ce523 | ||
|
|
f99b7edee3 | ||
|
|
edde9366ea | ||
|
|
041b854f97 | ||
|
|
ef28d469f1 |
27
.github/workflows/test.yml
vendored
27
.github/workflows/test.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
deno:
|
deno:
|
||||||
[1.x, "1.33.1", canary, ~1.32, b31cf9fde6ad5398c20370c136695db77df6beeb]
|
[1.x, "1.33.1", canary, ~1.32, b290fd01f3f5d32f9d010fc719ced0240759c049]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@@ -26,7 +26,14 @@ jobs:
|
|||||||
- name: Test Deno
|
- name: Test Deno
|
||||||
run: deno run https://deno.land/std@0.198.0/examples/welcome.ts
|
run: deno run https://deno.land/std@0.198.0/examples/welcome.ts
|
||||||
|
|
||||||
- name: Test `deno install`
|
- name: Test `deno install -g` (2.0)
|
||||||
|
if: matrix.deno == 'canary' || matrix.deno == 'latest'
|
||||||
|
run: |
|
||||||
|
deno install -g --allow-net -n deno_curl https://deno.land/std@0.198.0/examples/curl.ts
|
||||||
|
deno_curl https://deno.land/std@0.198.0/examples/curl.ts
|
||||||
|
|
||||||
|
- name: Test `deno install (1.0)
|
||||||
|
if: matrix.deno == '1.x' || matrix.deno == '1.33.1' || matrix.deno == '~1.32' || matrix.deno == 'b290fd01f3f5d32f9d010fc719ced0240759c049'
|
||||||
run: |
|
run: |
|
||||||
deno install --allow-net -n deno_curl https://deno.land/std@0.198.0/examples/curl.ts
|
deno install --allow-net -n deno_curl https://deno.land/std@0.198.0/examples/curl.ts
|
||||||
deno_curl https://deno.land/std@0.198.0/examples/curl.ts
|
deno_curl https://deno.land/std@0.198.0/examples/curl.ts
|
||||||
@@ -38,3 +45,19 @@ jobs:
|
|||||||
- name: Lint
|
- name: Lint
|
||||||
if: runner.os == 'Linux' && matrix.deno == 'canary'
|
if: runner.os == 'Linux' && matrix.deno == 'canary'
|
||||||
run: npm run lint
|
run: npm run lint
|
||||||
|
|
||||||
|
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: ${{ matrix.deno-version-file }}
|
||||||
|
|
||||||
|
- name: Check version
|
||||||
|
run: deno -V | grep -q "deno 1\.43\.1"
|
||||||
|
|||||||
7
.tool-versions
Normal file
7
.tool-versions
Normal file
@@ -0,0 +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
|
||||||
1
CODEOWNERS
Normal file
1
CODEOWNERS
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* @lucacasonato
|
||||||
20
README.md
20
README.md
@@ -53,3 +53,23 @@ Targets the latest major, minor and patch version of Deno.
|
|||||||
with:
|
with:
|
||||||
deno-version: e7b7129b7a92b7500ded88f8f5baa25a7f59e56e
|
deno-version: e7b7129b7a92b7500ded88f8f5baa25a7f59e56e
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Version from file
|
||||||
|
|
||||||
|
The extension can also automatically read the version file from
|
||||||
|
[`.tool-versions`](https://asdf-vm.com/manage/configuration.html#tool-versions)
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: denoland/setup-deno@v1
|
||||||
|
with:
|
||||||
|
deno-version-file: .tool-versions
|
||||||
|
```
|
||||||
|
|
||||||
|
The extension can also automatically read the file from
|
||||||
|
[`dvm`](https://github.com/justjavac/dvm).
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: denoland/setup-deno@v1
|
||||||
|
with:
|
||||||
|
deno-version-file: .dvmrc
|
||||||
|
```
|
||||||
|
|||||||
@@ -8,11 +8,13 @@ inputs:
|
|||||||
deno-version:
|
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.
|
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"
|
default: "1.x"
|
||||||
|
deno-version-file:
|
||||||
|
description: File containing the Deno version to install such as .dvmrc or .tool-versions.
|
||||||
outputs:
|
outputs:
|
||||||
deno-version:
|
deno-version:
|
||||||
description: "The Deno version that was installed."
|
description: "The Deno version that was installed."
|
||||||
is-canary:
|
is-canary:
|
||||||
description: "If the installed Deno version was a canary version."
|
description: "If the installed Deno version was a canary version."
|
||||||
runs:
|
runs:
|
||||||
using: "node16"
|
using: "node20"
|
||||||
main: "main.js"
|
main: "main.js"
|
||||||
|
|||||||
14
main.js
14
main.js
@@ -1,7 +1,11 @@
|
|||||||
const process = require("process");
|
const process = require("process");
|
||||||
const core = require("@actions/core");
|
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");
|
const { install } = require("./src/install.js");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,7 +19,13 @@ function exit(message) {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const range = parseVersionRange(core.getInput("deno-version"));
|
const denoVersionFile = core.getInput("deno-version-file");
|
||||||
|
const range = parseVersionRange(
|
||||||
|
denoVersionFile
|
||||||
|
? getDenoVersionFromFile(denoVersionFile)
|
||||||
|
: core.getInput("deno-version"),
|
||||||
|
);
|
||||||
|
|
||||||
if (range === null) {
|
if (range === null) {
|
||||||
exit("The passed version range is not valid.");
|
exit("The passed version range is not valid.");
|
||||||
}
|
}
|
||||||
|
|||||||
4
node_modules/.package-lock.json
generated
vendored
4
node_modules/.package-lock.json
generated
vendored
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-deno",
|
"name": "setup-deno",
|
||||||
"version": "1.1.0",
|
"version": "1.4.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-deno",
|
"name": "setup-deno",
|
||||||
"version": "1.1.0",
|
"version": "1.4.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "setup-deno",
|
"name": "setup-deno",
|
||||||
"version": "1.1.0",
|
"version": "1.4.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "setup-deno",
|
"name": "setup-deno",
|
||||||
"description": "Set up Deno easially in GitHub Actions",
|
"description": "Set up Deno easially in GitHub Actions",
|
||||||
"version": "1.1.3",
|
"version": "1.4.1",
|
||||||
"author": "Deno Land Inc",
|
"author": "Deno Land Inc",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ async function install(version) {
|
|||||||
const zip = zipName();
|
const zip = zipName();
|
||||||
const url = version.isCanary
|
const url = version.isCanary
|
||||||
? `https://dl.deno.land/canary/${version.version}/${zip}`
|
? `https://dl.deno.land/canary/${version.version}/${zip}`
|
||||||
: `https://github.com/denoland/deno/releases/download/v${version.version}/${zip}`;
|
: `https://dl.deno.land/release/v${version.version}/${zip}`;
|
||||||
|
|
||||||
core.info(`Downloading Deno from ${url}.`);
|
core.info(`Downloading Deno from ${url}.`);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const semver = require("semver");
|
const semver = require("semver");
|
||||||
const { fetch } = require("undici");
|
const { fetch } = require("undici");
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
const GIT_HASH_RE = /^[0-9a-fA-F]{40}$/;
|
const GIT_HASH_RE = /^[0-9a-fA-F]{40}$/;
|
||||||
|
|
||||||
@@ -29,6 +30,10 @@ function parseVersionRange(version) {
|
|||||||
return { range: "latest", isCanary: true };
|
return { range: "latest", isCanary: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (version == "latest") {
|
||||||
|
return { range: "latest", isCanary: false };
|
||||||
|
}
|
||||||
|
|
||||||
if (GIT_HASH_RE.test(version)) {
|
if (GIT_HASH_RE.test(version)) {
|
||||||
return { range: version, isCanary: true };
|
return { range: version, isCanary: true };
|
||||||
}
|
}
|
||||||
@@ -41,6 +46,35 @@ function parseVersionRange(version) {
|
|||||||
return null;
|
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");
|
||||||
|
|
||||||
|
// .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?(?<version>[^\s]+)$/m,
|
||||||
|
);
|
||||||
|
|
||||||
|
return denoVersionInToolVersions?.groups?.version || contents.trim();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {VersionRange} range
|
* @param {VersionRange} range
|
||||||
* @returns {Promise<Version | null>}
|
* @returns {Promise<Version | null>}
|
||||||
@@ -62,6 +96,23 @@ async function resolveVersion({ range, isCanary }) {
|
|||||||
return { version: range, isCanary: true };
|
return { version: range, isCanary: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (range === "latest") {
|
||||||
|
const res = await fetchWithRetries(
|
||||||
|
"https://dl.deno.land/release-latest.txt",
|
||||||
|
);
|
||||||
|
if (res.status !== 200) {
|
||||||
|
throw new Error(
|
||||||
|
"Failed to fetch release version info from dl.deno.land. Please try again later.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
let version = (await res.text()).trim();
|
||||||
|
version = semver.clean(version);
|
||||||
|
if (version === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return { version, isCanary: false };
|
||||||
|
}
|
||||||
|
|
||||||
const res = await fetchWithRetries("https://deno.com/versions.json");
|
const res = await fetchWithRetries("https://deno.com/versions.json");
|
||||||
if (res.status !== 200) {
|
if (res.status !== 200) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -115,4 +166,5 @@ async function fetchWithRetries(url, maxRetries = 5) {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
parseVersionRange,
|
parseVersionRange,
|
||||||
resolveVersion,
|
resolveVersion,
|
||||||
|
getDenoVersionFromFile,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user