From 7121c784646df8c2487270f904c7e006c20434c1 Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Sun, 11 Aug 2024 18:48:15 +0200 Subject: [PATCH] feat: Add support for riscv64 --- README.md | 3 ++- action.yml | 1 + src/index.js | 9 +++++---- src/lib.js | 2 +- test/getArchiveSuffixes.js | 4 ++++ 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 58b7bcd..204b016 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ where: * `{name}` is the name of the tool (executable) * `{platform}` is the name of the target platform: `linux`, `macos` or `windows` -* `{architecture}` is the name of the target architecture: `aarch64` or `arm64` (64-bit ARM), `amd64`, `x86_64`, `x64` or `x86` (64-bit AMD) +* `{architecture}` is the name of the target architecture: `aarch64` or `arm64` (64-bit ARM), `riscv64` (RISC-V), `amd64`, `x86_64`, `x64` (64-bit AMD) or `x86` (32-bit Intel) ## Inputs @@ -79,6 +79,7 @@ Type: `Map{String, String[]}`
Default: arm64:aarch64 + riscv64: x64:amd64,x86_64,x86 A map where keys are Node.js architectures and values are their aliases which will be recognised in names of the installation archives. The Node.js architectures name itself doesn't have to be included in the aliases. This input is a multi-line string, where each line is a map entry. The kay is separated from the value by colon (:). Aliases are separated by commas (,). diff --git a/action.yml b/action.yml index c2f97f9..40b6259 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,7 @@ inputs: A map where keys are Node.js architectures and values are their aliases which will be recognised in names of the installation archives. The Node.js architectures name itself doesn't have to be included in the aliases. This input is a multi-line string, where each line is a map entry. The kay is separated from the value by colon (:). Aliases are separated by commas (,). default: |- arm64:aarch64 + riscv64: x64:amd64,x86_64,x86 use-cache: description: >- diff --git a/src/index.js b/src/index.js index f50139f..1a9302d 100644 --- a/src/index.js +++ b/src/index.js @@ -5,19 +5,20 @@ if (typeof global.crypto.getRandomValues !== 'function') { global.crypto.getRandomValues = getRandomValues } -const { join, resolve } = require('path') +const { join, resolve } = require('node:path') const core = require('@actions/core') const { exec } = require("@actions/exec") const io = require('@actions/io') const httpm = require('@actions/http-client') const tc = require('@actions/tool-cache') -const { access, symlink } = require('fs').promises +const { access, symlink } = require('node:fs').promises const MersenneTwister = require('mersenne-twister') const { clean, satisfies, valid } = require('semver') const { getMapOfArrays, getArchiveSuffixes } = require('./lib') const { platform } = process -let platformSuffixes, archSuffixes +let platformSuffixes +let archSuffixes const twister = new MersenneTwister(Math.random() * Number.MAX_SAFE_INTEGER) function getRandomValues(dest) { @@ -173,7 +174,7 @@ async function run() { if (cleanedVersion) version = cleanedVersion; const name = core.getInput('name') const useCache = core.getBooleanInput('use-cache') - core.info(`Download ${version} from ${repo}${name ? 'named ' + name : ''}${useCache ? '' : ', no cache'}`) + core.info(`Download ${version} from ${repo}${name ? `named ${name}` : ''}${useCache ? '' : ', no cache'}`) platformSuffixes = getMapOfArrays('platforms') archSuffixes = getMapOfArrays('architectures') diff --git a/src/lib.js b/src/lib.js index 9aa6054..172c0d2 100644 --- a/src/lib.js +++ b/src/lib.js @@ -22,5 +22,5 @@ exports.getArchiveSuffixes = function getArchiveSuffixes(platformSuffixes, archS if (!plats.includes(platform)) plats.push(platform) const archs = archSuffixes[arch] || [] if (!archs.includes(arch)) archs.push(arch) - return plats.map(plat => archs.map(arch => `-${plat}-${arch}.zip`)).flat() + return plats.flatMap(plat => archs.map(arch => `-${plat}-${arch}.zip`)) } diff --git a/test/getArchiveSuffixes.js b/test/getArchiveSuffixes.js index 7b7af7f..fea5f84 100644 --- a/test/getArchiveSuffixes.js +++ b/test/getArchiveSuffixes.js @@ -12,6 +12,7 @@ const platforms = { const archives = { arm64: ['aarch64'], + riscv64: [], x64: ['amd64', 'x86_64', 'x86'] } @@ -42,6 +43,9 @@ const expected = { '-linux-arm64.zip', '-linux-aarch64.zip' ], + 'linux-riscv64': [ + '-linux-riscv64.zip' + ], 'win32-x64': [ '-win-amd64.zip', '-win-x86_64.zip',