Repository navigation
77 lines (68 loc) · 3.03 KB
/
Copy pathvale-comment.yml
File metadata and controls
77 lines (68 loc) · 3.03 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
name: Vale Comments
# Show the PR title of the linted PR in the Actions run list
run-name: ${{ github.event.workflow_run.display_title }}
# Posts Vale results from vale.yml as PR review comments, including for fork PRs.
on:
workflow_run:
workflows: ['Vale Linting']
types: [completed]
permissions:
actions: read
contents: read
pull-requests: write
jobs:
comment:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
steps:
# SECURITY: This workflow has write permissions, so never add a step that checks out or runs code from the PR.
- name: Download results
uses: actions/download-artifact@v8
with:
name: vale-results
path: vale-results
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ github.token }}
- name: Validate PR number
id: pr
run: |
PR_NUMBER=$(head -n 1 vale-results/pr-number)
# The artifact is untrusted: accept only a plain integer
if ! [[ "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
echo "Invalid PR number"
exit 1
fi
# Confirm the PR's head commit is the commit that was linted
PR_SHA=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER" --jq '.head.sha')
if [ "$PR_SHA" != "${{ github.event.workflow_run.head_sha }}" ]; then
echo "PR head ($PR_SHA) differs from linted commit; skipping stale results"
echo "skip=true" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
if [ -s vale-results/results.rdjsonl ]; then echo "has_results=true" >> "$GITHUB_OUTPUT"; fi
env:
GH_TOKEN: ${{ github.token }}
- name: Install reviewdog
if: steps.pr.outputs.has_results == 'true'
# Pin the version and verify its checksum
run: |
VERSION=0.21.3
SHA256=7029c2faf54e1237454cae8f1adf876c965b3d13d054f1a392206459091af4a1
curl -fsSL -o reviewdog.tar.gz "https://github.com/reviewdog/reviewdog/releases/download/v${VERSION}/reviewdog_${VERSION}_Linux_x86_64.tar.gz"
echo "$SHA256 reviewdog.tar.gz" | sha256sum -c -
mkdir -p "$RUNNER_TEMP/bin"
tar -xzf reviewdog.tar.gz -C "$RUNNER_TEMP/bin" reviewdog
echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
- name: Post review comments
if: steps.pr.outputs.has_results == 'true'
run: |
# reviewdog needs a git repo; filter-mode=added comments only on lines the PR changed
git init -q
env -u GITHUB_ACTIONS reviewdog -f=rdjsonl -name=vale -reporter=github-pr-review -filter-mode=added -fail-level=none -level=info < vale-results/results.rdjsonl
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }}
CI_PULL_REQUEST: ${{ steps.pr.outputs.number }}
CI_COMMIT: ${{ github.event.workflow_run.head_sha }}
CI_REPO_OWNER: ${{ github.repository_owner }}
CI_REPO_NAME: ${{ github.event.repository.name }}