-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
131 lines (120 loc) · 4.97 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Vale Spell-Check
description: Run Vale for spell-checking - much faster than the official Vale action.
branding:
icon: edit
color: orange
inputs:
version:
description: Vale release version to use.
required: false
default: ""
flags:
description: Space-delimited list of flags for the Vale CLI. To see a full list of available flags, run `vale -h`.
required: false
default: ""
files:
description: Space-delimited list of file or directory arguments; equivalent to calling `vale input1 input2`.
required: false
default: "."
reviewdog:
description: Whether to use Vale with Reviewdog.
required: false
default: "false"
github_token:
description: The GitHub repo access token to be used for Reviewdog.
required: false
default: ${{ github.token }}
github_com_pat:
description: A GitHub.com PAT to avoid API rate limits
required: false
default: ""
reporter:
description: Set the reporter type for Reviewdog.
required: false
default: "github-pr-review"
fail_on_error:
description: By default, Reviewdog will return exit code 0 even if it finds errors. If `fail_on_error` is enabled, Reviewdog exits with 1 when at least one error was reported.
required: false
default: "false"
filter_mode:
description: Set the [filter mode](https://github.com/reviewdog/reviewdog#filter-mode) for Reviewdog.
required: false
default: "added"
runs:
using: composite
steps:
- name: 🐧 Check for Linux
shell: bash
run: |
if ! [ "$RUNNER_OS" == "Linux" ]; then
echo "::error title=runner os is $RUNNER_OS::simbo/vale-action is only for linux runners"
exit 1
fi
- name: 🤝 Prepare GitHub API Auth
id: github-auth
shell: bash
run: |
if [[ "${{ inputs.github_com_pat }}" = "" ]]; then
pat=""
else
echo "::add-mask::${{ inputs.github_com_pat }}"
pat="${{ inputs.github_com_pat }}@"
fi
echo "::set-output name=pat::$pat"
- name: 🛠 Install Vale
shell: bash
run: |
if [[ "${{ inputs.version }}" = "" ]]; then
curl -sfL https://${{ steps.github-auth.outputs.pat }}api.github.com/repos/errata-ai/vale/releases/latest -o "${RUNNER_TEMP}/vale-latest-version.json" || true
if ! [[ -f "${RUNNER_TEMP}/vale-latest-version.json" ]]; then
echo "::error title=GitHub API Error::Could not retrieve the latest Vale version info from GitHub API."
exit 1
fi
valeVersion="$(cat "${RUNNER_TEMP}/vale-latest-version.json" | grep '"tag_name":' | cut -d \" -f 4 | cut -d v -f 2)"
else
valeVersion="${{ inputs.version }}"
fi
if ! [[ "$valeVersion" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error title=Invalid Version::The Vale version '${valeVersion}' is not a valid semver version."
exit 1
fi
echo "::group::Vale Installation"
curl -sfL https://${{ steps.github-auth.outputs.pat }}github.com/errata-ai/vale/releases/download/v${valeVersion}/vale_${valeVersion}_Linux_64-bit.tar.gz -o "${RUNNER_TEMP}/vale.tar.gz" || true
if ! [[ -f "${RUNNER_TEMP}/vale.tar.gz" ]]; then
echo "::error title=Vale Download failed::Downloading the latest Vale version failed."
exit 1
fi
mkdir -p "${RUNNER_TEMP}/bin"
tar -xvzf "${RUNNER_TEMP}/vale.tar.gz" -C "${RUNNER_TEMP}/bin"
echo "${RUNNER_TEMP}/bin" >> $GITHUB_PATH
echo "::endgroup::"
echo "::group::Syncing Vale"
${RUNNER_TEMP}/bin/vale sync
echo "::endgroup::"
- name: 🧑🏫 Run Vale
if: ${{ inputs.reviewdog != 'true' }}
shell: bash
run: vale ${{ inputs.flags }} ${{ inputs.files }}
- name: 🛠 Install Reviewdog
if: ${{ inputs.reviewdog == 'true' }}
shell: bash
run: |
echo "::group::Reviewdog Installation"
curl -sfL https://${{ steps.github-auth.outputs.pat }}raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh -o "${RUNNER_TEMP}/reviewdog-script.sh"
if ! [[ -f "${RUNNER_TEMP}/reviewdog-script.sh" ]]; then
echo "::error title=Reviewdog Download failed::Downloading the Reviewdog script from GitHub failed."
exit 1
fi
cat "${RUNNER_TEMP}/reviewdog-script.sh" | sh -s -- -b ${RUNNER_TEMP}/bin
echo "::endgroup::"
- name: 🧑🏫 Run Vale with Reviewdog
if: ${{ inputs.reviewdog == 'true' }}
shell: bash
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ inputs.github_token }}
run: |
output=$(vale --no-exit --output=$GITHUB_ACTION_PATH/rdjsonl.tmpl ${{ inputs.flags }} ${{ inputs.files }})
echo "::group::Vale output for Reviewdog"
echo -e "$output"
echo "::endgroup::"
printf "$output" | reviewdog -f=rdjsonl -name=vale -reporter=${{ inputs.reporter }} -fail-on-error=${{ inputs.fail_on_error }} -filter-mode=${{ inputs.filter_mode }} -level=info