Add .tool-versions and .dvmrc support
This commit is contained in:
parent
041b854f97
commit
355fe3a070
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,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."
|
||||
|
18
main.js
18
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);
|
||||
|
@ -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?(?<version>[^\s]+)$/m);
|
||||
|
||||
return (found && found.groups && found.groups.version) || contents.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {VersionRange} range
|
||||
* @returns {Promise<Version | null>}
|
||||
@ -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,
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user