Skip to content

Commit

Permalink
Avoid the need for GITHUB_TOKEN
Browse files Browse the repository at this point in the history
Instead of getting the (latest) Go releases from git tags GitHubs API (and thus needing a token to avoid being rate limited) we pull the versions from https://go.dev/dl/?mode=json&include=all instead.

#minor
  • Loading branch information
arnested committed Apr 5, 2022
1 parent f2d49ca commit 828c065
Show file tree
Hide file tree
Showing 11 changed files with 30,679 additions and 3,529 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ jobs:
id: go-version
with:
working-directory: ./__tests__/testdata
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: |
test '${{ steps.go-version.outputs.module }}' == 'example.com/go/testmodule'
- run: |
Expand Down
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ The action reads the minimal supported Go version from your `go.mod`
file and exposes it as a variable to you workflow.

It also pulls the list of release tags from
[github.com/golang/go](https://github.com/golang/go) and exposes the
latest released Go version as a variable as well.
[https://go.dev/dl/](https://go.dev/dl/) and exposes the latest
released Go version as a variable as well.

From the list of released go versions and the minimal version your
module supports we also build a "matrix" variable to be used as a
Expand All @@ -46,14 +46,6 @@ working-directory:
default: .
```
To avoid API rate limits when fetching go releases from GitHub it is
recommended to set a token:
```yaml
env:
GITHUB_TOKEN: ${{ github.token }}
```
## Outputs
```yaml
Expand Down Expand Up @@ -84,8 +76,6 @@ jobs:
- uses: actions/checkout@v2
- uses: arnested/go-version-action@v1
id: go-version
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Install Go ${{ steps.go-version.outputs.minimal }}
uses: actions/setup-go@v2
with:
Expand Down Expand Up @@ -115,8 +105,6 @@ jobs:
- uses: actions/checkout@v2
- uses: arnested/go-version-action@v1
id: versions
env:
GITHUB_TOKEN: ${{ github.token }}
test:
name: Test
runs-on: ubuntu-latest
Expand Down
19 changes: 6 additions & 13 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
gomod,
latest,
minimal,
matrix,
modulename,
getTags
} from '../src/go-versions'
import fs from 'fs'
import {gomod, latest, matrix, minimal, modulename} from '../src/go-versions'

test('test module name', () => {
const content = gomod('__tests__/testdata/go.mod')
Expand All @@ -19,13 +12,13 @@ test('test minimal version', () => {
})

test('test latest version', () => {
expect(latest(['1.16', '1.15', '1.14', '1.13'])).toEqual('1.16')
expect(latest(['1.18', '1.17', '1.16', '1.15', '1.14', '1.13'])).toEqual(
'1.18'
)
})

test('test version matrix', () => {
const t = JSON.parse(
fs.readFileSync('__tests__/testdata/listTags.json', 'utf8')
)
const t = JSON.parse(fs.readFileSync('__tests__/testdata/dl.json', 'utf8'))
const m = matrix('1.13', t)
expect(m).toEqual(['1.16', '1.15', '1.14', '1.13'])
expect(m).toEqual(['1.18', '1.17', '1.16', '1.15', '1.14', '1.13'])
})
Loading

0 comments on commit 828c065

Please sign in to comment.