mirror of
https://gitea.com/actions/setup-deno.git
synced 2025-12-11 10:56:49 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f99b7edee3 | ||
|
|
edde9366ea | ||
|
|
041b854f97 | ||
|
|
ef28d469f1 | ||
|
|
0df5d9c641 | ||
|
|
85bf53342c | ||
|
|
61fe2df320 | ||
|
|
b41525049b | ||
|
|
d114c5eb74 |
26
.github/workflows/test.yml
vendored
26
.github/workflows/test.yml
vendored
@@ -13,10 +13,10 @@ jobs:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
deno:
|
||||
[1.x, "1.8.2", canary, ~1.7, e7b7129b7a92b7500ded88f8f5baa25a7f59e56e]
|
||||
[1.x, "1.33.1", canary, ~1.32, b290fd01f3f5d32f9d010fc719ced0240759c049]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Setup Deno
|
||||
uses: ./
|
||||
@@ -24,12 +24,12 @@ jobs:
|
||||
deno-version: ${{ matrix.deno }}
|
||||
|
||||
- name: Test Deno
|
||||
run: deno run https://deno.land/std/examples/welcome.ts
|
||||
run: deno run https://deno.land/std@0.198.0/examples/welcome.ts
|
||||
|
||||
- name: Test `deno install`
|
||||
run: |
|
||||
deno install --allow-net -n deno_curl https://deno.land/std/examples/curl.ts
|
||||
deno_curl https://deno.land/std/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
|
||||
|
||||
- name: Format
|
||||
if: runner.os == 'Linux' && matrix.deno == 'canary'
|
||||
@@ -38,3 +38,19 @@ jobs:
|
||||
- name: Lint
|
||||
if: runner.os == 'Linux' && matrix.deno == 'canary'
|
||||
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
|
||||
14
README.md
14
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
|
||||
|
||||
@@ -8,11 +8,13 @@ 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.
|
||||
outputs:
|
||||
deno-version:
|
||||
description: "The Deno version that was installed."
|
||||
is-canary:
|
||||
description: "If the installed Deno version was a canary version."
|
||||
runs:
|
||||
using: "node16"
|
||||
using: "node20"
|
||||
main: "main.js"
|
||||
|
||||
14
main.js
14
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,13 @@ function exit(message) {
|
||||
|
||||
async function main() {
|
||||
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) {
|
||||
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",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"version": "1.2.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/@actions/core": {
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "setup-deno",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "setup-deno",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "setup-deno",
|
||||
"description": "Set up Deno easially in GitHub Actions",
|
||||
"version": "1.1.1",
|
||||
"version": "1.2.0",
|
||||
"author": "Deno Land Inc",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
@@ -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,35 @@ 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");
|
||||
|
||||
// .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
|
||||
* @returns {Promise<Version | null>}
|
||||
@@ -48,7 +78,9 @@ function parseVersionRange(version) {
|
||||
async function resolveVersion({ range, isCanary }) {
|
||||
if (isCanary) {
|
||||
if (range === "latest") {
|
||||
const res = await fetch("https://dl.deno.land/canary-latest.txt");
|
||||
const res = await fetchWithRetries(
|
||||
"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.",
|
||||
@@ -60,12 +92,10 @@ async function resolveVersion({ range, isCanary }) {
|
||||
return { version: range, isCanary: true };
|
||||
}
|
||||
|
||||
const res = await fetch(
|
||||
"https://raw.githubusercontent.com/denoland/dotland/main/versions.json",
|
||||
);
|
||||
const res = await fetchWithRetries("https://deno.com/versions.json");
|
||||
if (res.status !== 200) {
|
||||
throw new Error(
|
||||
"Failed to fetch stable version info from raw.githubusercontent.com. Please try again later.",
|
||||
"Failed to fetch stable version info from deno.com/versions.json. Please try again later.",
|
||||
);
|
||||
}
|
||||
const versionJson = await res.json();
|
||||
@@ -90,7 +120,30 @@ async function resolveVersion({ range, isCanary }) {
|
||||
return { version, isCanary: false };
|
||||
}
|
||||
|
||||
/** @param {string} url */
|
||||
async function fetchWithRetries(url, maxRetries = 5) {
|
||||
let sleepMs = 250;
|
||||
let iterationCount = 0;
|
||||
while (true) {
|
||||
iterationCount++;
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
if (res.status === 200 || iterationCount > maxRetries) {
|
||||
return res;
|
||||
}
|
||||
} catch (err) {
|
||||
if (iterationCount > maxRetries) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
console.warn(`Failed fetching. Retrying in ${sleepMs}ms...`);
|
||||
await new Promise((resolve) => setTimeout(resolve, sleepMs));
|
||||
sleepMs = Math.min(sleepMs * 2, 10_000);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
parseVersionRange,
|
||||
resolveVersion,
|
||||
getDenoVersionFromFile,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user