diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cad8865..f2e7c21 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,42 +28,159 @@ jobs: uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 - name: Install fish shell uses: fish-shop/install-fish-shell@720ad65b07b693d9332d73aaf811502196c1efb8 # v1.0.12 - - name: Create syntactically valid fish shell function + - name: Create syntactically valid fish shell file run: | - cat << EOF >./valid-syntax.fish + echo "\ function valid-syntax echo "valid-syntax" + end" > ./valid-syntax.fish + shell: fish {0} + - name: Syntax check valid fish shell file + id: passing-checks + continue-on-error: true + uses: ./ + with: + patterns: valid-syntax.fish + title: 'Passing syntax checks summary' + - name: Check passing syntax checks outcome + run: | + if test "${{ steps.passing-checks.outcome }}" != "success" + echo "Action is expected to succeed for syntactically valid file" + exit 1 end - EOF - - name: Create syntactically invalid fish shell function + shell: fish {0} + - name: Check passing syntax checks output parameters + env: + TOTAL: ${{ steps.passing-checks.outputs.total }} + PASSED: ${{ steps.passing-checks.outputs.passed }} + FAILED: ${{ steps.passing-checks.outputs.failed }} run: | - cat << EOF >./invalid-syntax.fish + set failures 0 + + set expected_total 1 + if test "$TOTAL" != "$expected_total" + echo "Output parameter 'total' should equal $expected_total (got '$TOTAL')" + set failures (math $failures + 1) + else + echo "Output parameter 'total' equals expected value $expected_total" + end + + set expected_passes 1 + if test "$PASSED" != "$expected_passes" + echo "Output parameter 'passed' should equal $expected_passes (got '$PASSED')" + set failures (math $failures + 1) + else + echo "Output parameter 'passed' equals expected value $expected_passes" end - EOF - - name: Syntax check valid fish file - id: check-valid-file + + set expected_failures 0 + if test "$FAILED" != "$expected_failures" + echo "Output parameter 'failed' should equal $expected_failures (got '$FAILED')" + set failures (math $failures + 1) + else + echo "Output parameter 'failed' equals expected value $expected_failures" + end + + exit $failures + shell: fish {0} + - name: Create syntactically invalid fish shell file + run: | + echo "\ + end" > ./invalid-syntax.fish + shell: fish {0} + - name: Syntax check invalid fish shell file + id: failing-checks continue-on-error: true uses: ./ with: - patterns: valid-syntax.fish - - name: Syntax check invalid fish file - id: check-invalid-file + patterns: invalid-syntax.fish + title: 'Failing syntax checks summary' + - name: Check failing syntax checks outcome + run: | + if test "${{ steps.failing-checks.outcome }}" != "failure" + echo "Action is expected to fail for syntactically invalid file" + exit 1 + end + shell: fish {0} + - name: Check failing syntax checks output parameters + env: + TOTAL: ${{ steps.failing-checks.outputs.total }} + PASSED: ${{ steps.failing-checks.outputs.passed }} + FAILED: ${{ steps.failing-checks.outputs.failed }} + run: | + set failures 0 + + set expected_total 1 + if test "$TOTAL" != "$expected_total" + echo "Output parameter 'total' should equal $expected_total (got '$TOTAL')" + set failures (math $failures + 1) + else + echo "Output parameter 'total' equals expected value $expected_total" + end + + set expected_passes 0 + if test "$PASSED" != "$expected_passes" + echo "Output parameter 'passed' should equal $expected_passes (got '$PASSED')" + set failures (math $failures + 1) + else + echo "Output parameter 'passed' equals expected value $expected_passes" + end + + set expected_failures 1 + if test "$FAILED" != "$expected_failures" + echo "Output parameter 'failed' should equal $expected_failures (got '$FAILED')" + set failures (math $failures + 1) + else + echo "Output parameter 'failed' equals expected value $expected_failures" + end + + exit $failures + shell: fish {0} + - name: Syntax check mixed valid/invalid fish shell files + id: mixed-checks continue-on-error: true uses: ./ with: - patterns: invalid-syntax.fish - - name: Check outcomes + patterns: 'valid-syntax.fish invalid-syntax.fish' + title: 'Mixed syntax checks summary' + - name: Check mixed syntax checks outcome + run: | + if test "${{ steps.mixed-checks.outcome }}" != "failure" + echo "Action is expected to fail for syntactically invalid file" + exit 1 + end + shell: fish {0} + - name: Check mixed syntax checks output parameters + env: + TOTAL: ${{ steps.mixed-checks.outputs.total }} + PASSED: ${{ steps.mixed-checks.outputs.passed }} + FAILED: ${{ steps.mixed-checks.outputs.failed }} run: | - exit_code=0 + set failures 0 - if [[ "${{ steps.check-valid-file.outcome }}" != "success" ]]; then - echo "Action is expected to succeed for file with valid syntax" - exit_code=1 - fi + set expected_total 2 + if test "$TOTAL" != "$expected_total" + echo "Output parameter 'total' should equal $expected_total (got '$TOTAL')" + set failures (math $failures + 1) + else + echo "Output parameter 'total' equals expected value $expected_total" + end - if [[ "${{ steps.check-invalid-file.outcome }}" != "failure" ]]; then - echo "Action is expected to fail for file with invalid syntax" - exit_code=1 - fi + set expected_passes 1 + if test "$PASSED" != "$expected_passes" + echo "Output parameter 'passed' should equal $expected_passes (got '$PASSED')" + set failures (math $failures + 1) + else + echo "Output parameter 'passed' equals expected value $expected_passes" + end + + set expected_failures 1 + if test "$FAILED" != "$expected_failures" + echo "Output parameter 'failed' should equal $expected_failures (got '$FAILED')" + set failures (math $failures + 1) + else + echo "Output parameter 'failed' equals expected value $expected_failures" + end - exit ${exit_code} + exit $failures + shell: fish {0} diff --git a/README.md b/README.md index 58c9a02..c8f4171 100644 --- a/README.md +++ b/README.md @@ -14,22 +14,22 @@ Here's an example from the test workflow for [Pond](https://github.com/marcranso ## Prerequisites -This action requires the [fish shell](https://fishshell.com). You can install it using the [fish-shop/install-fish-shell](https://github.com/fish-shop/install-fish-shell) action. +This action requires [fish shell](https://fishshell.com). You can install it using the [fish-shop/install-fish-shell](https://github.com/fish-shop/install-fish-shell) action. ## Usage -Add a suitable `uses` step to your GitHub [workflow](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions) as shown below: +Add a `uses` step to your GitHub [workflow](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions) as shown below: ```yaml - name: Syntax check - uses: fish-shop/syntax-check@v1 + uses: fish-shop/syntax-check@v2 ``` -By default, all files under `$GITHUB_WORKSPACE` with a `.fish` file extension are checked. To override the default behaviour, provide one or more space-seperated pattern values to the `patterns` input. For example, to check all `.fish` files starting in the `src` directory and descending into subdirectories: +By default, all files under `$GITHUB_WORKSPACE` with a `.fish` file extension are checked. To override the default behaviour, provide one or more space-separated pattern values to the `patterns` input. For example, to check all `.fish` files starting in the `src` directory and descending into subdirectories: ```yaml - name: Syntax check - uses: fish-shop/syntax-check@v1 + uses: fish-shop/syntax-check@v2 with: patterns: src/**.fish ``` @@ -38,7 +38,7 @@ Each pattern value may include [wildcards](https://fishshell.com/docs/current/la ```yaml - name: Syntax check - uses: fish-shop/syntax-check@v1 + uses: fish-shop/syntax-check@v2 with: patterns: init.fish functions/**.fish {conf.d,completions}/**.fish tests/???-*.fish ``` @@ -46,6 +46,31 @@ Each pattern value may include [wildcards](https://fishshell.com/docs/current/la > [!IMPORTANT] > The `?` wildcard character is [deprecated](https://fishshell.com/docs/current/language.html#wildcards-globbing) and can be disabled via the `fish` feature flag `qmark-noglob`. Support for the `?` wildcard may therefore be dependent upon the version of `fish` shell in use and/or the configuration of its feature flags. +## Inputs + +Configure the action using the following inputs: + +| Name | Description | Default | +|--------------|----------------------------------------|-----------------------| +| `patterns` | A space-separated list of file patterns to match against when running syntax checks; each pattern may include [wildcards](https://fishshell.com/docs/current/language.html#expand-wildcard) and/or [brace expansions](https://fishshell.com/docs/current/language.html?highlight=brace+expansion#brace-expansion) | `**.fish` | +| `title` | The title to display in the [job summary](#job-summary); can be used to distinguish multiple summaries generated from a single workflow | `Syntax check results` | + +## Outputs + +The following outputs are made available to subsequent steps in a workflow: + +| Name | Description | +|----------|-----------------------------------------------| +| `total` | The total number of files syntax checked | +| `passed` | The number of files that passed syntax checks | +| `failed` | The number of files that failed syntax checks | + +## Job summary + +This action generates a [job summary](https://github.blog/news-insights/product-news/supercharging-github-actions-with-job-summaries/) at run-time which can be viewed from the workflow run summary page: + +job-summary + ## Action versions Use one of the following patterns when specifying the version reference for this action in your workflow (i.e. the `{ref}` value in `uses: fish-shop/syntax-check@{ref}`): diff --git a/action.yml b/action.yml index d228f0c..899ef5a 100644 --- a/action.yml +++ b/action.yml @@ -4,21 +4,39 @@ branding: icon: 'check' color: 'green' inputs: + title: + description: 'Title to display in job summary' + required: false + default: 'Syntax check results' patterns: description: 'File patterns to match against when running syntax checks' required: false default: '**.fish' +outputs: + total: + description: "Total number of files syntax checked" + value: ${{ steps.syntax-check.outputs.total }} + passed: + description: "Number of files passed syntax check" + value: ${{ steps.syntax-check.outputs.passed }} + failed: + description: "Number of files failed syntax check" + value: ${{ steps.syntax-check.outputs.failed }} runs: using: "composite" steps: - name: Syntax check fish shell files + id: syntax-check env: + TITLE: ${{ inputs.title }} PATTERNS: ${{ inputs.patterns }} run: | set -gx TERM xterm-256color - set -l passes 0 - set -l failures 0 + set -l passed 0 + set -l failed 0 + + set title "$TITLE" for pattern in (string split --no-empty -- " " $PATTERNS) set -l escaped (string escape --style=script --no-quoted -- $pattern) @@ -35,29 +53,47 @@ runs: for line in (string split -- $output) echo " $line" end - set failures (math $failures + 1) + set failed (math $failed + 1) else set_color green; and echo -n "✔"; and set_color normal echo " $file" - set passes (math $passes + 1) + set passed (math $passed + 1) end end end - set -l total (math $passes + $failures) + set -l total (math $passed + $failed) echo - set_color green; and echo -n "passed: $passes"; and set_color normal + set_color green; and echo -n "passed: $passed"; and set_color normal echo -n " " - set_color red; and echo -n "failed: $failures"; and set_color normal + set_color red; and echo -n "failed: $failed"; and set_color normal echo " of $total files" echo - if test $failures -gt 0 - set_color red; and echo "$failures of $total failed." + if test $failed -gt 0 + set_color red; and echo "$failed of $total failed." else set_color green; and echo "All of $total files passed!" end - exit $failures + if test $failed -eq 0 + set result ":white_check_mark: Pass" + else + set result ":x: Fail" + end + + echo "### $title" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "| Result :microscope: | Passed :white_check_mark: | Failed :x: |" >> $GITHUB_STEP_SUMMARY + echo "|---------------------|---------------------------|------------|" >> $GITHUB_STEP_SUMMARY + echo "| $result | $passed | $failed |" >> $GITHUB_STEP_SUMMARY + + echo "total=$total" >> "$GITHUB_OUTPUT" + echo "passed=$passed" >> "$GITHUB_OUTPUT" + echo "failed=$failed" >> "$GITHUB_OUTPUT" + + if test $failed -ne 0 + exit 1 + end shell: fish {0} diff --git a/images/job-summary.png b/images/job-summary.png new file mode 100644 index 0000000..f7c1a9f Binary files /dev/null and b/images/job-summary.png differ