-
Notifications
You must be signed in to change notification settings - Fork 1.4k
142 lines (128 loc) · 4.6 KB
/
automation.yml
File metadata and controls
142 lines (128 loc) · 4.6 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
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Automation
on:
push:
branches: [main]
pull_request_target:
types: [opened, synchronize, reopened]
pull_request_review:
types: [submitted]
permissions:
contents: write
issues: write
pull-requests: write
jobs:
format:
name: Format
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
token: ${{ secrets.GOOGLEWORKSPACE_BOT_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
with:
components: rustfmt
- name: Run cargo fmt
run: cargo fmt --all
- name: Commit and push
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git diff --cached --quiet || git commit -m "style: cargo fmt" && git push
file-labeler:
name: File Labeler
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5
with:
repo-token: ${{ secrets.GOOGLEWORKSPACE_BOT_TOKEN }}
sync-labels: true
gemini-review:
name: Gemini Review
if: >-
github.event_name == 'pull_request_target' &&
github.event.action == 'synchronize'
runs-on: ubuntu-latest
concurrency:
group: gemini-review-${{ github.event.pull_request.number }}
cancel-in-progress: true
steps:
- name: Remove reviewed label
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
name: 'gemini: reviewed',
});
} catch (e) {
// Label not present — ignore
}
- name: Debounce
run: sleep 60
- name: Trigger Gemini Code Assist review
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
github-token: ${{ secrets.GOOGLEWORKSPACE_BOT_TOKEN }}
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: '/gemini review',
});
gemini-reviewed:
name: Gemini Reviewed
if: >-
github.event_name == 'pull_request_review' &&
github.event.review.user.login == 'gemini-code-assist[bot]'
runs-on: ubuntu-latest
steps:
- name: Add reviewed label if review matches HEAD
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
if (context.payload.review.commit_id !== pr.data.head.sha) {
console.log(`Review is for ${context.payload.review.commit_id} but HEAD is ${pr.data.head.sha} — skipping label`);
return;
}
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['gemini: reviewed'],
});
} catch (e) {
if (e.status === 403) {
console.log(`Token cannot add labels for this review event (${e.message}) — skipping`);
return;
}
throw e;
}