Repository navigation
185 lines (169 loc) · 9.47 KB
/
Copy pathcode-review.yml
File metadata and controls
185 lines (169 loc) · 9.47 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Code Review
# Reviews a pull request with the shared vaadin/github-actions/code-review
# action and posts the findings as one review by vaadin-review-bot. Runs when a
# pull request to main is opened or marked ready for review, and on request: a
# "/code-review" comment on a pull request to any branch, or a review request
# for vaadin-review-bot.
# This workflow owns the triggers, the eligibility rules, the choice of review
# profile and the reaction to the trigger.
on:
issue_comment:
types: [created]
pull_request:
types: [opened, ready_for_review, review_requested]
env:
PR_NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
jobs:
check:
# A cheap `if` pre-filter, then an authoritative permission check in the
# job: only users with write access start a review. A requested review (a
# comment or a review request) checks only who asked. An automatic trigger
# runs only for pull requests to main, and skips drafts, Dependabot,
# cherry-picks, version updates and chore pull requests. A pull request
# opened with vaadin-review-bot as a reviewer is reviewed once, by its
# review_requested event. Doc Bot and totally-not-ai open drafts, so their
# pull requests are reviewed when a person marks them ready for review.
# A pull_request event runs the workflow of the pull request's base
# branch, so a review request works only where that branch has this
# file. A "/code-review" comment always runs the workflow of main.
# Pull requests from forks are not reviewed: the pre-filter skips their
# pull request events, and the job skips a "/code-review" comment on one.
if: |
(github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.body == '/code-review' &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association)) ||
(github.event_name == 'pull_request' &&
!github.event.pull_request.head.repo.fork &&
github.event.action == 'review_requested' &&
github.event.requested_reviewer.login == 'vaadin-review-bot') ||
(github.event_name == 'pull_request' &&
!github.event.pull_request.head.repo.fork &&
contains(fromJSON('["opened", "ready_for_review"]'), github.event.action) &&
github.event.pull_request.base.ref == 'main' &&
github.event.pull_request.draft == false &&
!(github.event.action == 'opened' &&
contains(github.event.pull_request.requested_reviewers.*.login, 'vaadin-review-bot')) &&
github.event.pull_request.user.login != 'dependabot[bot]' &&
!contains(github.event.pull_request.title, '(CP: ') &&
!startsWith(github.event.pull_request.title, 'Update vaadin version') &&
!startsWith(github.event.pull_request.title, 'chore:') &&
!startsWith(github.event.pull_request.title, 'chore('))
runs-on: ubuntu-26.04
timeout-minutes: 5
permissions:
contents: read
pull-requests: read
outputs:
eligible: ${{ steps.access.outputs.eligible }}
profile: ${{ steps.profile.outputs.profile }}
steps:
- name: Check repository permission and pull request origin
id: access
env:
GH_TOKEN: ${{ secrets.VAADIN_REVIEW_BOT || github.token }}
REQUESTER: ${{ github.event.sender.login }}
run: |
# .permission rather than .role_name: maintain and custom roles
# based on write or maintain are reported as "write" there
role=$(gh api "repos/${{ github.repository }}/collaborators/$REQUESTER/permission" \
--jq .permission || echo none)
# A comment event does not say where the pull request comes from
cross=$(gh pr view "$PR_NUMBER" --repo "${{ github.repository }}" \
--json isCrossRepository --jq .isCrossRepository || echo true)
if [ "$cross" != false ]; then
echo "Skipping a pull request from a fork."
echo "eligible=false" >> "$GITHUB_OUTPUT"
exit 0
fi
case "$role" in
admin|write) echo "eligible=true" >> "$GITHUB_OUTPUT" ;;
*) echo "eligible=false" >> "$GITHUB_OUTPUT" ;;
esac
- name: Select review profile
id: profile
if: steps.access.outputs.eligible == 'true'
env:
GH_TOKEN: ${{ secrets.VAADIN_REVIEW_BOT || github.token }}
run: |
# Pages and their code examples get the docs profile. A pull request
# that changes only tooling, such as scripts, workflows or the
# publisher theme, gets the code profile.
files=$(gh api --paginate "repos/${{ github.repository }}/pulls/$PR_NUMBER/files" \
--jq '.[].filename')
if grep -qE '^(articles|src|frontend)/' <<< "$files"; then
echo "profile=docs" >> "$GITHUB_OUTPUT"
else
echo "profile=code" >> "$GITHUB_OUTPUT"
fi
review:
needs: check
if: needs.check.outputs.eligible == 'true'
# One review per pull request at a time. A new trigger queues instead of
# cancelling a run that may be posting. The group is on the job, not on the
# workflow, so that a trigger that fails the pre-filter cannot cancel an
# eligible run that waits for its turn.
concurrency:
group: code-review-${{ github.event.issue.number || github.event.pull_request.number }}
cancel-in-progress: false
runs-on: ubuntu-26.04
timeout-minutes: 45
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: React to trigger
env:
GH_TOKEN: ${{ secrets.VAADIN_REVIEW_BOT || github.token }}
run: |
if [ "${{ github.event_name }}" = "issue_comment" ]; then
target="issues/comments/${{ github.event.comment.id }}"
else
target="issues/$PR_NUMBER"
fi
gh api "repos/${{ github.repository }}/$target/reactions" \
-f content=eyes
# The review session is read-only and never builds or runs anything, so
# it needs Node only, for the action's scripts and the Claude Code CLI.
- name: Checkout PR branch
uses: actions/checkout@v6
with:
ref: refs/pull/${{ env.PR_NUMBER }}/head
fetch-depth: 1
# The review action authenticates with its `github-token` input.
persist-credentials: false
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '22'
# The review uses no MCP servers. The repository's .mcp.json is for local
# authoring sessions.
- name: Remove the MCP configuration
run: rm -f .mcp.json
- name: Run code review
uses: vaadin/github-actions/code-review@2c9bd830f448599af76fa9a124360189f4613542 # main
with:
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
pr-number: ${{ env.PR_NUMBER }}
profile: ${{ needs.check.outputs.profile }}
github-token: ${{ secrets.VAADIN_REVIEW_BOT || github.token }}
reference-repos: |
vaadin/flow | the Vaadin Flow framework (Java): routing, server-side UI, data binding, signals, security, dev mode and the build tooling. The source of the pages under articles/flow and most pages under articles/building-apps.
vaadin/flow-components | the Java API of the Vaadin UI components. The source of the Java examples and the Java API on the pages under articles/components.
vaadin/web-components | the Vaadin web components (TypeScript): behavior, properties, events, styling parts and theme variants. The source of the component behavior, the styling pages, and the Lit and React examples under articles/components.
vaadin/hilla | the Hilla framework (Java and TypeScript): browser-callable services and React views. The source of the pages about them under articles/flow, such as articles/flow/react-views, and under articles/building-apps/react.
vaadin/browserless-test | the browserless test framework for Flow. The source of the pages under articles/flow/testing/browserless and articles/building-apps/testing/browserless.
extra-instructions: |
# Documentation Review Context
This repository holds the pages of vaadin.com/docs and the code examples that they include. `guidelines/repository.md` describes the layout, how files map to URLs, and the branches.
These checks of a pull request already report their findings:
- Vale (`lint`): the writing style of the lines added under `articles/`.
- Maven Compile and Format Check: the Java examples compile, their tests pass, and they follow the Java formatting conventions.
- Check Redirects: a moved or removed page leaves a redirect behind, and every redirect resolves.
- Check Versions: the version attributes in `articles/_vaadin-version.adoc` match `pom.xml`.
- Check Feature Flags: every feature flag of Flow and Flow Components is documented.
No check compiles or lints the TypeScript examples under `frontend/`.
The pages use the AsciiDoc extensions of Vaadin Design System Publisher. Rendered examples, `// hidden-source-line` comments and `since` badges are valid markup. `articles/contributing/docs/dspublisher/editing.adoc` documents them.
Several commercial products have no source in the reference checkouts. Their pages fall under the rule for unverifiable claims.
upload-execution-log: ${{ vars.CLAUDE_DEBUG }}