Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
114 lines (109 loc) · 4.57 KB
/
Copy pathaction.yml
File metadata and controls
114 lines (109 loc) · 4.57 KB
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
name: 'Writing Style Checker'
# Marketplace requires description < 125 chars.
description: 'Flag AI tells, weasel words, passive voice, duplicate words, long sentences, nominalizations, hedging, and filler adverbs'
branding:
icon: 'edit-3'
color: 'purple'
inputs:
files:
description: 'Glob pattern for files to check'
required: false
default: '**/*.md'
config:
description: 'Path to .wscrc.json config file'
required: false
max-warnings:
description: 'Maximum number of warnings before failing (default: unlimited)'
required: false
default: '-1'
only-changed:
description: 'On pull requests, check changed files that match files. If none match, skip (exit 0, total-issues 0). Other events check files.'
required: false
default: 'false'
exclude:
description: 'Glob patterns to skip (comma or newline separated). Stacks with config ignore'
required: false
default: ''
outputs:
total-issues:
description: 'Total number of issues found'
value: ${{ steps.check.outputs.total-issues }}
runs:
using: 'composite'
steps:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Build wsc-lint CLI
shell: bash
run: |
cd "$GITHUB_ACTION_PATH/cli"
npm ci
npm run build
- name: Get changed files (PR only)
id: changed
if: inputs.only-changed == 'true' && github.event_name == 'pull_request'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
# List every changed path, one per line (paths may contain spaces).
# The check step intersects this list with the `files` glob. An empty
# list is success: the check step skips and does not fall back to the
# full glob. The files API (up to 3000 files) is used instead of
# `gh pr diff`, which fails once GitHub deems the diff too large.
files=$(gh api --paginate "repos/$REPO/pulls/$PR_NUMBER/files?per_page=100" --jq '.[].filename')
delim="wsc_$(od -An -N8 -tx1 /dev/urandom | tr -d ' \n')"
printf 'files<<%s\n%s\n%s\n' "$delim" "$files" "$delim" >> "$GITHUB_OUTPUT"
- name: Run wsc check
id: check
shell: bash
env:
WSC_CHANGED: ${{ steps.changed.outputs.files }}
WSC_FILES: ${{ inputs.files }}
WSC_ONLY_CHANGED: ${{ inputs.only-changed }}
WSC_EVENT_NAME: ${{ github.event_name }}
WSC_CONFIG: ${{ inputs.config }}
WSC_MAX: ${{ inputs.max-warnings }}
WSC_EXCLUDE: ${{ inputs.exclude }}
run: |
# Inputs arrive via env vars (not workflow-expression interpolation)
# to avoid shell injection, and `set -f` stops the runner shell from
# pre-expanding globs like **/*.md — the CLI globs them itself.
set -f
# Exit 10: only-changed PR with no paths matching `files`. Any other
# non-zero status is a real failure. `||` keeps `set -e` from exiting
# before we can handle the skip.
code=0
selected=$(node --no-warnings "$GITHUB_ACTION_PATH/scripts/select-action-files.mjs") || code=$?
if [ "$code" -eq 10 ]; then
echo "No files matching the files pattern changed in this pull request. Skipping check."
echo "total-issues=0" >> "$GITHUB_OUTPUT"
exit 0
fi
if [ "$code" -ne 0 ]; then
echo "Could not decide which files to check." >&2
exit "$code"
fi
# One pattern per line. Read line by line so a path with spaces stays
# one argv.
check_files=()
while IFS= read -r line; do
if [ -n "$line" ]; then check_files+=("$line"); fi
done <<< "$selected"
args=(check "${check_files[@]}" --format github)
if [ -n "$WSC_CONFIG" ]; then args+=(--config "$WSC_CONFIG"); fi
if [ "$WSC_MAX" != "-1" ]; then args+=(--max-warnings "$WSC_MAX"); fi
# Quoted so a multiline exclude list is one argv; the CLI splits it.
if [ -n "$WSC_EXCLUDE" ]; then args+=(--ignore "$WSC_EXCLUDE"); fi
# Capture output (so we can read the issue count) without tripping
# `set -e`, then re-emit it so ::warning annotations register.
output=$(node "$GITHUB_ACTION_PATH/cli/dist/cli/index.js" "${args[@]}") || code=$?
: "${code:=0}"
printf '%s\n' "$output"
total=$(printf '%s\n' "$output" | grep -oE 'Found [0-9]+' | grep -oE '[0-9]+' | head -1 || true)
echo "total-issues=${total:-0}" >> "$GITHUB_OUTPUT"
exit "$code"