mirror of
https://github.com/SonarSource/sonarqube-scan-action.git
synced 2025-12-12 09:21:16 +00:00
SQSCANGHA-107 Migrate install-build-wrapper
This commit is contained in:
parent
a88c96d7e4
commit
ff001fd600
13 changed files with 27796 additions and 27337 deletions
27277
dist/exec-BTlTa8sL.js
vendored
Normal file
27277
dist/exec-BTlTa8sL.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
dist/exec-BTlTa8sL.js.map
vendored
Normal file
1
dist/exec-BTlTa8sL.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
27314
dist/index.js
vendored
27314
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
207
dist/install-build-wrapper.js
vendored
Normal file
207
dist/install-build-wrapper.js
vendored
Normal file
|
|
@ -0,0 +1,207 @@
|
||||||
|
import { f as execExports, e as coreExports } from './exec-BTlTa8sL.js';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
import * as path from 'path';
|
||||||
|
import 'os';
|
||||||
|
import 'crypto';
|
||||||
|
import 'http';
|
||||||
|
import 'https';
|
||||||
|
import 'net';
|
||||||
|
import 'tls';
|
||||||
|
import 'events';
|
||||||
|
import 'assert';
|
||||||
|
import 'util';
|
||||||
|
import 'stream';
|
||||||
|
import 'buffer';
|
||||||
|
import 'querystring';
|
||||||
|
import 'stream/web';
|
||||||
|
import 'node:stream';
|
||||||
|
import 'node:util';
|
||||||
|
import 'node:events';
|
||||||
|
import 'worker_threads';
|
||||||
|
import 'perf_hooks';
|
||||||
|
import 'util/types';
|
||||||
|
import 'async_hooks';
|
||||||
|
import 'console';
|
||||||
|
import 'url';
|
||||||
|
import 'zlib';
|
||||||
|
import 'string_decoder';
|
||||||
|
import 'diagnostics_channel';
|
||||||
|
import 'child_process';
|
||||||
|
import 'timers';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute all names and paths related to the build wrapper
|
||||||
|
* based on the runner environment
|
||||||
|
*/
|
||||||
|
function getBuildWrapperInfo({
|
||||||
|
runnerOS,
|
||||||
|
runnerArch,
|
||||||
|
runnerTemp,
|
||||||
|
sonarHostUrl,
|
||||||
|
}) {
|
||||||
|
const { buildWrapperSuffix, buildWrapperName } = getSuffixAndName(
|
||||||
|
runnerOS,
|
||||||
|
runnerArch
|
||||||
|
);
|
||||||
|
|
||||||
|
const buildWrapperDir = `${runnerTemp}/build-wrapper-${buildWrapperSuffix}`;
|
||||||
|
const buildWrapperUrl = `${sonarHostUrl}/static/cpp/build-wrapper-${buildWrapperSuffix}.zip`;
|
||||||
|
const buildWrapperBin = `${buildWrapperDir}/${buildWrapperName}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
buildWrapperUrl,
|
||||||
|
buildWrapperDir,
|
||||||
|
buildWrapperBin,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSuffixAndName(runnerOS, runnerArch) {
|
||||||
|
if (
|
||||||
|
runnerArch !== "X64" &&
|
||||||
|
!(runnerArch === "ARM64" && (runnerOS === "macOS" || runnerOS === "Linux"))
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Architecture '${runnerArch}' is unsupported by build-wrapper`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (runnerOS) {
|
||||||
|
case "Windows":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "win-x86",
|
||||||
|
buildWrapperName: "build-wrapper-win-x86-64.exe",
|
||||||
|
};
|
||||||
|
|
||||||
|
case "Linux":
|
||||||
|
switch (runnerArch) {
|
||||||
|
case "X64":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "linux-x86",
|
||||||
|
buildWrapperName: "build-wrapper-linux-x86-64",
|
||||||
|
};
|
||||||
|
|
||||||
|
case "ARM64":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "linux-aarch64",
|
||||||
|
buildWrapperName: "build-wrapper-linux-aarch64",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
break; // handled before the switch
|
||||||
|
|
||||||
|
case "macOS":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "macosx-x86",
|
||||||
|
buildWrapperName: "build-wrapper-macosx-x86",
|
||||||
|
};
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported runner OS '${runnerOS}'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getRealPath(filePath, runnerOS) {
|
||||||
|
switch (runnerOS) {
|
||||||
|
case "Windows": {
|
||||||
|
const windowsResult = await execExports.getExecOutput("cygpath", [
|
||||||
|
"--absolute",
|
||||||
|
"--windows",
|
||||||
|
filePath,
|
||||||
|
]);
|
||||||
|
return windowsResult.stdout.trim();
|
||||||
|
}
|
||||||
|
case "Linux": {
|
||||||
|
const linuxResult = await execExports.getExecOutput("readlink", [
|
||||||
|
"-f",
|
||||||
|
filePath,
|
||||||
|
]);
|
||||||
|
return linuxResult.stdout.trim();
|
||||||
|
}
|
||||||
|
case "macOS": {
|
||||||
|
const macResult = await execExports.getExecOutput("greadlink", ["-f", filePath]);
|
||||||
|
return macResult.stdout.trim();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return path.resolve(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function installMacOSPackages() {
|
||||||
|
if (process.platform === "darwin") {
|
||||||
|
coreExports.info("Installing required packages for macOS");
|
||||||
|
await execExports.exec("brew", ["install", "coreutils"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These RUNNER_XX env variables come from GitHub by default.
|
||||||
|
* See https://docs.github.com/en/actions/reference/workflows-and-actions/variables#default-environment-variables
|
||||||
|
*
|
||||||
|
* If SONAR_HOST_URL is omitted, we assume sonarcloud.io
|
||||||
|
*/
|
||||||
|
function getEnvVariables() {
|
||||||
|
const sonarHostUrl = process.env.SONAR_HOST_URL
|
||||||
|
? process.env.SONAR_HOST_URL.replace(/\/$/, "")
|
||||||
|
: "https://sonarcloud.io";
|
||||||
|
|
||||||
|
return {
|
||||||
|
runnerOS: process.env.RUNNER_OS,
|
||||||
|
runnerArch: process.env.RUNNER_ARCH,
|
||||||
|
runnerTemp: process.env.RUNNER_TEMP,
|
||||||
|
sonarHostUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadAndInstallBuildWrapper(downloadUrl, runnerEnv) {
|
||||||
|
const { runnerArch, runnerOS, runnerTemp } = runnerEnv;
|
||||||
|
const tmpZipPath = path.join(
|
||||||
|
runnerTemp,
|
||||||
|
`build-wrapper-${runnerOS}-${runnerArch}.zip`
|
||||||
|
);
|
||||||
|
|
||||||
|
coreExports.startGroup(`Download ${downloadUrl}`);
|
||||||
|
|
||||||
|
coreExports.info(`Downloading '${downloadUrl}'`);
|
||||||
|
|
||||||
|
if (!fs.existsSync(runnerTemp)) {
|
||||||
|
fs.mkdirSync(runnerTemp, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
await execExports.exec("curl", ["-sSLo", tmpZipPath, downloadUrl]);
|
||||||
|
|
||||||
|
coreExports.info("Decompressing");
|
||||||
|
await execExports.exec("unzip", ["-o", "-d", runnerTemp, tmpZipPath]);
|
||||||
|
|
||||||
|
coreExports.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
await installMacOSPackages();
|
||||||
|
|
||||||
|
const envVariables = getEnvVariables();
|
||||||
|
|
||||||
|
const { buildWrapperBin, buildWrapperDir, buildWrapperUrl } =
|
||||||
|
getBuildWrapperInfo(envVariables);
|
||||||
|
|
||||||
|
await downloadAndInstallBuildWrapper(buildWrapperUrl, envVariables);
|
||||||
|
|
||||||
|
const buildWrapperBinDir = await getRealPath(
|
||||||
|
buildWrapperDir,
|
||||||
|
envVariables.runnerOS
|
||||||
|
);
|
||||||
|
coreExports.addPath(buildWrapperBinDir);
|
||||||
|
coreExports.info(`'${buildWrapperBinDir}' added to the path`);
|
||||||
|
|
||||||
|
const buildWrapperBinPath = await getRealPath(
|
||||||
|
buildWrapperBin,
|
||||||
|
envVariables.runnerOS
|
||||||
|
);
|
||||||
|
coreExports.setOutput("build-wrapper-binary", buildWrapperBinPath);
|
||||||
|
coreExports.info(`'build-wrapper-binary' output set to '${buildWrapperBinPath}'`);
|
||||||
|
} catch (error) {
|
||||||
|
coreExports.setFailed(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
//# sourceMappingURL=install-build-wrapper.js.map
|
||||||
1
dist/install-build-wrapper.js.map
vendored
Normal file
1
dist/install-build-wrapper.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -1,4 +1,4 @@
|
||||||
name: 'Install Build Wrapper for C and C++'
|
name: "Install Build Wrapper for C and C++"
|
||||||
description: >
|
description: >
|
||||||
Download and install the Build Wrapper for C, C++, and Objective-C
|
Download and install the Build Wrapper for C, C++, and Objective-C
|
||||||
projects analyzed with manual config.
|
projects analyzed with manual config.
|
||||||
|
|
@ -8,55 +8,6 @@ branding:
|
||||||
outputs:
|
outputs:
|
||||||
build-wrapper-binary:
|
build-wrapper-binary:
|
||||||
description: "Absolute path to Build Wrapper binary."
|
description: "Absolute path to Build Wrapper binary."
|
||||||
value: ${{ steps.setup-outputs.outputs.build-wrapper-binary }}
|
|
||||||
runs:
|
runs:
|
||||||
using: "composite"
|
using: node20
|
||||||
|
main: ../dist/install-build-wrapper.js
|
||||||
steps:
|
|
||||||
# install packaged required for greadlink and sha256sum command on macOS
|
|
||||||
- name: Install required packages for macOS
|
|
||||||
if: runner.os == 'macOS'
|
|
||||||
shell: bash
|
|
||||||
run: brew install coreutils
|
|
||||||
|
|
||||||
- name: Set SONAR_HOST_URL to 'https://sonarcloud.io'
|
|
||||||
if: env.SONAR_HOST_URL == ''
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
echo "Setting SONAR_HOST_URL to 'https://sonarcloud.io'"
|
|
||||||
echo "SONAR_HOST_URL=https://sonarcloud.io" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Configure paths
|
|
||||||
id: configure_paths
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
OS: ${{ runner.os }}
|
|
||||||
ARCH: ${{ runner.arch }}
|
|
||||||
INSTALL_PATH: ${{ runner.temp }} # TODO: or .sonar, if RUNNER_TEMP creates problem with caching and self-hosted runners
|
|
||||||
run: ${GITHUB_ACTION_PATH}/../scripts/configure_paths.sh >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Download and install Build Wrapper
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
DOWNLOAD_URL: ${{ steps.configure_paths.outputs.build-wrapper-url }}
|
|
||||||
TMP_ZIP_PATH: ${{ runner.temp }}/build-wrapper-${{ inputs.configure_paths.sonar-scanner-version }}-${{ runner.os }}-${{ runner.arch }}.zip
|
|
||||||
INSTALL_PATH: ${{ runner.temp }} # TODO: or .sonar, if RUNNER_TEMP creates problem with caching and self-hosted runners
|
|
||||||
run: ${GITHUB_ACTION_PATH}/../scripts/download.sh
|
|
||||||
|
|
||||||
- name: Setup action outputs
|
|
||||||
id: setup-outputs
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
BUILD_WRAPPER_DIR: ${{ steps.configure_paths.outputs.build-wrapper-dir }}
|
|
||||||
BUILD_WRAPPER_BIN: ${{ steps.configure_paths.outputs.build-wrapper-bin }}
|
|
||||||
run: |
|
|
||||||
source ${GITHUB_ACTION_PATH}/../scripts/utils.sh
|
|
||||||
|
|
||||||
BUILD_WRAPPER_BIN_DIR=$(realpath "${BUILD_WRAPPER_DIR}")
|
|
||||||
echo "${BUILD_WRAPPER_BIN_DIR}" >> $GITHUB_PATH
|
|
||||||
echo "'${BUILD_WRAPPER_BIN_DIR}' added to the path"
|
|
||||||
|
|
||||||
BUILD_WRAPPER_BIN=$(realpath "${BUILD_WRAPPER_BIN}")
|
|
||||||
echo "build-wrapper-binary=${BUILD_WRAPPER_BIN}" >> $GITHUB_OUTPUT
|
|
||||||
echo "'build-wrapper-binary' output set to '${BUILD_WRAPPER_BIN}'"
|
|
||||||
echo "::endgroup::"
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"description": "This SonarSource project, available as a GitHub Action, scans your projects with SonarQube [Server](https://www.sonarsource.com/products/sonarqube/) or [Cloud](https://www.sonarsource.com/products/sonarcloud/).",
|
"description": "This SonarSource project, available as a GitHub Action, scans your projects with SonarQube [Server](https://www.sonarsource.com/products/sonarqube/) or [Cloud](https://www.sonarsource.com/products/sonarcloud/).",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "src/index.js",
|
"main": "src/main/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rollup --config rollup.config.js",
|
"build": "rollup --config rollup.config.js",
|
||||||
"test": "node --test"
|
"test": "node --test"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ import commonjs from "@rollup/plugin-commonjs";
|
||||||
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
input: "src/index.js",
|
input: [
|
||||||
|
"src/main/index.js",
|
||||||
|
"src/install-build-wrapper/install-build-wrapper.js",
|
||||||
|
],
|
||||||
output: {
|
output: {
|
||||||
esModule: true,
|
esModule: true,
|
||||||
dir: "dist",
|
dir: "dist",
|
||||||
|
|
|
||||||
80
src/install-build-wrapper/__tests__/utils.test.js
Normal file
80
src/install-build-wrapper/__tests__/utils.test.js
Normal file
|
|
@ -0,0 +1,80 @@
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { describe, it } from "node:test";
|
||||||
|
import { getBuildWrapperInfo } from "../utils.js";
|
||||||
|
|
||||||
|
describe("getBuildWrapperInfo", () => {
|
||||||
|
const supportedPlatforms = [
|
||||||
|
{
|
||||||
|
platform: "Linux",
|
||||||
|
arch: "X64",
|
||||||
|
expectedSuffix: "linux-x86",
|
||||||
|
expectedName: "build-wrapper-linux-x86-64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "Linux",
|
||||||
|
arch: "ARM64",
|
||||||
|
expectedSuffix: "linux-aarch64",
|
||||||
|
expectedName: "build-wrapper-linux-aarch64",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "Windows",
|
||||||
|
arch: "X64",
|
||||||
|
expectedSuffix: "win-x86",
|
||||||
|
expectedName: "build-wrapper-win-x86-64.exe",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "macOS",
|
||||||
|
arch: "X64",
|
||||||
|
expectedSuffix: "macosx-x86",
|
||||||
|
expectedName: "build-wrapper-macosx-x86",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
platform: "macOS",
|
||||||
|
arch: "ARM64",
|
||||||
|
expectedSuffix: "macosx-x86",
|
||||||
|
expectedName: "build-wrapper-macosx-x86",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const unsupportedPlatforms = [
|
||||||
|
{ platform: "linux", arch: "arm" },
|
||||||
|
{ platform: "openbsd", arch: "X64" },
|
||||||
|
{ platform: undefined, arch: "X64" },
|
||||||
|
{ platform: "Linux", arch: undefined },
|
||||||
|
{ platform: null, arch: "X64" },
|
||||||
|
{ platform: "Linux", arch: null },
|
||||||
|
];
|
||||||
|
|
||||||
|
supportedPlatforms.forEach(
|
||||||
|
({ platform, arch, expectedSuffix, expectedName }) => {
|
||||||
|
it(`returns ${expectedName} for ${platform} ${arch}`, () => {
|
||||||
|
const result = getBuildWrapperInfo({
|
||||||
|
runnerOS: platform,
|
||||||
|
runnerArch: arch,
|
||||||
|
runnerTemp: "/tmp",
|
||||||
|
sonarHostUrl: "https://sonarcloud.io"
|
||||||
|
});
|
||||||
|
assert.equal(result.buildWrapperUrl, `https://sonarcloud.io/static/cpp/build-wrapper-${expectedSuffix}.zip`);
|
||||||
|
assert.equal(result.buildWrapperDir, `/tmp/build-wrapper-${expectedSuffix}`);
|
||||||
|
assert.equal(result.buildWrapperBin, `/tmp/build-wrapper-${expectedSuffix}/${expectedName}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
unsupportedPlatforms.forEach(({ platform, arch }) => {
|
||||||
|
it(`throws for unsupported platform ${platform} ${arch}`, () => {
|
||||||
|
assert.throws(
|
||||||
|
() => getBuildWrapperInfo({
|
||||||
|
runnerOS: platform,
|
||||||
|
runnerArch: arch,
|
||||||
|
runnerTemp: "/tmp",
|
||||||
|
sonarHostUrl: "https://sonarcloud.io"
|
||||||
|
}),
|
||||||
|
(error) => {
|
||||||
|
return error.message.includes('unsupported') || error.message.includes('Unsupported');
|
||||||
|
},
|
||||||
|
`should have thrown for ${platform} ${arch}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
85
src/install-build-wrapper/install-build-wrapper.js
Normal file
85
src/install-build-wrapper/install-build-wrapper.js
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
import * as core from "@actions/core";
|
||||||
|
import * as exec from "@actions/exec";
|
||||||
|
import * as fs from "fs";
|
||||||
|
import * as path from "path";
|
||||||
|
import { getBuildWrapperInfo, getRealPath } from "./utils";
|
||||||
|
|
||||||
|
async function installMacOSPackages() {
|
||||||
|
if (process.platform === "darwin") {
|
||||||
|
core.info("Installing required packages for macOS");
|
||||||
|
await exec.exec("brew", ["install", "coreutils"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These RUNNER_XX env variables come from GitHub by default.
|
||||||
|
* See https://docs.github.com/en/actions/reference/workflows-and-actions/variables#default-environment-variables
|
||||||
|
*
|
||||||
|
* If SONAR_HOST_URL is omitted, we assume sonarcloud.io
|
||||||
|
*/
|
||||||
|
function getEnvVariables() {
|
||||||
|
const sonarHostUrl = process.env.SONAR_HOST_URL
|
||||||
|
? process.env.SONAR_HOST_URL.replace(/\/$/, "")
|
||||||
|
: "https://sonarcloud.io";
|
||||||
|
|
||||||
|
return {
|
||||||
|
runnerOS: process.env.RUNNER_OS,
|
||||||
|
runnerArch: process.env.RUNNER_ARCH,
|
||||||
|
runnerTemp: process.env.RUNNER_TEMP,
|
||||||
|
sonarHostUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadAndInstallBuildWrapper(downloadUrl, runnerEnv) {
|
||||||
|
const { runnerArch, runnerOS, runnerTemp } = runnerEnv;
|
||||||
|
const tmpZipPath = path.join(
|
||||||
|
runnerTemp,
|
||||||
|
`build-wrapper-${runnerOS}-${runnerArch}.zip`
|
||||||
|
);
|
||||||
|
|
||||||
|
core.startGroup(`Download ${downloadUrl}`);
|
||||||
|
|
||||||
|
core.info(`Downloading '${downloadUrl}'`);
|
||||||
|
|
||||||
|
if (!fs.existsSync(runnerTemp)) {
|
||||||
|
fs.mkdirSync(runnerTemp, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
await exec.exec("curl", ["-sSLo", tmpZipPath, downloadUrl]);
|
||||||
|
|
||||||
|
core.info("Decompressing");
|
||||||
|
await exec.exec("unzip", ["-o", "-d", runnerTemp, tmpZipPath]);
|
||||||
|
|
||||||
|
core.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
try {
|
||||||
|
await installMacOSPackages();
|
||||||
|
|
||||||
|
const envVariables = getEnvVariables();
|
||||||
|
|
||||||
|
const { buildWrapperBin, buildWrapperDir, buildWrapperUrl } =
|
||||||
|
getBuildWrapperInfo(envVariables);
|
||||||
|
|
||||||
|
await downloadAndInstallBuildWrapper(buildWrapperUrl, envVariables);
|
||||||
|
|
||||||
|
const buildWrapperBinDir = await getRealPath(
|
||||||
|
buildWrapperDir,
|
||||||
|
envVariables.runnerOS
|
||||||
|
);
|
||||||
|
core.addPath(buildWrapperBinDir);
|
||||||
|
core.info(`'${buildWrapperBinDir}' added to the path`);
|
||||||
|
|
||||||
|
const buildWrapperBinPath = await getRealPath(
|
||||||
|
buildWrapperBin,
|
||||||
|
envVariables.runnerOS
|
||||||
|
);
|
||||||
|
core.setOutput("build-wrapper-binary", buildWrapperBinPath);
|
||||||
|
core.info(`'build-wrapper-binary' output set to '${buildWrapperBinPath}'`);
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
98
src/install-build-wrapper/utils.js
Normal file
98
src/install-build-wrapper/utils.js
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
import * as exec from "@actions/exec";
|
||||||
|
import * as path from "path";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute all names and paths related to the build wrapper
|
||||||
|
* based on the runner environment
|
||||||
|
*/
|
||||||
|
export function getBuildWrapperInfo({
|
||||||
|
runnerOS,
|
||||||
|
runnerArch,
|
||||||
|
runnerTemp,
|
||||||
|
sonarHostUrl,
|
||||||
|
}) {
|
||||||
|
const { buildWrapperSuffix, buildWrapperName } = getSuffixAndName(
|
||||||
|
runnerOS,
|
||||||
|
runnerArch
|
||||||
|
);
|
||||||
|
|
||||||
|
const buildWrapperDir = `${runnerTemp}/build-wrapper-${buildWrapperSuffix}`;
|
||||||
|
const buildWrapperUrl = `${sonarHostUrl}/static/cpp/build-wrapper-${buildWrapperSuffix}.zip`;
|
||||||
|
const buildWrapperBin = `${buildWrapperDir}/${buildWrapperName}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
buildWrapperUrl,
|
||||||
|
buildWrapperDir,
|
||||||
|
buildWrapperBin,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSuffixAndName(runnerOS, runnerArch) {
|
||||||
|
if (
|
||||||
|
runnerArch !== "X64" &&
|
||||||
|
!(runnerArch === "ARM64" && (runnerOS === "macOS" || runnerOS === "Linux"))
|
||||||
|
) {
|
||||||
|
throw new Error(
|
||||||
|
`Architecture '${runnerArch}' is unsupported by build-wrapper`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (runnerOS) {
|
||||||
|
case "Windows":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "win-x86",
|
||||||
|
buildWrapperName: "build-wrapper-win-x86-64.exe",
|
||||||
|
};
|
||||||
|
|
||||||
|
case "Linux":
|
||||||
|
switch (runnerArch) {
|
||||||
|
case "X64":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "linux-x86",
|
||||||
|
buildWrapperName: "build-wrapper-linux-x86-64",
|
||||||
|
};
|
||||||
|
|
||||||
|
case "ARM64":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "linux-aarch64",
|
||||||
|
buildWrapperName: "build-wrapper-linux-aarch64",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
break; // handled before the switch
|
||||||
|
|
||||||
|
case "macOS":
|
||||||
|
return {
|
||||||
|
buildWrapperSuffix: "macosx-x86",
|
||||||
|
buildWrapperName: "build-wrapper-macosx-x86",
|
||||||
|
};
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported runner OS '${runnerOS}'`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getRealPath(filePath, runnerOS) {
|
||||||
|
switch (runnerOS) {
|
||||||
|
case "Windows": {
|
||||||
|
const windowsResult = await exec.getExecOutput("cygpath", [
|
||||||
|
"--absolute",
|
||||||
|
"--windows",
|
||||||
|
filePath,
|
||||||
|
]);
|
||||||
|
return windowsResult.stdout.trim();
|
||||||
|
}
|
||||||
|
case "Linux": {
|
||||||
|
const linuxResult = await exec.getExecOutput("readlink", [
|
||||||
|
"-f",
|
||||||
|
filePath,
|
||||||
|
]);
|
||||||
|
return linuxResult.stdout.trim();
|
||||||
|
}
|
||||||
|
case "macOS": {
|
||||||
|
const macResult = await exec.getExecOutput("greadlink", ["-f", filePath]);
|
||||||
|
return macResult.stdout.trim();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return path.resolve(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { installSonarScanner } from "./main/install-sonar-scanner";
|
import { installSonarScanner } from "./install-sonar-scanner";
|
||||||
import { runSonarScanner } from "./main/run-sonar-scanner";
|
import { runSonarScanner } from "./run-sonar-scanner";
|
||||||
import {
|
import {
|
||||||
checkGradleProject,
|
checkGradleProject,
|
||||||
checkMavenProject,
|
checkMavenProject,
|
||||||
checkSonarToken,
|
checkSonarToken,
|
||||||
validateScannerVersion,
|
validateScannerVersion,
|
||||||
} from "./main/sanity-checks";
|
} from "./sanity-checks";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inputs are defined in action.yml
|
* Inputs are defined in action.yml
|
||||||
Loading…
Reference in a new issue