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

Break up stack-arguments, prep v5 #36

Merged
merged 10 commits into from
Feb 5, 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
48 changes: 30 additions & 18 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,45 @@ jobs:
- macOS-latest
- windows-latest

resolver:
- nightly # ghc-9.4 (as of writing)
- lts # ghc-9.2 (as of writing)
- lts-20.2 # ghc-9.2
- lts-19.33 # ghc-9.0
- lts-18.28 # ghc-8.10
- lts-16.31 # ghc-8.8
- lts-12.26 # ghc-8.4
stack:
- resolver: nightly
- resolver: lts
- resolver: lts-22.7
ghc: "9.6.4"
- resolver: lts-20.2
ghc: "9.2.5"
- resolver: lts-19.33
ghc: "9.0.2"
- resolver: lts-18.28
ghc: "8.10.7"
- resolver: lts-16.31
ghc: "8.8.4"
- resolver: lts-12.26
ghc: "8.4.4"

fail-fast: false

runs-on: ${{ matrix.runner }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: stack
uses: ./
with:
working-directory: example
stack-arguments: --resolver ${{ matrix.resolver }}
cache-prefix: ${{ matrix.resolver }}/
stack-arguments: --resolver ${{ matrix.stack.resolver }}
cache-prefix: ${{ matrix.stack.resolver }}/

- if: ${{ runner.os != 'windows' }}
- name: Check compiler[-*] outputs
if: matrix.stack.ghc
shell: bash
run: |
[[ "${{ steps.stack.outputs.compiler }}" = "ghc-8.10.4" ]]
[[ "${{ steps.stack.outputs.compiler-version }}" = "8.10.4" ]]
[[ "${{ steps.stack.outputs.compiler }}" = ghc-${{ matrix.stack.ghc }} ]]
[[ "${{ steps.stack.outputs.compiler-version }}" = ${{ matrix.stack.ghc }} ]]

- name: Check presence of other outputs
shell: bash
run: |
# stack path | cut -d: -f1
[[ -n "${{ steps.stack.outputs.snapshot-doc-root }}" ]]
[[ -n "${{ steps.stack.outputs.local-doc-root }}" ]]
Expand Down Expand Up @@ -79,7 +91,7 @@ jobs:
test-generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: generate
uses: ./generate-matrix
with:
Expand All @@ -97,7 +109,7 @@ jobs:
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./
with:
working-directory: example
Expand All @@ -106,7 +118,7 @@ jobs:
test-auto-nightly:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: stack
uses: ./
with:
Expand All @@ -117,7 +129,7 @@ jobs:
test-auto-nightly-with-explicit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: stack
uses: ./
with:
Expand Down
162 changes: 81 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Stack Action

GitHub Action to build, test, and lint a stack-based Haskell project.
GitHub Action to build and test a stack-based Haskell project.

## Usage

Expand All @@ -9,89 +9,33 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: freckle/stack-action@v4
- uses: actions/checkout@v4
- uses: freckle/stack-action@v5
```

**NOTE**: as of version 4, this action automatically handles caching. You do not
need to use a separate `stack-cache-action` step any more.
## Notable Changes in v5

## Inputs

- `working-directory`: working directory for all `run` steps.

Useful for a multi-project repository.

- `stack-yaml`: path to use instead of `stack.yaml`.

Expected to be relative to `working-directory`.

- `fast`: pass `--fast` to stack build/test (default `true`).

You probably want to disable `--fast` if building executables for
deployment. Assuming that happens on your default branch, you could
do:

```yaml
with:
fast: ${{ github.ref != 'refs/heads/main' }}
```

- `pedantic`: pass `--pedantic` to stack build/test (default `true`).

- `test`: whether tests should be executed (default `true`).

- `stack-arguments`: additional arguments for stack invocation.

Default is none, except if `stack-yaml` is the string `"stack-nightly.yaml"`,
in which case `--resolver nightly` will be used.

- `cache-prefix`: prefix applied to all cache keys. This can be any value you
like, but teams often use `v{N}` and bump it to `v{N+1}` when/if they need to
explicitly bust caches. The default is empty.
As of version 5, the single `stack-arguments` input has been broken up into
various, distinct `stack-[*-]arguments[-*]` inputs that are used in more
specific ways. See the _Inputs_ section, or `action.yml` for documentation of
the new options.

- `cache-save-always`: 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`)

## Outputs

