mirror of
https://github.com/GoTestTools/gotestfmt-action.git
synced 2026-02-08 00:37:27 +00:00
Download artifact for the correct architecture
This adds support for running the action for CPU architectures other than amd64/x86_64.
This commit is contained in:
parent
8b4478c701
commit
8de621c2cf
1 changed files with 16 additions and 5 deletions
21
index.js
21
index.js
|
|
@ -2,9 +2,10 @@ const core = require('@actions/core');
|
|||
const { Octokit } = require("@octokit/rest");
|
||||
const fs = require("fs")
|
||||
const { execSync } = require("child_process")
|
||||
const { arch: processArch } = require("node:process");
|
||||
|
||||
async function downloadRelease(octokit, os, org, repo, release, token) {
|
||||
const postfix = `_${os}_amd64.${os === "windows" ? "zip" : "tar.gz"}`;
|
||||
async function downloadRelease(octokit, os, arch, org, repo, release, token) {
|
||||
const postfix = `_${os}_${arch}.${os === "windows" ? "zip" : "tar.gz"}`;
|
||||
const tempdir = os === "windows" ? process.env.TEMP + "\\" : "/tmp/";
|
||||
const extract = os === "windows" ? "tar -xvf" : "tar -xvzf";
|
||||
const archive = `${tempdir}gotestfmt${postfix}`;
|
||||
|
|
@ -40,7 +41,7 @@ async function downloadRelease(octokit, os, org, repo, release, token) {
|
|||
throw `No release asset matched postfix '${postfix}'.`
|
||||
}
|
||||
|
||||
async function downloadGofmt(octokit, version, versionPrefix, os, org, repo, token) {
|
||||
async function downloadGofmt(octokit, version, versionPrefix, os, arch, org, repo, token) {
|
||||
if (version !== "") {
|
||||
if (!version.startsWith(versionPrefix)) {
|
||||
throw "Specified version " + version + " does not start with required version prefix " + versionPrefix + "."
|
||||
|
|
@ -60,7 +61,7 @@ async function downloadGofmt(octokit, version, versionPrefix, os, org, repo, tok
|
|||
if ((version !== "" && release.name === version) || (!release.prerelease && release.name.startsWith(versionPrefix))) {
|
||||
console.log("Found release " + release.name + " matching criteria, attempting to download binary...")
|
||||
try {
|
||||
await downloadRelease(octokit, os, org, repo, release, token)
|
||||
await downloadRelease(octokit, os, arch, org, repo, release, token)
|
||||
return
|
||||
} catch (e) {
|
||||
tries++
|
||||
|
|
@ -90,6 +91,15 @@ async function determineOS() {
|
|||
return os
|
||||
}
|
||||
|
||||
function determineArch() {
|
||||
switch (processArch) {
|
||||
case "x64":
|
||||
return "amd64";
|
||||
default:
|
||||
return processArch;
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// versionPrefix is the prefix of the version gotestfmt-action supports.
|
||||
|
|
@ -102,7 +112,8 @@ async function main() {
|
|||
auth: token,
|
||||
})
|
||||
const os = await determineOS()
|
||||
await downloadGofmt(octokit, version, versionPrefix, os, org, repo, token)
|
||||
const arch = determineArch()
|
||||
await downloadGofmt(octokit, version, versionPrefix, os, arch, org, repo, token)
|
||||
console.log("Setup complete.")
|
||||
} catch (error) {
|
||||
console.log("Setup failed.")
|
||||
|
|
|
|||
Loading…
Reference in a new issue