Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Feb 12, 2024
1 parent e771ab0 commit 2deb790
Showing 1 changed file with 40 additions and 35 deletions.
75 changes: 40 additions & 35 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,22 @@ 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"),
test: core.getBooleanInput("test"),
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;
Expand Down Expand Up @@ -173,18 +176,20 @@ 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}`);
core.info(`Sources: ${hashes.sources}`);
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);
Expand All @@ -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-/, "");
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 2deb790

Please sign in to comment.