From 8d25176cd6ef1c72f51547dd3757d0e5ca13d847 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Sat, 10 Feb 2024 10:18:59 -0500 Subject: [PATCH] Build --- dist/index.js | 102 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 28 deletions(-) diff --git a/dist/index.js b/dist/index.js index 47f59fd..9c01c1f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -43,6 +43,9 @@ class ExecStack { .concat(resolverArgs) .concat(args); } + async upgrade() { + return await exec.exec("stack", ["upgrade"]); + } async exec(args, options) { return await exec.exec("stack", this.stackArguments.concat(args), options); } @@ -233,7 +236,6 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -const path = __importStar(__nccwpck_require__(1017)); const core = __importStar(__nccwpck_require__(2186)); const exec_stack_1 = __nccwpck_require__(5927); const get_cache_keys_1 = __nccwpck_require__(1341); @@ -241,11 +243,8 @@ const hash_project_1 = __nccwpck_require__(4717); const inputs_1 = __nccwpck_require__(6180); const parse_stack_path_1 = __nccwpck_require__(1895); const parse_stack_query_1 = __nccwpck_require__(6445); +const stack_yaml_1 = __nccwpck_require__(7703); const with_cache_1 = __nccwpck_require__(4739); -function setOutputs(stackQuery, stackPath) { - core.setOutput("compiler", stackQuery.compiler.actual); - core.setOutput("compiler-version", stackQuery.compiler.actual.replace(/^ghc-/, "")); -} async function dependencies(stack, inputs) { await stack.exec(["setup"].concat(inputs.stackSetupArguments)); await stack.exec(["build", "--dependencies-only", "--test", "--no-run-tests"] @@ -269,21 +268,24 @@ async function run() { core.info(`Change directory: ${inputs.workingDirectory}`); process.chdir(inputs.workingDirectory); } - const stack = new exec_stack_1.ExecStack(inputs.stackYaml, inputs.stackArguments); - const stackPath = await stack.parse(["path"], parse_stack_path_1.parseStackPath); - const stackQuery = await stack.parse(["query"], parse_stack_query_1.parseStackQuery); - setOutputs(stackQuery, stackPath); - const stackWork = path.join(process.cwd(), ".stack-work"); - const stackWorks = (0, parse_stack_query_1.getLocalStackWorks)(stackQuery, [stackWork]); - core.info(`Found .stack-works:\n - ${stackWorks.join("\n - ")}`); const hashes = await (0, hash_project_1.hashProject)(inputs.stackYaml); + core.info(`Snapshot hash ${hashes.snapshot}`); + core.info(`Package hash ${hashes.package}`); + core.info(`Sources hash ${hashes.sources}`); + const stack = new exec_stack_1.ExecStack(inputs.stackYaml, inputs.stackArguments); + await core.group("Stack upgrade", async () => { + await stack.upgrade(); + }); + const stackRoot = (await stack.parse(["path", "--stack-root]"], parse_stack_path_1.parseStackPath))["stack-root"]; + const stackYaml = (0, stack_yaml_1.readStackYamlSync)(inputs.stackYaml); + const stackWorks = (0, stack_yaml_1.packagesStackWorks)(stackYaml); await core.group("Dependencies", async () => { const cacheKeys = (0, get_cache_keys_1.getCacheKeys)([ - inputs.cachePrefix("stack-deps", stackQuery.compiler.actual), + inputs.cachePrefix("stack-deps", stackYaml.resolver), hashes.snapshot, hashes.package, ]); - const cachePaths = [stackPath["stack-root"], stackPath.programs].concat(stackWorks); + const cachePaths = [stackRoot].concat(stackWorks); await (0, with_cache_1.withCache)(cachePaths, cacheKeys, dependencies(stack, inputs), { ...with_cache_1.DEFAULT_CACHE_OPTIONS, skipOnHit: !inputs.cacheSaveAlways, @@ -291,19 +293,26 @@ async function run() { }); await core.group("Build", async () => { const cacheKeys = (0, get_cache_keys_1.getCacheKeys)([ - inputs.cachePrefix("stack-deps", stackQuery.compiler.actual), + inputs.cachePrefix("stack-deps", stackYaml.resolver), hashes.snapshot, hashes.package, hashes.sources, ]); await (0, with_cache_1.withCache)(stackWorks, cacheKeys, build(stack, inputs), { ...with_cache_1.DEFAULT_CACHE_OPTIONS, - skipOnHit: !inputs.cacheSaveAlways, + skipOnHit: false, }); }); if (inputs.test) { await core.group("Test", async () => await test(stack, inputs)); } + const stackQuery = await stack.parse(["query", "compiler"], parse_stack_query_1.parseStackQuery); + core.setOutput("compiler", stackQuery.compiler.actual); + core.setOutput("compiler-version", stackQuery.compiler.actual.replace(/^ghc-/, "")); + const stackPath = await stack.parse(["path"], parse_stack_path_1.parseStackPath); + for (const k in stackPath) { + core.setOutput(k, stackPath[k]); + } } catch (error) { if (error instanceof Error) { @@ -393,24 +402,61 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getLocalStackWorks = exports.parseStackQuery = void 0; -const osPath = __importStar(__nccwpck_require__(1017)); +exports.parseStackQuery = void 0; const yaml = __importStar(__nccwpck_require__(1917)); function parseStackQuery(stdout) { return yaml.load(stdout); } exports.parseStackQuery = parseStackQuery; -function getLocalStackWorks(stackQuery, stackWorks = []) { - for (const k in stackQuery.locals) { - const { path } = stackQuery.locals[k]; - const stackWork = osPath.join(path, ".stack-work"); - if (!stackWorks.includes(stackWork)) { - stackWorks.push(stackWork); - } + + +/***/ }), + +/***/ 7703: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; } - return stackWorks; -} -exports.getLocalStackWorks = getLocalStackWorks; + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.packagesStackWorks = 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); +} +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)); +} +exports.packagesStackWorks = packagesStackWorks; /***/ }),