Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add compatibility for multiple os and arch #38

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30837,6 +30837,8 @@ var io = __nccwpck_require__(2826);
var tool_cache = __nccwpck_require__(5561);
// EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(7147);
// EXTERNAL MODULE: external "os"
var external_os_ = __nccwpck_require__(2037);
// EXTERNAL MODULE: ./node_modules/.pnpm/@actions+http-client@2.2.1/node_modules/@actions/http-client/lib/index.js
var lib = __nccwpck_require__(6372);
;// CONCATENATED MODULE: ./lib/version.js
Expand Down Expand Up @@ -30871,13 +30873,36 @@ const getLatest = async () => {




const TOOL_NAME = 'scw';
const PLATFORM_MAP = {
darwin: 'darwin',
freebsd: 'freebsd',
win32: 'windows',
};
const ARCH_MAP = {
arm64: 'arm64',
i386: '386',
};
const downloadURL = (targetVersion) => {
let version = targetVersion;
let platform = 'linux';
let arch = 'amd64';
if (external_os_.platform() in PLATFORM_MAP) {
platform = PLATFORM_MAP[external_os_.platform()];
}
if (external_os_.machine() in ARCH_MAP) {
if (platform === 'windows') {
arch = `${ARCH_MAP[external_os_.machine()]}.exe`;
}
else {
arch = ARCH_MAP[external_os_.machine()];
}
}
if (version.startsWith('v')) {
version = version.slice(1);
}
return `https://github.com/scaleway/scaleway-cli/releases/download/v${version}/scaleway-cli_${version}_linux_amd64`;
return `https://github.com/scaleway/scaleway-cli/releases/download/v${version}/scaleway-cli_${version}_${platform}_${arch}`;
};
const isInPath = (toolPath) => {
const envPath = process.env.PATH;
Expand Down
26 changes: 25 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,43 @@ import * as core from '@actions/core'
import * as io from '@actions/io'
import * as tc from '@actions/tool-cache'
import { promises as fs } from 'fs'
import os from 'os'
import type { Args } from './input.js'
import { VERSION_LATEST, getLatest } from './version.js'

const TOOL_NAME = 'scw'
const PLATFORM_MAP = {
darwin: 'darwin',
freebsd: 'freebsd',
win32: 'windows',
}
const ARCH_MAP = {
arm64: 'arm64',
i386: '386',
}

const downloadURL = (targetVersion: string): string => {
let version = targetVersion
let platform = 'linux'
let arch = 'amd64'

if (os.platform() in PLATFORM_MAP) {
platform = PLATFORM_MAP[os.platform() as keyof typeof PLATFORM_MAP]
}

if (os.machine() in ARCH_MAP) {
if (platform === 'windows') {
arch = `${ARCH_MAP[os.machine() as keyof typeof ARCH_MAP]}.exe`
} else {
arch = ARCH_MAP[os.machine() as keyof typeof ARCH_MAP]
}
}

if (version.startsWith('v')) {
version = version.slice(1)
}

return `https://github.com/scaleway/scaleway-cli/releases/download/v${version}/scaleway-cli_${version}_linux_amd64`
return `https://github.com/scaleway/scaleway-cli/releases/download/v${version}/scaleway-cli_${version}_${platform}_${arch}`
}

const isInPath = (toolPath: string): boolean => {
Expand Down
Loading