Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support installing compiler-tools with dependencies #77

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,23 @@ jobs:

## Inputs

| name | description | required | default |
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------- |
| `working-directory` | <p>Working directory for run commands</p> | `false` | `""` |
| `test` | <p>Whether to run tests</p> | `false` | `true` |
| `stack-arguments` | <p>Additional arguments for all top-level <code>stack</code> command invocations.</p> | `false` | `--no-terminal` |
| `stack-query-arguments` | <p>Additional arguments in <code>stack query</code> invocations.</p> | `false` | `""` |
| `stack-path-arguments` | <p>Additional arguments in <code>stack path</code> invocations.</p> | `false` | `""` |
| `stack-setup-arguments` | <p>Additional arguments in <code>stack setup</code> invocations.</p> | `false` | `""` |
| `stack-build-arguments` | <p>Additional arguments for all <code>stack build</code> invocations.</p> | `false` | `--fast --pedantic` |
| `stack-build-arguments-dependencies` | <p>Additional arguments passed after <code>stack-build-arguments</code> in <code>stack build</code> invocations on the <em>Dependencies</em> step.</p> | `false` | `""` |
| `stack-build-arguments-build` | <p>Additional arguments passed after <code>stack-build-arguments</code> in <code>stack build</code> invocations on the <em>Build</em> step.</p> | `false` | `""` |
| `stack-build-arguments-test` | <p>Additional arguments passed after <code>stack-build-arguments</code> in <code>stack build</code> invocations on the <em>Test</em> step.</p> | `false` | `""` |
| `cache-prefix` | <p>Prefix applied to all cache keys. This can be any value you like, but teams often use <code>v{N}</code> and bump it to <code>v{N+1}</code> when/if they need to explicitly bust caches.</p> | `false` | `""` |
| `cache-save-always` | <p>Save artifacts to the cache even if the build fails. This may speed up builds in subsequent runs at the expense of slightly-longer builds when a full cache-hit occurs. Since <code>@v4.2.0</code></p> | `false` | `false` |
| `upgrade-stack` | <p>Upgrade stack</p> | `false` | `true` |
| `stack-yaml` | <p><strong>Deprecated</strong> use <code>env.STACK_YAML</code> or <code>stack-arguments</code> instead.</p> | `false` | `""` |
| name | description | required | default |
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------- |
| `working-directory` | <p>Working directory for run commands</p> | `false` | `""` |
| `test` | <p>Whether to run tests</p> | `false` | `true` |
| `stack-arguments` | <p>Additional arguments for all top-level <code>stack</code> command invocations.</p> | `false` | `--no-terminal` |
| `stack-query-arguments` | <p>Additional arguments in <code>stack query</code> invocations.</p> | `false` | `""` |
| `stack-path-arguments` | <p>Additional arguments in <code>stack path</code> invocations.</p> | `false` | `""` |
| `stack-setup-arguments` | <p>Additional arguments in <code>stack setup</code> invocations.</p> | `false` | `""` |
| `stack-build-arguments` | <p>Additional arguments for all <code>stack build</code> invocations.</p> | `false` | `--fast --pedantic` |
| `stack-build-arguments-dependencies` | <p>Additional arguments passed after <code>stack-build-arguments</code> in <code>stack build</code> invocations on the <em>Dependencies</em> step.</p> | `false` | `""` |
| `stack-build-arguments-build` | <p>Additional arguments passed after <code>stack-build-arguments</code> in <code>stack build</code> invocations on the <em>Build</em> step.</p> | `false` | `""` |
| `stack-build-arguments-test` | <p>Additional arguments passed after <code>stack-build-arguments</code> in <code>stack build</code> invocations on the <em>Test</em> step.</p> | `false` | `""` |
| `cache-prefix` | <p>Prefix applied to all cache keys. This can be any value you like, but teams often use <code>v{N}</code> and bump it to <code>v{N+1}</code> when/if they need to explicitly bust caches.</p> | `false` | `""` |
| `cache-save-always` | <p>Save artifacts to the cache even if the build fails. This may speed up builds in subsequent runs at the expense of slightly-longer builds when a full cache-hit occurs. Since <code>@v4.2.0</code>.</p> | `false` | `false` |
| `upgrade-stack` | <p>Upgrade stack</p> | `false` | `true` |
| `compiler-tools` | <p>A list of packages to install as compiler tools, one per line. This is useful to do here rather than separate <code>run</code> commands so that their installation is incorporated in the dependency cache. Since <code>@v5.2.0</code>.</p> | `false` | `""` |
| `stack-yaml` | <p><strong>Deprecated</strong> use <code>env.STACK_YAML</code> or <code>stack-arguments</code> instead.</p> | `false` | `""` |

<!-- action-docs-inputs action="action.yml" -->

Expand Down Expand Up @@ -114,6 +115,32 @@ jobs:
| `dist-dir` | <p><code>dist-dir</code> value from <code>stack path</code></p> |
| `local-hpc-root` | <p><code>local-hpc-root</code> value from <code>stack path</code></p> |

## Installing Compiler Tools

