From 2deb79073d9f6a5e6a78a9d940aba3cb1dc1ec07 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Mon, 12 Feb 2024 08:48:32 -0500 Subject: [PATCH] Build --- dist/index.js | 75 +++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/dist/index.js b/dist/index.js index 60bbbb8..af4cbe3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -102,6 +102,9 @@ exports.getInputs = void 0; const core = __importStar(__nccwpck_require__(2186)); const Shellwords = __importStar(__nccwpck_require__(8519)); function getInputs() { + const getBuildArguments = (step) => { + return getShellWordsInput("stack-build-arguments").concat(getShellWordsInput(`stack-build-arguments-${step}`)); + }; return { workingDirectory: getInputDefault("working-directory", null), stackYaml: getInputDefault("stack-yaml", "stack.yaml"), @@ -109,12 +112,12 @@ function getInputs() { stackArguments: getShellWordsInput("stack-arguments"), stackSetupArguments: getShellWordsInput("stack-setup-arguments"), stackQueryArguments: getShellWordsInput("stack-query-arguments"), - stackBuildArguments: getShellWordsInput("stack-build-arguments"), - stackBuildArgumentsDependencies: getShellWordsInput("stack-build-arguments-dependencies"), - stackBuildArgumentsBuild: getShellWordsInput("stack-build-arguments-build"), - stackBuildArgumentsTest: getShellWordsInput("stack-build-arguments-test"), + stackBuildArgumentsDependencies: getBuildArguments("dependencies"), + stackBuildArgumentsBuild: getBuildArguments("build"), + stackBuildArgumentsTest: getBuildArguments("test"), cachePrefix: core.getInput("cache-prefix"), cacheSaveAlways: core.getBooleanInput("cache-save-always"), + noUpgradeStack: core.getBooleanInput("no-upgrade-stack"), }; } exports.getInputs = getInputs; @@ -173,7 +176,7 @@ async function run() { core.debug(`Change directory: ${inputs.workingDirectory}`); process.chdir(inputs.workingDirectory); } - const hashes = await core.group("Calculate hashes", async () => { + const hashes = await core.group(":hash: Calculate hashes", async () => { const hashes = await (0, hash_project_1.hashProject)(inputs.stackYaml); core.info(`Snapshot: ${hashes.snapshot}`); core.info(`Packages: ${hashes.package}`); @@ -181,10 +184,12 @@ async function run() { return hashes; }); const stack = new stack_cli_1.StackCLI(inputs.stackYaml, inputs.stackArguments, core.isDebug()); - await core.group("Upgrade stack", async () => { - await stack.upgrade(); - }); - const { stackYaml, stackRoot, stackWorks } = await core.group("Determine stack directories", async () => { + if (!inputs.noUpgradeStack) { + await core.group(":arrow_up: Upgrade stack", async () => { + await stack.upgrade(); + }); + } + const { stackYaml, stackRoot, stackWorks } = await core.group(":file_folder: Determine stack directories", async () => { const stackRoot = (await stack.read(["path", "--stack-root"])).trim(); core.info(`Stack root: ${stackRoot}`); const stackYaml = (0, stack_yaml_1.readStackYamlSync)(inputs.stackYaml); @@ -193,39 +198,34 @@ async function run() { return { stackYaml, stackRoot, stackWorks }; }); const cachePrefix = `${inputs.cachePrefix}${process.platform}/${stackYaml.resolver}`; - await core.group("Setup and install dependencies", async () => { - const cacheKeys = (0, get_cache_keys_1.getCacheKeys)([ - `${cachePrefix}/deps`, - hashes.snapshot, - hashes.package, - ]); - const cachePaths = [stackRoot].concat(stackWorks); - await (0, with_cache_1.withCache)(cachePaths, cacheKeys, async () => { + await core.group(":gear: Setup and install dependencies", async () => { + await (0, with_cache_1.withCache)([stackRoot].concat(stackWorks), (0, get_cache_keys_1.getCacheKeys)([`${cachePrefix}/deps`, hashes.snapshot, hashes.package]), async () => { await stack.setup(inputs.stackSetupArguments); - await stack.buildDependencies(inputs.stackBuildArguments.concat(inputs.stackBuildArgumentsDependencies)); + await stack.buildDependencies(inputs.stackBuildArgumentsDependencies); }, { ...with_cache_1.DEFAULT_CACHE_OPTIONS, skipOnHit: !inputs.cacheSaveAlways, }); }); - await core.group("Build", async () => { - const cacheKeys = (0, get_cache_keys_1.getCacheKeys)([ + await core.group(":building_construction: Build", async () => { + await (0, with_cache_1.withCache)(stackWorks, (0, get_cache_keys_1.getCacheKeys)([ `${cachePrefix}/build`, hashes.snapshot, hashes.package, hashes.sources, - ]); - await (0, with_cache_1.withCache)(stackWorks, cacheKeys, async () => await stack.buildNoTest(inputs.stackBuildArguments.concat(inputs.stackBuildArgumentsBuild)), { + ]), async () => { + await stack.buildNoTest(inputs.stackBuildArgumentsBuild); + }, { ...with_cache_1.DEFAULT_CACHE_OPTIONS, skipOnHit: false, }); }); - await core.group("Test", async () => { - if (inputs.test) { - await stack.buildTest(inputs.stackBuildArguments.concat(inputs.stackBuildArgumentsTest)); - } - }); - await core.group("Set outputs", async () => { + if (inputs.test) { + await core.group(":detective: Test", async () => { + await stack.buildTest(inputs.stackBuildArgumentsTest); + }); + } + await core.group(":incoming_envelope: Set outputs", async () => { const stackQuery = await stack.query(); const compiler = stackQuery.compiler.actual; const compilerVersion = compiler.replace(/^ghc-/, ""); @@ -468,20 +468,25 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.packagesStackWorks = exports.readStackYamlSync = void 0; +exports.packagesStackWorks = exports.parseStackYaml = exports.readStackYamlSync = void 0; const fs = __importStar(__nccwpck_require__(7147)); const path_1 = __nccwpck_require__(1017); const yaml = __importStar(__nccwpck_require__(1917)); function readStackYamlSync(path) { const contents = fs.readFileSync(path, { encoding: "utf-8" }); - return yaml.load(contents); + return parseStackYaml(contents); } exports.readStackYamlSync = readStackYamlSync; -function packagesStackWorks(stackYaml) { - const cwd = process.cwd(); - return [".stack-work"] - .concat((stackYaml.packages ?? []).map((p) => (0, path_1.join)(p, ".stack-work"))) - .map((sw) => (0, path_1.join)(cwd, sw)); +function parseStackYaml(contents) { + return yaml.load(contents); +} +exports.parseStackYaml = parseStackYaml; +function packagesStackWorks(stackYaml, workingDirectory) { + const cwd = workingDirectory ?? process.cwd(); + const packageStackWorks = (stackYaml.packages ?? []) + .filter((p) => p !== ".") + .map((p) => (0, path_1.join)(cwd, p, ".stack-work")); + return [(0, path_1.join)(cwd, ".stack-work")].concat(packageStackWorks); } exports.packagesStackWorks = packagesStackWorks;