Skip to content

Commit c36b3f5

Browse files
committed
doc(example): show env.GITHUB_TOKEN usage
1 parent e6fb93f commit c36b3f5

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

.github/workflows/community.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ on:
1919
pull_request:
2020
types: [opened]
2121

22+
permissions:
23+
issues: write
24+
pull-requests: write
25+
2226
jobs:
2327

2428
labeler:
2529
runs-on: ubuntu-latest
26-
2730
steps:
2831
- name: Check Labels
2932
id: labeler
3033
uses: jimschubert/labeler-action@v2
3134
# uses: docker://jimschubert/test-labeler:action-0.0.0
3235
# uses: ./
33-
with:
36+
env:
3437
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88

99
GitHub Action allowing for applying labels to issues and pull requests based on patterns found in the title or description.
1010

11-
**NOTE** Thanks to the awesome efforts from the people at GitHub, `v2` and later support labeling from forked repositories via the [pull_request_target](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#pull_request_target) event.
11+
## Deprecation Notice
12+
13+
⚠️ **The `GITHUB_TOKEN` input is deprecated and will be removed in v3.** Pass the token via `env` instead:
14+
15+
```yaml
16+
- uses: jimschubert/labeler-action@v2
17+
env:
18+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
```
1220
1321
## Usage
1422
@@ -102,7 +110,7 @@ labels:
102110

103111
### Create a Workflow
104112

105-
The action requires a single input parameter: `GITHUB_TOKEN`. This token allows the action to access the GitHub API for your account. Workflows automatically provide a default `GITHUB_TOKEN`, which provides full API access. You create a secret from a [new token](https://github.com/settings/tokens) with `public_repo` scope to limit the action's footprint.
113+
The action requires the `GITHUB_TOKEN` environment variable. This token allows the action to access the GitHub API for your account. Workflows automatically provide a default `GITHUB_TOKEN`, which provides full API access. You can create a secret from a [new token](https://github.com/settings/tokens) with `public_repo` scope to limit the action's footprint.
106114

107115
**NOTE** Binding to issue or pull_request `edit` actions is _not_ recommended.
108116

@@ -116,6 +124,10 @@ on:
116124
pull_request_target:
117125
types: [opened]
118126
127+
permissions:
128+
issues: write
129+
pull-requests: write
130+
119131
jobs:
120132
121133
labeler:
@@ -125,7 +137,7 @@ jobs:
125137
- name: Check Labels
126138
id: labeler
127139
uses: jimschubert/labeler-action@v2
128-
with:
140+
env:
129141
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
130142
```
131143

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func runLabelerFromEnv() error {
4141
return fmt.Errorf("missing environment variable 'GITHUB_TOKEN' in labeler action configuration")
4242
}
4343
} else {
44-
fmt.Println("::warning::The GITHUB_TOKEN input is deprecated. Pass it via env instead. See docs for details.")
44+
fmt.Println("::warning::The GITHUB_TOKEN input is deprecated and will be removed in v3. Pass it via env instead. See docs for details.")
4545
}
4646

4747
// actions will pass input GITHUB_TOKEN as env INPUT_GITHUB_TOKEN, so set this back to GITHUB_TOKEN for the lib.

main_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,36 @@ func TestRunLabeler_InvokesLabelerError(t *testing.T) {
149149
})
150150
})
151151
}
152+
153+
func TestRunLabeler_DeprecationWarning(t *testing.T) {
154+
// Capture stdout to verify deprecation warning
155+
oldStdout := os.Stdout
156+
r, w, _ := os.Pipe()
157+
os.Stdout = w
158+
159+
// INPUT_GITHUB_TOKEN simulates passing token via 'with:' in actions
160+
withEnv("INPUT_GITHUB_TOKEN", "token", func() {
161+
withEnv("GITHUB_EVENT_NAME", "issues", func() {
162+
withEnv("GITHUB_EVENT_PATH", "testdata/issue.json", func() {
163+
withEnv("GITHUB_REPOSITORY", "jimschubert/testrepo", func() {
164+
withEnv("GITHUB_REPOSITORY_OWNER", "jimschubert", func() {
165+
withMockLabeler(func(mockLabeler *MockLabeler) {
166+
err := runLabelerFromEnv()
167+
assert.NoError(t, err)
168+
})
169+
})
170+
})
171+
})
172+
})
173+
})
174+
175+
w.Close()
176+
os.Stdout = oldStdout
177+
178+
var buf [1024]byte
179+
n, _ := r.Read(buf[:])
180+
output := string(buf[:n])
181+
182+
assert.Contains(t, output, "::warning::The GITHUB_TOKEN input is deprecated and will be removed in v3. Pass it via env instead. See docs for details.")
183+
}
184+

0 commit comments

Comments
 (0)