Skip to content

Commit 631373b

Browse files
committed
optionally include a token to help with rate limits
1 parent 601e8a9 commit 631373b

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

.github/workflows/main.yml

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
on:
2-
push:
3-
paths:
4-
- src/*
5-
- action.yml
6-
- package.json
7-
- package-lock.json
1+
on: push
82

93
jobs:
104
build:
@@ -25,6 +19,7 @@ jobs:
2519
uses: ./
2620
with:
2721
version: ${{ matrix.version }}
22+
github_token: ${{ github.token }}
2823

2924
- name: Print version
3025
run: |

README.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ This will add the following executables to your `PATH`, making them available fo
1313

1414
### Inputs
1515

16-
#### `version`
16+
| Parameter | Description | Required | Default |
17+
| -------------- | --------------------------------------------------------------------- | -------- | -------- |
18+
| `version` | The version of Dhall to install | N | `latest` |
19+
| `github_token` | A GitHub Token. This can help with rate limits when fetching releases | N | None |
1720

18-
**Optional** The version of Dhall to install. Default: `latest`.
21+
#### `version`
1922

2023
### Usage
2124

@@ -44,6 +47,32 @@ jobs:
4447
- run: dhall-to-json --version
4548
```
4649
50+
#### Adding a GitHub token
51+
52+
If the action fails, it could be because GitHub rate limits anonymous requests to the API. In that
53+
case, the action will log an error message that looks something like this:
54+
55+
```
56+
##[error]Failed to fetch releases from GitHub API, providing a token may help.
57+
Error: {"message":"API rate limit exceeded for 1.1.1.1. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)","documentation_url":"https://developer.github.com/v3/#rate-limiting"}
58+
```
59+
60+
As the error indicates, making the request as an authenticated user will grant a higher rate limit,
61+
so you can provide a `github_token` input to do so.
62+
63+
```yaml
64+
jobs:
65+
build:
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: dhall-lang/setup-dhall@v4
69+
with:
70+
version: '1.28.0'
71+
github_token: ${{ github.token }}
72+
- run: dhall version
73+
- run: dhall-to-json --version
74+
```
75+
4776
### TODO
4877

4978
- [x] Add platform validation on action to fail early if an unsupported runner is used

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
description: 'Version of Dhall to use. Default: `latest`'
1111
required: false
1212
default: latest
13+
github_token:
14+
description: A GitHub Token. This can help with rate limits when fetching releases.
15+
required: false
1316

1417
runs:
1518
using: node12

src/action.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,17 @@ const fetchReleases = async () => {
6161

6262
const get = url => {
6363
return new Promise((resolve, reject) => {
64-
const request = https.get(url, {
65-
headers: { 'User-Agent': 'setup-dhall Github action' },
66-
})
64+
const headers = {
65+
'User-Agent': 'setup-dhall Github action',
66+
}
67+
68+
const token = core.getInput('github_token')
69+
70+
if (token) {
71+
headers['Authorization'] = `token ${token}`
72+
}
73+
74+
const request = https.get(url, { headers })
6775

6876
request.on('response', res => {
6977
let data = ''

0 commit comments

Comments
 (0)