diff --git a/.github/workflows/example.yml b/.github/workflows/example.yml index e263da2..1851164 100644 --- a/.github/workflows/example.yml +++ b/.github/workflows/example.yml @@ -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 @@ -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 }}" ]] diff --git a/action.yml b/action.yml index eafe7a5..a9a7c8a 100644 --- a/action.yml +++ b/action.yml @@ -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: @@ -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" <>"$GITHUB_OUTPUT" - echo "stack-build-arguments=${stack_build_arguments[*]}" >>"$GITHUB_OUTPUT" + + set_trimmed_output "stack-arguments" <>"$GITHUB_OUTPUT" # We can't just list out '**/.stack-work' because the files may not @@ -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" @@ -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 @@ -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: | @@ -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: | @@ -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 }}