mirror of
https://github.com/GoTestTools/gotestfmt-action.git
synced 2026-02-18 21:51:47 +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 { Octokit } = require("@octokit/rest");
|
||||||
const fs = require("fs")
|
const fs = require("fs")
|
||||||
const { execSync } = require("child_process")
|
const { execSync } = require("child_process")
|
||||||
|
const { arch: processArch } = require("node:process");
|
||||||
|
|
||||||
async function downloadRelease(octokit, os, org, repo, release, token) {
|
async function downloadRelease(octokit, os, arch, org, repo, release, token) {
|
||||||
const postfix = `_${os}_amd64.${os === "windows" ? "zip" : "tar.gz"}`;
|
const postfix = `_${os}_${arch}.${os === "windows" ? "zip" : "tar.gz"}`;
|
||||||
const tempdir = os === "windows" ? process.env.TEMP + "\\" : "/tmp/";
|
const tempdir = os === "windows" ? process.env.TEMP + "\\" : "/tmp/";
|
||||||
const extract = os === "windows" ? "tar -xvf" : "tar -xvzf";
|
const extract = os === "windows" ? "tar -xvf" : "tar -xvzf";
|
||||||
const archive = `${tempdir}gotestfmt${postfix}`;
|
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}'.`
|
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 !== "") {
|
||||||
if (!version.startsWith(versionPrefix)) {
|
if (!version.startsWith(versionPrefix)) {
|
||||||
throw "Specified version " + version + " does not start with required version prefix " + 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))) {
|
if ((version !== "" && release.name === version) || (!release.prerelease && release.name.startsWith(versionPrefix))) {
|
||||||
console.log("Found release " + release.name + " matching criteria, attempting to download binary...")
|
console.log("Found release " + release.name + " matching criteria, attempting to download binary...")
|
||||||
try {
|
try {
|
||||||
await downloadRelease(octokit, os, org, repo, release, token)
|
await downloadRelease(octokit, os, arch, org, repo, release, token)
|
||||||
return
|
return
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
tries++
|
tries++
|
||||||
|
|
@ -90,6 +91,15 @@ async function determineOS() {
|
||||||
return os
|
return os
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function determineArch() {
|
||||||
|
switch (processArch) {
|
||||||
|
case "x64":
|
||||||
|
return "amd64";
|
||||||
|
default:
|
||||||
|
return processArch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
// versionPrefix is the prefix of the version gotestfmt-action supports.
|
// versionPrefix is the prefix of the version gotestfmt-action supports.
|
||||||
|
|
@ -102,7 +112,8 @@ async function main() {
|
||||||
auth: token,
|
auth: token,
|
||||||
})
|
})
|
||||||
const os = await determineOS()
|
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.")
|
console.log("Setup complete.")
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Setup failed.")
|
console.log("Setup failed.")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue