Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Feb 10, 2024
1 parent 110d54c commit 8d25176
Showing 1 changed file with 74 additions and 28 deletions.
102 changes: 74 additions & 28 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -233,19 +236,15 @@ 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);
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"]
Expand All @@ -269,41 +268,51 @@ 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,
});
});
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) {
Expand Down Expand Up @@ -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;


/***/ }),
Expand Down

0 comments on commit 8d25176

Please sign in to comment.