mirror of
https://github.com/SonarSource/sonarqube-scan-action.git
synced 2026-06-05 09:00:31 +03:00
SQSCANGHA-88 Deprecate the SONARCLOUD_URL env variable support
Emit a warning when SONARCLOUD_URL is set, directing users to either pass nothing, use SONAR_REGION=us for the US region, or pass -Dsonar.scanner.sonarcloudUrl and -Dsonar.scanner.apiBaseUrl via args for advanced needs. Backward compatibility is preserved. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,85 @@ function mockDependencies(t, { getInputFn, setSecretFn }) {
|
||||
});
|
||||
}
|
||||
|
||||
describe("SONARCLOUD_URL deprecation", () => {
|
||||
it("should warn when SONARCLOUD_URL is set", async (t) => {
|
||||
const warningFn = mock.fn();
|
||||
const getInputFn = mock.fn(() => "");
|
||||
|
||||
t.mock.module("@actions/core", {
|
||||
namedExports: {
|
||||
getInput: getInputFn,
|
||||
getBooleanInput: mock.fn(() => false),
|
||||
setSecret: mock.fn(),
|
||||
setFailed: mock.fn(),
|
||||
info: mock.fn(),
|
||||
warning: warningFn,
|
||||
},
|
||||
});
|
||||
t.mock.module("../install-sonar-scanner.js", {
|
||||
namedExports: { installSonarScanner: mock.fn(async () => "/scanner") },
|
||||
});
|
||||
t.mock.module("../run-sonar-scanner.js", {
|
||||
namedExports: { runSonarScanner: mock.fn(async () => {}) },
|
||||
});
|
||||
t.mock.module("../sanity-checks.js", {
|
||||
namedExports: {
|
||||
validateScannerVersion: mock.fn(),
|
||||
checkSonarToken: mock.fn(),
|
||||
checkMavenProject: mock.fn(),
|
||||
checkGradleProject: mock.fn(),
|
||||
},
|
||||
});
|
||||
|
||||
process.env.SONARCLOUD_URL = "mirror.sonarcloud.io";
|
||||
t.after(() => delete process.env.SONARCLOUD_URL);
|
||||
|
||||
await import("../index.js?test=deprecation-warning");
|
||||
|
||||
assert.equal(warningFn.mock.calls.length, 1);
|
||||
assert.match(
|
||||
warningFn.mock.calls[0].arguments[0],
|
||||
/SONARCLOUD_URL.*deprecated/
|
||||
);
|
||||
});
|
||||
|
||||
it("should not warn when SONARCLOUD_URL is not set", async (t) => {
|
||||
const warningFn = mock.fn();
|
||||
const getInputFn = mock.fn(() => "");
|
||||
|
||||
t.mock.module("@actions/core", {
|
||||
namedExports: {
|
||||
getInput: getInputFn,
|
||||
getBooleanInput: mock.fn(() => false),
|
||||
setSecret: mock.fn(),
|
||||
setFailed: mock.fn(),
|
||||
info: mock.fn(),
|
||||
warning: warningFn,
|
||||
},
|
||||
});
|
||||
t.mock.module("../install-sonar-scanner.js", {
|
||||
namedExports: { installSonarScanner: mock.fn(async () => "/scanner") },
|
||||
});
|
||||
t.mock.module("../run-sonar-scanner.js", {
|
||||
namedExports: { runSonarScanner: mock.fn(async () => {}) },
|
||||
});
|
||||
t.mock.module("../sanity-checks.js", {
|
||||
namedExports: {
|
||||
validateScannerVersion: mock.fn(),
|
||||
checkSonarToken: mock.fn(),
|
||||
checkMavenProject: mock.fn(),
|
||||
checkGradleProject: mock.fn(),
|
||||
},
|
||||
});
|
||||
|
||||
delete process.env.SONARCLOUD_URL;
|
||||
|
||||
await import("../index.js?test=no-deprecation-warning");
|
||||
|
||||
assert.equal(warningFn.mock.calls.length, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getInputs", () => {
|
||||
it("should mask scannerBinariesAuthHeader using setSecret when provided", async (t) => {
|
||||
const setSecretFn = mock.fn();
|
||||
|
||||
+9
-1
@@ -79,7 +79,15 @@ async function run() {
|
||||
const { args, projectBaseDir, scannerVersion, scannerBinariesUrl, scannerBinariesAuthHeader, skipSignatureVerification } =
|
||||
getInputs();
|
||||
const runnerEnv = getEnvVariables();
|
||||
const { sonarToken } = runnerEnv;
|
||||
const { sonarToken, sonarcloudUrl } = runnerEnv;
|
||||
|
||||
if (sonarcloudUrl) {
|
||||
core.warning(
|
||||
"The SONARCLOUD_URL environment variable is deprecated and will be removed in a future version. " +
|
||||
"Regular users should not set it; use SONAR_REGION=us for the US region. " +
|
||||
"For advanced needs, pass -Dsonar.scanner.sonarcloudUrl and -Dsonar.scanner.apiBaseUrl via the args input."
|
||||
);
|
||||
}
|
||||
|
||||
runSanityChecks({ projectBaseDir, scannerVersion, sonarToken });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user