Skip to content

Commit

Permalink
Implement subcommand-specific options
Browse files Browse the repository at this point in the history
The `stack-arguments` option preceding this was too limited. It could be
used for global arguments to `stack` as well as arguments to `stack
build`, this made it impossible to use the input consistently across all
`stack` commands we happen to invoke.

The new interface separates:

- `stack-arguments` for globals arguments, used in all invocations from
- `stack-build-arguments` for all `stack build` invocations from
- `stack-build-arguments-{step}` for _specific_ `stack build` invocations and, finally
- `stack-{subcommand}-arguments` for other invocations
  • Loading branch information
deemp authored and pbrisbin committed Feb 5, 2024
1 parent 178359c commit 4b7c98e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 58 deletions.
40 changes: 25 additions & 15 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ 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

Expand All @@ -41,14 +48,17 @@ jobs:
uses: ./
with:
working-directory: example
stack-arguments: --resolver ${{ matrix.resolver }}
cache-prefix: ${{ matrix.resolver }}/

- if: ${{ runner.os != 'windows' }}
stack-arguments: --resolver ${{ matrix.stack.resolver }}
cache-prefix: ${{ matrix.stack.resolver }}/

- if: matrix.stack.ghc
shell: bash
run: |
[[ "${{ steps.stack.outputs.compiler }}" = ghc-${{ matrix.stack.ghc }} ]]
[[ "${{ steps.stack.outputs.compiler-version }}" = ${{ matrix.stack.ghc }} ]]
- shell: bash
run: |
[[ "${{ steps.stack.outputs.compiler }}" = "ghc-8.10.4" ]]
[[ "${{ steps.stack.outputs.compiler-version }}" = "8.10.4" ]]
# stack path | cut -d: -f1
[[ -n "${{ steps.stack.outputs.snapshot-doc-root }}" ]]
[[ -n "${{ steps.stack.outputs.local-doc-root }}" ]]
Expand Down
124 changes: 81 additions & 43 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,40 @@ inputs:
description: "Override stack.yaml, relative to working-directory"
required: true
default: stack.yaml
fast:
description: "Pass --fast in build/test"
required: true
default: true
pedantic:
description: "Pass --pedantic in build/test"
required: true
default: true
test:
description: Whether to run tests
required: false
default: true
stack-arguments:
description: "Additional arguments for stack invocations"
description: "Additional arguments for all top-level `stack` command invocations."
required: true
default: "--no-terminal"
stack-query-arguments:
description: "Additional arguments in `stack query` invocations."
required: true
default: ""
stack-path-arguments:
description: "Additional arguments in `stack path` invocations."
required: true
default: ""
stack-setup-arguments:
description: "Additional arguments in `stack setup` invocations."
required: true
default: ""
stack-build-arguments:
description: "Additional arguments for all `stack build` invocations."
required: true
default: "--fast --pedantic"
stack-build-arguments-dependencies:
description: "Additional arguments passed after `stack-build-arguments` in `stack build` invocations on the `Dependencies` step."
required: true
default: ""
stack-build-arguments-build:
description: "Additional arguments passed after `stack-build-arguments` in `stack build` invocations on the `Build` step."
required: true
default: ""
stack-build-arguments-test:
description: "Additional arguments passed after `stack-build-arguments` in `stack build` invocations on the `Test` step."
required: true
default: ""
cache-prefix:
Expand Down Expand Up @@ -112,31 +132,54 @@ runs:
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
resolver_nightly=
# Extra arguments for build and test steps, not the dependencies step
stack_build_arguments=()
if ${{ inputs.fast }}; then
stack_build_arguments+=( --fast )
fi
if ${{ inputs.pedantic }}; then
stack_build_arguments+=( --pedantic )
fi
# Accept newline-separated content on stdin and set it as the given
# output with those newlines replaced by spaces.
set_trimmed_output() {
{ printf '%s=' "$1"; tr '\n' ' '; echo; } >>"$GITHUB_OUTPUT"
}
# Check if stack-arguments is specifying --resolver
has_resolver() {
grep -Fq -- '--resolver' <<'EOM'
${{ inputs.stack-arguments }}
EOM
}
set_trimmed_output "stack-query-arguments" <<EOM
${{ inputs.query-arguments }}
EOM
set_trimmed_output "stack-path-arguments" <<EOM
${{ inputs.path-arguments }}
EOM
set_trimmed_output "stack-setup-arguments" <<EOM
${{ inputs.setup-arguments }}
EOM
set_trimmed_output "stack-build-arguments-dependencies" <<EOM
${{ inputs.stack-build-arguments }} ${{ inputs.stack-build-arguments-dependencies }}
EOM
set_trimmed_output "stack-build-arguments-build" <<EOM
${{ inputs.stack-build-arguments }} ${{ inputs.stack-build-arguments-build }}
EOM
set_trimmed_output "stack-build-arguments-test" <<EOM
${{ inputs.stack-build-arguments }} ${{ inputs.stack-build-arguments-test }}
EOM
resolver_nightly=
if ! has_resolver && [[ "${{ inputs.stack-yaml }}" == 'stack-nightly.yaml' ]]; then
resolver_nightly='--resolver nightly'
fi
echo "resolver-nightly=$resolver_nightly" >>"$GITHUB_OUTPUT"
echo "stack-build-arguments=${stack_build_arguments[*]}" >>"$GITHUB_OUTPUT"
set_trimmed_output "stack-arguments" <<EOM
--stack-yaml ${{ inputs.stack-yaml }} $resolver_nightly ${{ inputs.stack-arguments }}
EOM
echo 'stack-works<<EOM' >>"$GITHUB_OUTPUT"
# We can't just list out '**/.stack-work' because the files may not
Expand Down Expand Up @@ -177,9 +220,9 @@ runs:
tmp=$(mktemp)
trap 'rm -r "$tmp"' EXIT
stack --no-terminal --stack-yaml ${{ inputs.stack-yaml }} \
${{ steps.setup.outputs.resolver-nightly }} \
query compiler | tee "$tmp"
stack ${{ steps.setup.outputs.stack-arguments }} \
query compiler ${{ steps.setup.outputs.stack-query-arguments }} \
| tee "$tmp"
sed '/^actual: \(.*\)$/!d; s//compiler=\1/' "$tmp" >>"$GITHUB_OUTPUT"
sed '/^actual: ghc-\(.*\)$/!d; s//compiler-version=\1/' "$tmp" >>"$GITHUB_OUTPUT"
Expand All @@ -189,9 +232,9 @@ runs:
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
stack --no-terminal --stack-yaml ${{ inputs.stack-yaml }} \
${{ steps.setup.outputs.resolver-nightly }} \
path | while IFS=:\ read -r name value; do
stack ${{ steps.setup.outputs.stack-arguments }} \
path ${{ steps.setup.outputs.stack-path-arguments }} \
| while IFS=:\ read -r name value; do
printf '%s: %s\n' "$name" "$value"
printf '%s=%s\n' "$name" "$value" >>"$GITHUB_OUTPUT"
done
Expand All @@ -216,13 +259,11 @@ runs:
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
stack --no-terminal --stack-yaml ${{ inputs.stack-yaml }} \
${{ steps.setup.outputs.resolver-nightly }} \
setup
stack --no-terminal --stack-yaml ${{ inputs.stack-yaml }} \
${{ steps.setup.outputs.resolver-nightly }} \
stack ${{ steps.setup.outputs.stack-arguments }} \
setup ${{ steps.setup.outputs.stack-setup-arguments }}
stack ${{ steps.setup.outputs.stack-arguments }} \
build --dependencies-only --test --no-run-tests \
${{ inputs.stack-arguments }}
${{ steps.setup.outputs.stack-build-arguments-dependencies }}
- name: Save dependencies cache
if: |
Expand Down Expand Up @@ -253,11 +294,9 @@ runs:
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
stack --no-terminal --stack-yaml ${{ inputs.stack-yaml }} \
${{ steps.setup.outputs.resolver-nightly }} \
build ${{ steps.setup.outputs.stack-build-arguments }} \
--test --no-run-tests \
${{ inputs.stack-arguments }}
stack ${{ steps.setup.outputs.stack-arguments }} \
build --test --no-run-tests \
${{ steps.setup.outputs.stack-build-arguments-build }}
- name: Save build cache
if: |
Expand All @@ -273,7 +312,6 @@ runs:
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
stack --no-terminal --stack-yaml ${{ inputs.stack-yaml }} \
${{ steps.setup.outputs.resolver-nightly }} \
build ${{ steps.setup.outputs.stack-build-arguments }} --test \
${{ inputs.stack-arguments }}
stack ${{ steps.setup.outputs.stack-arguments }} \
build --test \
${{ steps.setup.outputs.stack-build-arguments-test }}

0 comments on commit 4b7c98e

Please sign in to comment.