Skip to content

Commit

Permalink
Add class for maintaining hie.yaml
Browse files Browse the repository at this point in the history
If `hie.yaml` exists, install `implicit-hie` and update it with
`gen-hie` as part of the build. Next, we'll incorporate it into the
`on-dirty-files` check.
  • Loading branch information
pbrisbin committed Jan 16, 2025
1 parent 53aff32 commit d6fc05e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Empty file added example/hie.yaml
Empty file.
47 changes: 47 additions & 0 deletions src/hie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as fs from "fs";
import * as core from "@actions/core";

import { StackCLI } from "./stack-cli";

export const HIE_YAML: string = "hie.yaml";

export class GenHIE {
public readonly path: string;

private readonly stack: StackCLI;
private readonly exists: boolean;
private installed: boolean;

constructor(stack: StackCLI, path?: string) {
this.stack = stack;
this.path = path ? path : HIE_YAML;
this.exists = fs.existsSync(this.path);
this.installed = false;
}

async install(): Promise<void> {
if (this.exists) {
try {
await this.stack.installCompilerTools(["implicit-hie"]);
this.installed = true;
} catch {
core.warning(
`Failed to install implicit-hie, ${this.path} will not be maintained`,
);
}
}
}

async generate(): Promise<void> {
if (this.exists && this.installed) {
const contents = await this.stack.read([
"exec",
"--",
"gen-hie",
"--stack",
]);

fs.writeFileSync(this.path, contents);
}
}
}
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { hashProject } from "./hash-project";
import { getInputs } from "./inputs";
import { readStackYamlSync, getStackDirectories } from "./stack-yaml";
import { DEFAULT_CACHE_OPTIONS, withCache } from "./with-cache";
import { GenHIE } from "./hie";

async function run() {
try {
Expand All @@ -28,6 +29,7 @@ async function run() {
}

const stack = new StackCLI(inputs.stackArguments, core.isDebug());
const genHIE = new GenHIE(stack);

await core.group("Install/upgrade stack", async () => {
const installed = await stack.installed();
Expand Down Expand Up @@ -98,6 +100,7 @@ async function run() {
await stack.setup(inputs.stackSetupArguments);
await stack.buildDependencies(inputs.stackBuildArgumentsDependencies);
await stack.installCompilerTools(inputs.compilerTools);
await genHIE.install();
},
{
...DEFAULT_CACHE_OPTIONS,
Expand Down Expand Up @@ -126,6 +129,10 @@ async function run() {
);
});

await core.group(`Maintain ${genHIE.path}`, async () => {
await genHIE.generate();
});

await core.group("Check for dirty files", async () => {
await checkDirtyFiles(inputs.onDirtyFiles);
});
Expand Down

0 comments on commit d6fc05e

Please sign in to comment.