Skip to content

Commit 18f236b

Browse files
authored
Assess push permission (#226)
* use `contents: write` permission to post comments on push events * update docs
1 parent f487388 commit 18f236b

File tree

6 files changed

+84
-24
lines changed

6 files changed

+84
-24
lines changed

.github/workflows/self-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Self test action
22

33
on:
44
push:
5-
branches: main
5+
branches: [main]
66
paths:
77
- 'action.yml'
88
- 'requirements.txt'
@@ -19,7 +19,7 @@ on:
1919
jobs:
2020
test:
2121
permissions:
22-
issues: write
22+
contents: write
2323
pull-requests: write
2424
strategy:
2525
matrix:

docs/action.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ inputs:
1414
minimum-version: '1.3.0'
1515
lines-changed-only:
1616
minimum-version: '1.5.0'
17-
required-permission: 'content: read #file-changes'
17+
required-permission: 'contents: read #file-changes'
1818
files-changed-only:
1919
minimum-version: '1.3.0'
20-
required-permission: 'content: read #file-changes'
20+
required-permission: 'contents: read #file-changes'
2121
ignore:
2222
minimum-version: '1.3.0'
2323
thread-comments:
2424
minimum-version: '2.6.2'
25-
required-permission: 'issues: write #thread-comments'
25+
required-permission: 'contents: write #thread-comments'
2626
no-lgtm:
2727
minimum-version: '2.6.2'
2828
step-summary:

docs/examples/index.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Here are some example workflows to get started quickly.
3131
--8<-- "docs/examples/only-PR-comments.yml"
3232
```
3333

34-
1. See also [`style`][style]
35-
2. See also [`tidy-checks`][tidy-checks]
36-
3. See also [`thread-comments`][thread-comments]
34+
1. See also our [token permissions document](../permissions.md)
35+
2. See also [`style`][style]
36+
3. See also [`tidy-checks`][tidy-checks]
37+
4. See also [`thread-comments`][thread-comments]

docs/examples/only-PR-comments.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
jobs:
1111
cpp-linter:
1212
runs-on: ubuntu-latest
13+
permissions: # (1)!
14+
pull-requests: write
1315
steps:
1416
- uses: actions/checkout@v4
1517

@@ -20,9 +22,9 @@ jobs:
2022
env:
2123
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2224
with:
23-
style: 'file' # Use .clang-format config file. (1)
24-
tidy-checks: '' # Use .clang-tidy config file. (2)
25-
# only 'update' a single comment in a pull request's thread. (3)
25+
style: 'file' # Use .clang-format config file. (2)
26+
tidy-checks: '' # Use .clang-tidy config file. (3)
27+
# only 'update' a single comment in a pull request's thread. (4)
2628
thread-comments: ${{ github.event_name == 'pull_request' && 'update' }}
2729

2830
- name: Fail fast?!

docs/permissions.md

+48-13
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,61 @@ When using [`files-changed-only`](inputs-outputs.md#files-changed-only) or
1414
[`lines-changed-only`](inputs-outputs.md#lines-changed-only) to get the list
1515
of file changes for a CI event, the following permissions are needed:
1616

17-
```yaml
18-
permissions:
19-
contents: read # (1)!
20-
```
17+
=== "`#!yaml on: push`"
18+
19+
For [push events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push)
20+
21+
```yaml
22+
permissions:
23+
contents: read # (1)!
24+
```
25+
26+
1. This permission is also needed to download files if the repository is not
27+
checked out before running cpp-linter.
28+
29+
=== "`#!yaml on: pull_request`"
30+
31+
For [pull_request events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request)
32+
33+
```yaml
34+
permissions:
35+
contents: read # (1)!
36+
pull-requests: read # (2)!
37+
```
2138

22-
1. This permission is also needed to download files if the repository is not checked out before
23-
running cpp-linter (for both push and pull_request events).
39+
1. For pull requests, this permission is only needed to download files if
40+
the repository is not checked out before running cpp-linter.
41+
2. Specifying `#!yaml write` is also sufficient as that is required for
42+
43+
* posting [thread comments](#thread-comments) on pull requests
44+
* posting [pull request reviews](#pull-request-reviews)
2445

2546
## Thread Comments
2647

2748
The [`thread-comments`](inputs-outputs.md#thread-comments) feature requires the following permissions:
2849

29-
```yaml
30-
permissions:
31-
issues: write # (1)!
32-
pull-requests: write # (2)!
33-
```
50+
=== "`#!yaml on: push`"
51+
52+
For [push events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push)
53+
54+
```yaml
55+
permissions:
56+
metadata: read # (1)!
57+
contents: write # (2)!
58+
```
59+
60+
1. needed to fetch existing comments
61+
2. needed to post or update a commit comment. This also allows us to delete
62+
an outdated comment if needed.
63+
64+
=== "`#!yaml on: pull_request`"
65+
66+
For [pull_request events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request)
3467

35-
1. for [push events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push)
36-
2. for [pull_request events](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request)
68+
```yaml
69+
permissions:
70+
pull-requests: write
71+
```
3772

3873
## Pull Request Reviews
3974

docs/stylesheets/extra.css

+22
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,25 @@ th {
204204
display: block;
205205
max-height: none
206206
}
207+
208+
/* annotation buttons' pulse animation */
209+
a.md-annotation__index {
210+
border-radius: 2.2ch;
211+
}
212+
213+
@keyframes pulse {
214+
0% {
215+
box-shadow: 0 0 0 0 var(--md-accent-fg-color);
216+
transform: scale(.95)
217+
}
218+
219+
75% {
220+
box-shadow: 0 0 0 .625em transparent;
221+
transform: scale(1)
222+
}
223+
224+
to {
225+
box-shadow: 0 0 0 0 transparent;
226+
transform: scale(.95)
227+
}
228+
}

0 commit comments

Comments
 (0)