`compiler` (e.g. `ghc-9.2.5`) and `compiler-version` (e.g. `9.2.5`) are set from
the output of `stack query compiler actual`. This can be useful when downstream
actions depend on it:
The `fast` and `pedantic` inputs were removed. Use a ternary operator (see [Operators](https://docs.github.com/en/actions/learn-github-actions/expressions#operators)) to pass a flag conditionally. Example:

```yaml
- id: stack
uses: freckle/stack-action@v4
- uses: freckle/weeder-action@v2
with:
ghc-version: ${{ steps.stack.outputs.compiler-version }}
stack-build-arguments: ${{ github.ref_name != 'main' && '--fast' || '' }} --pedantic
```

Every value from `stack path` is set as itself as an output. This can be useful,
for example, to upload executables or coverage reports:
## Notable Changes in v4

```yaml
- id: stack
uses: freckle/stack-action@v4
with:
stack-arguments: --copy-bins --coverage

- uses: actions/upload-artifact@v2
with:
name: executable
path: ${{ steps.stack.outputs.local-bin-path }}/my-exe

- uses: actions/upload-artifact@v2
with:
name: coverage-report
path: ${{ steps.stack.outputs.local-hpc-root }}/index.html
```
As of version 4, this action automatically handles caching. You do not need to
use a separate `stack-cache-action` step any more.

## HLint & Weeder
## Notable Changes in v3

Previous versions of this Action ran HLint and Weeder for you. We recommend
doing that as separate actions now, so those options have been removed.
doing that as separate actions now, so, as of `v3, those options have been
removed.

Here is an example of running separate Actions:

Expand All @@ -100,9 +44,9 @@ jobs:
test:
# ...
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: stack
uses: freckle/stack-action@v4
uses: freckle/stack-action@v5

# Weeder requires running in the same Job (to access .hie artifacts)
- uses: freckle/weeder-action@v2
Expand All @@ -113,11 +57,66 @@ jobs:
hlint:
# ...
steps:
- uses: actions/checkout@v3
- uses: haskell/actions/hlint-setup@v1
- uses: haskell/actions/hlint-run@v2
- uses: actions/checkout@v4
- uses: haskell-actions/hlint-setup@v1
- uses: haskell-actions/hlint-run@v2
```

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

## Inputs

| name | description | required | default |
| ------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------- |
| `working-directory` | <p>Working directory for run commands</p> | `false` | `.` |
| `stack-yaml` | <p>Override stack.yaml, relative to working-directory</p> | `false` | `stack.yaml` |
| `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` |

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

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

## Outputs

| name | description |
| ----------------------- | ---------------------------------------------------------------------------- |
| `compiler` | <p><code>compiler.actual</code> value from stack query</p> |
| `compiler-version` | <p>The GHC version part of compiler</p> |
| `snapshot-doc-root` | <p><code>snapshot-doc-root</code> value from <code>stack path</code></p> |
| `local-doc-root` | <p><code>local-doc-root</code> value from <code>stack path</code></p> |
| `local-hoogle-root` | <p><code>local-hoogle-root</code> value from <code>stack path</code></p> |
| `stack-root` | <p><code>stack-root</code> value from <code>stack path</code></p> |
| `project-root` | <p><code>project-root</code> value from <code>stack path</code></p> |
| `config-location` | <p><code>config-location</code> value from <code>stack path</code></p> |
| `bin-path` | <p><code>bin-path</code> value from <code>stack path</code></p> |
| `programs` | <p><code>programs</code> value from <code>stack path</code></p> |
| `compiler-exe` | <p><code>compiler-exe</code> value from <code>stack path</code></p> |
| `compiler-bin` | <p><code>compiler-bin</code> value from <code>stack path</code></p> |
| `compiler-tools-bin` | <p><code>compiler-tools-bin</code> value from <code>stack path</code></p> |
| `local-bin` | <p><code>local-bin</code> value from <code>stack path</code></p> |
| `extra-include-dirs` | <p><code>extra-include-dirs</code> value from <code>stack path</code></p> |
| `extra-library-dirs` | <p><code>extra-library-dirs</code> value from <code>stack path</code></p> |
| `snapshot-pkg-db` | <p><code>snapshot-pkg-db</code> value from <code>stack path</code></p> |
| `local-pkg-db` | <p><code>local-pkg-db</code> value from <code>stack path</code></p> |
| `global-pkg-db` | <p><code>global-pkg-db</code> value from <code>stack path</code></p> |
| `ghc-package-path` | <p><code>ghc-package-path</code> value from <code>stack path</code></p> |
| `snapshot-install-root` | <p><code>snapshot-install-root</code> value from <code>stack path</code></p> |
| `local-install-root` | <p><code>local-install-root</code> value from <code>stack path</code></p> |
| `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> |

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

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

The following automatically discovers all files matching `stack*.yaml` and runs
Expand All @@ -128,9 +127,9 @@ jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- id: generate
uses: freckle/stack-action/generate-matrix@v4
uses: freckle/stack-action/generate-matrix@v5
outputs:
stack-yamls: ${{ steps.generate.outputs.stack-yamls }}

Expand All @@ -143,13 +142,14 @@ jobs:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: freckle/stack-action@v4
- uses: actions/checkout@v4
- uses: freckle/stack-action@v5
with:
stack-yaml: ${{ matrix.stack-yaml }}
```

See [generate-matrix/action.yml](./generate-matrix/action.yml) for more details.
This has been available since version 4 of this action.

---

Expand Down
Loading