The `compiler-tools` input can be used to install packages (with
`--copy-compiler-tool`) as part of the _Dependencies_ step. The installed tools
can be used by other parts of the build via `stack exec`, such as to reformat
and upload coverage:

```yaml
- id: stack
uses: freckle/stack-action@v5
with:
compiler-tools: hpc-lcov
stack-build-arguments: --coverage

- run: stack --no-terminal exec -- hpc-lcov --file "$HPC_ROOT"/combined/all/all.tix
env:
HPC_ROOT: ${{ steps.stack.outputs.local-hpc-root }}

- uses: codecov/codecov-action@v2
with:
files: ./lcov.info
```

Doing it this way, vs a separate `run: stack install...`, means the building of
these tools will be included in the dependencies cache.

## Generating a Build Matrix of `stack.yaml`s

The following automatically discovers all files matching `stack*.yaml` and runs
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,17 @@ inputs:
description: |
Save artifacts to the cache even if the build fails. This may speed up
builds in subsequent runs at the expense of slightly-longer builds when a
full cache-hit occurs. Since `@v4.2.0`
full cache-hit occurs. Since `@v4.2.0`.
default: false
upgrade-stack:
description: |
Upgrade stack
default: true
compiler-tools:
description: |
A list of packages to install as compiler tools, one per line. This is
useful to do here rather than separate `run` commands so that their
installation is incorporated in the dependency cache. Since `@v5.2.0`.
stack-yaml:
description: |
**Deprecated** use `env.STACK_YAML` or `stack-arguments` instead.
Expand Down
8 changes: 8 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ function getInputs() {
cachePrefix: core.getInput("cache-prefix"),
cacheSaveAlways: core.getBooleanInput("cache-save-always"),
upgradeStack: core.getBooleanInput("upgrade-stack"),
compilerTools: core.getMultilineInput("compiler-tools"),
stackYaml: getInputDefault("stack-yaml", null),
};
}
Expand Down Expand Up @@ -230,6 +231,7 @@ async function run() {
await (0, with_cache_1.withCache)([stackRoot, stackPrograms].concat(stackWorks), (0, get_cache_keys_1.getCacheKeys)([`${cachePrefix}/deps`, hashes.snapshot, hashes.package]), async () => {
await stack.setup(inputs.stackSetupArguments);
await stack.buildDependencies(inputs.stackBuildArgumentsDependencies);
await stack.installCompilerTools(inputs.compilerTools);
}, {
...with_cache_1.DEFAULT_CACHE_OPTIONS,
saveOnError: inputs.cacheSaveAlways,
Expand Down Expand Up @@ -432,6 +434,12 @@ class StackCLI {
async setup(args) {
return await this.exec(["setup"].concat(args));
}
async installCompilerTools(tools) {
if (tools.length > 0) {
return await this.exec(["install", "--copy-compiler-tool"].concat(tools));
}
return 0;
}
async buildDependencies(args) {
return await this.buildNoTest(["--dependencies-only"].concat(args));
}
Expand Down
2 changes: 2 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Inputs = {
cachePrefix: string;
cacheSaveAlways: boolean;
upgradeStack: boolean;
compilerTools: string[];

// Deprecated
stackYaml: string | null;
Expand All @@ -38,6 +39,7 @@ export function getInputs(): Inputs {
cachePrefix: core.getInput("cache-prefix"),
cacheSaveAlways: core.getBooleanInput("cache-save-always"),
upgradeStack: core.getBooleanInput("upgrade-stack"),
compilerTools: core.getMultilineInput("compiler-tools"),
stackYaml: getInputDefault("stack-yaml", null),
};
}
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ async function run() {
async () => {
await stack.setup(inputs.stackSetupArguments);
await stack.buildDependencies(inputs.stackBuildArgumentsDependencies);
await stack.installCompilerTools(inputs.compilerTools);
},
{
...DEFAULT_CACHE_OPTIONS,
Expand Down
18 changes: 18 additions & 0 deletions src/stack-cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ describe("StackCLI", () => {
);
});

test("installCompilerTools", async () => {
const stackCLI = new StackCLI([], false);
await stackCLI.installCompilerTools(["hlint", "weeder"]);

expect(exec.exec).toHaveBeenCalledWith(
"stack",
["install", "--copy-compiler-tool", "hlint", "weeder"],
undefined,
);
});

test("installCompilerTools with empty arguments", async () => {
const stackCLI = new StackCLI([], false);
await stackCLI.installCompilerTools([]);

expect(exec.exec).not.toHaveBeenCalled();
});

test("buildDependencies", async () => {
const stackCLI = new StackCLI([], false);

Expand Down
9 changes: 9 additions & 0 deletions src/stack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export class StackCLI {
return await this.exec(["setup"].concat(args));
}

async installCompilerTools(tools: string[]): Promise<number> {
if (tools.length > 0) {
return await this.exec(["install", "--copy-compiler-tool"].concat(tools));
}

// No tools to install
return 0;
}

async buildDependencies(args: string[]): Promise<number> {
return await this.buildNoTest(["--dependencies-only"].concat(args));
}
Expand Down
Loading