From 7b1370fb8eded9b6b787d8c2fc9dce313c7c3278 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Mon, 8 Sep 2025 23:07:10 -0700 Subject: [PATCH 1/4] Fix an issue in getCMakeBinDir function --- src/setup-build-tools/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup-build-tools/index.js b/src/setup-build-tools/index.js index 7da6f48..a411144 100644 --- a/src/setup-build-tools/index.js +++ b/src/setup-build-tools/index.js @@ -33,7 +33,7 @@ async function getLatestCMakeVersion(githubToken) { } function getCMakeBinDir(cmakePath, platform) { - if (platform === 'darwin') { + if (platform === 'macos') { const macOsBinPath = path.join(cmakePath, 'CMake.app', 'Contents', 'bin'); if (fs.existsSync(macOsBinPath)) { return macOsBinPath; From ef927d0bc1334e130f876cf7c9147a01e7e7e1fa Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Tue, 9 Sep 2025 10:17:53 -0700 Subject: [PATCH 2/4] stash --- src/format-lint-check/index.js | 3 ++- src/setup-build-tools/index.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/format-lint-check/index.js b/src/format-lint-check/index.js index ea738d6..e1b37a2 100644 --- a/src/format-lint-check/index.js +++ b/src/format-lint-check/index.js @@ -6,6 +6,7 @@ const path = require('node:path'); const fs = require('node:fs/promises'); const crypto = require('node:crypto'); const os = require('node:os'); +const { addPath } = require('../common/ci'); // --- SHA256 Verification Helper --- /** @@ -142,7 +143,7 @@ async function run() { throw new Error(`LLVM 'bin' directory not found at: ${llvmBinPath}`); } core.info(`Adding LLVM bin directory to PATH: ${llvmBinPath}`); - core.addPath(llvmBinPath); + addPath(llvmBinPath); try { // Verify clang-format exists in PATH *and* store the command name/path // Use 'which' to confirm it's findable and potentially get full path if needed later diff --git a/src/setup-build-tools/index.js b/src/setup-build-tools/index.js index a411144..cfd93d2 100644 --- a/src/setup-build-tools/index.js +++ b/src/setup-build-tools/index.js @@ -8,6 +8,7 @@ const os = require('node:os'); // Import shared utilities const { executeCommand, verifySHA512, getPlatformIdentifier, getArchIdentifier } = require('../common/utils'); +const { addPath, exportVariable } = require('../common/ci'); // --- CMake Specific Helper --- async function getLatestCMakeVersion(githubToken) { @@ -338,7 +339,7 @@ async function run() { if (addCMakeToPath) { core.info(`Adding ${cmakeBinPath} to PATH.`); - core.addPath(cmakeBinPath); + addPath(cmakeBinPath); // Verify Installation via PATH await core.group('Verifying CMake installation via PATH', async () => { @@ -383,7 +384,7 @@ async function run() { // Set vcpkg Environment Variable & Output core.info(`Setting VCPKG_INSTALLATION_ROOT to ${finalVcpkgPath}`); - core.exportVariable('VCPKG_INSTALLATION_ROOT', finalVcpkgPath); + exportVariable('VCPKG_INSTALLATION_ROOT', finalVcpkgPath); core.setOutput('vcpkg-root', finalVcpkgPath); core.info('vcpkg setup complete.'); core.endGroup(); // End vcpkg setup group From c3b5a02d47fedb82f3c0addc1a7d11fe392f26a0 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Tue, 9 Sep 2025 10:20:26 -0700 Subject: [PATCH 3/4] stash --- src/common/utils.js | 37 ++++++++++++++++++++++++++++++++++ src/format-lint-check/index.js | 2 +- src/setup-build-tools/index.js | 3 +-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/common/utils.js b/src/common/utils.js index 50d77d5..f030b9d 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -8,6 +8,41 @@ const path = require('node:path'); const glob = require('@actions/glob'); const { XMLParser, XMLValidator } = require('fast-xml-parser'); +// --- CI/CD Agnostic Helpers --- + +const isGitHub = process.env.GITHUB_ACTIONS === 'true'; + +/** + * Sets an environment variable for the current and subsequent actions in the job. + * The variable will be available to scripts running in the job. + * + * @param {string} name The name of the environment variable. + * @param {string} value The value of the environment variable. + */ +function exportVariable(name, value) { + if (isGitHub) { + core.exportVariable(name, value); + } else { + // Azure DevOps logging command to set a variable + console.log(`##vso[task.setvariable variable=${name}]${value}`); + } +} + +/** + * Adds a directory to the system's PATH environment variable for the current and subsequent actions in the job. + * + * @param {string} path The directory to add to the PATH. + */ +function addPath(path) { + if (isGitHub) { + core.addPath(path); + } else { + // Azure DevOps logging command to prepend a path + console.log(`##vso[task.prependpath]${path}`); + } +} + + // --- Execution Helper --- /** @@ -455,4 +490,6 @@ module.exports = { getArchIdentifier, checkPathExists, generateTestSummary, + exportVariable, + addPath, }; diff --git a/src/format-lint-check/index.js b/src/format-lint-check/index.js index e1b37a2..884b348 100644 --- a/src/format-lint-check/index.js +++ b/src/format-lint-check/index.js @@ -6,7 +6,7 @@ const path = require('node:path'); const fs = require('node:fs/promises'); const crypto = require('node:crypto'); const os = require('node:os'); -const { addPath } = require('../common/ci'); +const { addPath } = require('../common/utils'); // --- SHA256 Verification Helper --- /** diff --git a/src/setup-build-tools/index.js b/src/setup-build-tools/index.js index cfd93d2..45c2bb9 100644 --- a/src/setup-build-tools/index.js +++ b/src/setup-build-tools/index.js @@ -7,8 +7,7 @@ const fs = require('node:fs'); const os = require('node:os'); // Import shared utilities -const { executeCommand, verifySHA512, getPlatformIdentifier, getArchIdentifier } = require('../common/utils'); -const { addPath, exportVariable } = require('../common/ci'); +const { executeCommand, verifySHA512, getPlatformIdentifier, getArchIdentifier, addPath, exportVariable } = require('../common/utils'); // --- CMake Specific Helper --- async function getLatestCMakeVersion(githubToken) { From 36cbb0849e68552703d7b32bb65c6d2bc1ecb01b Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Tue, 9 Sep 2025 10:26:28 -0700 Subject: [PATCH 4/4] update --- test/setup-build-tools/index.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/setup-build-tools/index.test.js b/test/setup-build-tools/index.test.js index 8d090be..3960bd9 100644 --- a/test/setup-build-tools/index.test.js +++ b/test/setup-build-tools/index.test.js @@ -15,13 +15,13 @@ describe('getCMakeBinDir', () => { const cmakePath = '/path/to/cmake'; const macOsBinPath = path.join(cmakePath, 'CMake.app', 'Contents', 'bin'); fs.existsSync.mockReturnValue(true); - expect(getCMakeBinDir(cmakePath, 'darwin')).toBe(macOsBinPath); + expect(getCMakeBinDir(cmakePath, 'macos')).toBe(macOsBinPath); }); it('should return the default bin path for macos when the specific path does not exist', () => { const cmakePath = '/path/to/cmake'; const expectedPath = path.join(cmakePath, 'bin'); fs.existsSync.mockReturnValue(false); - expect(getCMakeBinDir(cmakePath, 'darwin')).toBe(expectedPath); + expect(getCMakeBinDir(cmakePath, 'macos')).toBe(expectedPath); }); });