diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3162b4..30bf507 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -80,6 +80,19 @@ jobs: - name: Check binary exists run: deno_foo -V + test-target: + runs-on: windows-11-arm + steps: + - uses: actions/checkout@v5 + + - name: Setup Deno with target x64 + uses: ./ + with: + target: x86_64-pc-windows-msvc + + - name: Check version + run: deno --version + test-setup-cache: runs-on: ${{ matrix.os }} strategy: diff --git a/README.md b/README.md index 4f276b8..37ca228 100644 --- a/README.md +++ b/README.md @@ -179,3 +179,17 @@ It is possible to customize the default hash # the default cache-hash of `${{ hashFiles('**/deno.lock') }}` cache-hash: ${{ hashFiles('**/deno.json') }} ``` + +### Determining the target platform + +You can determine the target platform of Deno. + +This can be used when automatic platform detection does not meet the conditions, +such as when you want to run x64 binaries on Windows Arm. + +```yaml +- uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + target: x86_64-pc-windows-msvc +``` diff --git a/action.yml b/action.yml index 9f4d68f..3595e05 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,8 @@ inputs: deno-binary-name: description: The name to use for the binary. default: "deno" + target: + description: The target platform of the binary (e.g., "x86_64-pc-windows-msvc"). cache: description: Cache downloaded modules & packages automatically in GitHub Actions cache. default: "false" diff --git a/dist/main.mjs b/dist/main.mjs index d4dc23d..583ae36 100644 --- a/dist/main.mjs +++ b/dist/main.mjs @@ -20252,14 +20252,14 @@ var import_tool_cache = __toESM(require_tool_cache(), 1); //#endregion //#region src/install.ts -async function install(version) { +async function install(version, target = "") { const cachedPath = import_tool_cache.find("deno", version.kind === "canary" ? `0.0.0-${version.version}` : version.version); if (cachedPath) { import_core.info(`Using cached Deno installation from ${cachedPath}.`); import_core.addPath(cachedPath); return; } - const zip = zipName(); + const zip = target ? `deno-${target}.zip` : zipName(); let url; switch (version.kind) { case "canary": @@ -20276,8 +20276,9 @@ async function install(version) { import_core.info(`Downloading Deno from ${url}.`); const zipPath = await import_tool_cache.downloadTool(url); const extractedFolder = await import_tool_cache.extractZip(zipPath); + const isWindowsPlatform = target ? target.includes("windows") : process$1.platform === "win32"; const binaryName = import_core.getInput("deno-binary-name"); - if (binaryName !== "deno") await fs.rename(path$1.join(extractedFolder, process$1.platform === "win32" ? "deno.exe" : "deno"), path$1.join(extractedFolder, process$1.platform === "win32" ? binaryName + ".exe" : binaryName)); + if (binaryName !== "deno") await fs.rename(path$1.join(extractedFolder, isWindowsPlatform ? "deno.exe" : "deno"), path$1.join(extractedFolder, isWindowsPlatform ? binaryName + ".exe" : binaryName)); const newCachedPath = await import_tool_cache.cacheDir(extractedFolder, binaryName, version.kind === "canary" ? `0.0.0-${version.version}` : version.version); import_core.info(`Cached Deno to ${newCachedPath}.`); import_core.addPath(newCachedPath); @@ -20328,7 +20329,8 @@ async function main() { const version = await resolveVersion(range); if (version === null) exit("Could not resolve a version for the given range."); import_core.info(`Going to install ${version.kind} version ${version.version}.`); - await install(version); + const target = import_core.getInput("target"); + await install(version, target); import_core.info(`::add-matcher::${path.join(import.meta.dirname ?? ".", "..", "deno-problem-matchers.json")}`); import_core.setOutput("deno-version", version.version); import_core.setOutput("release-channel", version.kind); diff --git a/src/install.ts b/src/install.ts index aacdf29..b799e2d 100644 --- a/src/install.ts +++ b/src/install.ts @@ -6,7 +6,7 @@ import core from "@actions/core"; import tc from "@actions/tool-cache"; import type { Version } from "./version.ts"; -export async function install(version: Version) { +export async function install(version: Version, target: string = "") { const cachedPath = tc.find( "deno", version.kind === "canary" ? `0.0.0-${version.version}` : version.version, @@ -17,7 +17,7 @@ export async function install(version: Version) { return; } - const zip = zipName(); + const zip = target ? `deno-${target}.zip` : zipName(); let url; switch (version.kind) { @@ -39,16 +39,21 @@ export async function install(version: Version) { const zipPath = await tc.downloadTool(url); const extractedFolder = await tc.extractZip(zipPath); + // Determine if the binary has .exe extension based on target or current platform + const isWindowsPlatform = target + ? target.includes("windows") + : process.platform === "win32"; + const binaryName = core.getInput("deno-binary-name"); if (binaryName !== "deno") { await fs.rename( path.join( extractedFolder, - process.platform === "win32" ? "deno.exe" : "deno", + isWindowsPlatform ? "deno.exe" : "deno", ), path.join( extractedFolder, - process.platform === "win32" ? binaryName + ".exe" : binaryName, + isWindowsPlatform ? binaryName + ".exe" : binaryName, ), ); } diff --git a/src/main.ts b/src/main.ts index 39d1f08..da5bb31 100644 --- a/src/main.ts +++ b/src/main.ts @@ -45,7 +45,8 @@ async function main() { core.info(`Going to install ${version.kind} version ${version.version}.`); - await install(version); + const target = core.getInput("target"); + await install(version, target); core.info( `::add-matcher::${