Skip to content

Commit

Permalink
Merge pull request #106 from fish-shop/annotations
Browse files Browse the repository at this point in the history
Add annotations
  • Loading branch information
marcransome authored Aug 26, 2024
2 parents c77c1cc + 6e382d3 commit 8f5d9cd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 10 deletions.
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ Each pattern value may include [wildcards](https://fishshell.com/docs/current/la

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` |
| Name | Description | Default |
|---------------|----------------------------------------|-----------------------|
| `annotations` | The string value `'true'` or `'false'` indicating whether to enable [annotations](#annotations) or not | `true` |
| `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

Expand All @@ -65,11 +66,23 @@ The following outputs are made available to subsequent steps in a workflow:
| `passed` | The number of files that passed syntax checks |
| `failed` | The number of files that failed syntax checks |

## Annotations

Syntax issues identified by this action are displayed as [annotations](https://github.blog/news-insights/product-news/introducing-check-runs-and-annotations/) on the workflow summary page:

<img alt="Workflow summary annotations" src="images/annotations-workflow-summary.png" width="909">

Annotations are also displayed directly alongside the code in the 'Files changed' tab of pull requests:

<img alt="Pull request annotations" src="images/annotations-pull-request.png" width="909">

This behaviour can be disabled by setting the `annotations` input to `false`.

## 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:

<img alt="job-summary" src="images/job-summary.png" width="909">
<img alt="Job summary" src="images/job-summary.png" width="909">

## Action versions

Expand Down
23 changes: 18 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ branding:
icon: 'check'
color: 'green'
inputs:
annotations:
description: 'Display annotations for syntax errors in workflow summary and pull request checks'
required: false
default: 'true'
title:
description: 'Title to display in job summary'
required: false
Expand All @@ -28,15 +32,17 @@ runs:
- name: Syntax check fish shell files
id: syntax-check
env:
ANNOTATIONS: ${{ inputs.annotations }}
TITLE: ${{ inputs.title }}
PATTERNS: ${{ inputs.patterns }}
run: |
set -gx TERM xterm-256color
set -l passed 0
set -l failed 0
set title "$TITLE"
set annotations "$ANNOTATIONS"
set passed 0
set failed 0
for pattern in (string split --no-empty -- " " $PATTERNS)
set -l escaped (string escape --style=script --no-quoted -- $pattern)
Expand All @@ -46,13 +52,20 @@ runs:
for file in $files
echo -n " "
set output (fish --no-execute $file 2>&1)
set -l output (fish --no-execute $file 2>&1)
if test $status -ne 0
set_color red; and echo -n "✖"; and set_color normal
echo " $file"
for line in (string split -- $output)
echo " $line"
end
if test "$annotations" = "true"
string match --regex --groups-only '^(?<file>.+)\s+\(line\s+(?<line>[0-9]+)\):\s+(?<message>.+)' $output
set -l title "Syntax issue"
echo "::error file=$file,line=$line,title=$title::$message"
end
set failed (math $failed + 1)
else
set_color green; and echo -n "✔"; and set_color normal
Expand All @@ -62,7 +75,7 @@ runs:
end
end
set -l total (math $passed + $failed)
set total (math $passed + $failed)
echo
set_color green; and echo -n "passed: $passed"; and set_color normal
Expand Down
Binary file added images/annotations-pull-request.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/annotations-workflow-summary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8f5d9cd

Please sign in to comment.