Skip to content

Commit 9754a25

Browse files
caarlos0crazy-max
andauthored
fix: use @action/github (#390)
* fix: use @action/github Signed-off-by: Carlos A Becker <[email protected]> Co-authored-by: CrazyMax <[email protected]> Signed-off-by: Carlos A Becker <[email protected]> * Update README.md Co-authored-by: CrazyMax <[email protected]> * Update action.yml Co-authored-by: CrazyMax <[email protected]> --------- Signed-off-by: Carlos A Becker <[email protected]> Co-authored-by: CrazyMax <[email protected]> Co-authored-by: CrazyMax <[email protected]>
1 parent b1a2381 commit 9754a25

File tree

16 files changed

+834
-29
lines changed

16 files changed

+834
-29
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
uses: docker/bake-action@v2
3030
with:
3131
targets: test
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3234
-
3335
name: Upload coverage
3436
uses: codecov/codecov-action@v3

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ___
2020
* [Signing](#signing)
2121
* [Upload artifacts](#upload-artifacts)
2222
* [Install Only](#install-only)
23+
* [Using on GHES](#using-on-ghes)
2324
* [Customizing](#customizing)
2425
* [inputs](#inputs)
2526
* [outputs](#outputs)
@@ -162,6 +163,37 @@ steps:
162163
name: Show GoReleaser version
163164
run: goreleaser -v
164165
```
166+
### Using on GHES
167+
168+
If you specify a version or `latest` of GoReleaser in your workflow, the
169+
version will be downloaded from [GitHub Releases in
170+
`goreleaser/goreleaser`](https://github.com/goreleaser/goreleaser/releases)
171+
repository. These calls to `goreleaser/goreleaser` are made via unauthenticated
172+
requests, which are limited to [60 requests per hour per
173+
IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting).
174+
175+
If more requests are made within the time frame, then you will start to see
176+
rate-limit errors during downloading that looks like:
177+
178+
```
179+
##[error]API rate limit exceeded for...
180+
```
181+
182+
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new)
183+
and pass it as the `github_token` input for the action:
184+
185+
```yaml
186+
uses: goreleaser/goreleaser-action@v4
187+
with:
188+
github_token: ${{ secrets.GH_DOTCOM_TOKEN }}
189+
version: v1.14.1
190+
```
191+
192+
If the runner is not able to access `github.com`, it will take the default one
193+
available on the GitHub Runner or runner's tool cache. See "[Setting up the
194+
tool cache on self-hosted runners without internet
195+
access](https://docs.github.com/en/[email protected]/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
196+
for more information.
165197

166198
## Customizing
167199

__tests__/github.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,43 @@ import * as github from '../src/github';
33

44
describe('github', () => {
55
it('returns latest GoReleaser GitHub release', async () => {
6-
const release = await github.getRelease('goreleaser', 'latest');
6+
const githubToken = process.env.GITHUB_TOKEN || '';
7+
const release = await github.getRelease('goreleaser', 'latest', githubToken);
78
expect(release).not.toBeNull();
89
expect(release?.tag_name).not.toEqual('');
910
});
1011

1112
it('returns v0.182.0 GoReleaser GitHub release', async () => {
12-
const release = await github.getRelease('goreleaser', 'v0.182.0');
13+
const githubToken = process.env.GITHUB_TOKEN || '';
14+
const release = await github.getRelease('goreleaser', 'v0.182.0', githubToken);
1315
expect(release).not.toBeNull();
1416
expect(release?.tag_name).toEqual('v0.182.0');
1517
});
1618

1719
it('returns v0.182.1 GoReleaser GitHub release', async () => {
18-
const release = await github.getRelease('goreleaser', '~> 0.182');
20+
const githubToken = process.env.GITHUB_TOKEN || '';
21+
const release = await github.getRelease('goreleaser', '~> 0.182', githubToken);
1922
expect(release).not.toBeNull();
2023
expect(release?.tag_name).toEqual('v0.182.1');
2124
});
2225

2326
it('returns latest GoReleaser Pro GitHub release', async () => {
24-
const release = await github.getRelease('goreleaser-pro', 'latest');
27+
const githubToken = process.env.GITHUB_TOKEN || '';
28+
const release = await github.getRelease('goreleaser-pro', 'latest', githubToken);
2529
expect(release).not.toBeNull();
2630
expect(release?.tag_name).not.toEqual('');
2731
});
2832

2933
it('returns v0.182.0-pro GoReleaser Pro GitHub release', async () => {
30-
const release = await github.getRelease('goreleaser-pro', 'v0.182.0-pro');
34+
const githubToken = process.env.GITHUB_TOKEN || '';
35+
const release = await github.getRelease('goreleaser-pro', 'v0.182.0-pro', githubToken);
3136
expect(release).not.toBeNull();
3237
expect(release?.tag_name).toEqual('v0.182.0-pro');
3338
});
3439

3540
it('returns v0.182.1-pro GoReleaser Pro GitHub release when using semver', async () => {
36-
const release = await github.getRelease('goreleaser-pro', '~> 0.182');
41+
const githubToken = process.env.GITHUB_TOKEN || '';
42+
const release = await github.getRelease('goreleaser-pro', '~> 0.182', githubToken);
3743
expect(release).not.toBeNull();
3844
expect(release?.tag_name).toEqual('v0.182.1-pro');
3945
});

__tests__/goreleaser.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import * as goreleaser from '../src/goreleaser';
44

55
describe('install', () => {
66
it('acquires v0.182.0 version of GoReleaser', async () => {
7-
const bin = await goreleaser.install('goreleaser', 'v0.182.0');
7+
const githubToken = process.env.GITHUB_TOKEN || '';
8+
const bin = await goreleaser.install('goreleaser', 'v0.182.0', githubToken);
89
expect(fs.existsSync(bin)).toBe(true);
910
}, 100000);
1011

1112
it('acquires latest version of GoReleaser', async () => {
12-
const bin = await goreleaser.install('goreleaser', 'latest');
13+
const githubToken = process.env.GITHUB_TOKEN || '';
14+
const bin = await goreleaser.install('goreleaser', 'latest', githubToken);
1315
expect(fs.existsSync(bin)).toBe(true);
1416
}, 100000);
1517

1618
it('acquires v0.182.0-pro version of GoReleaser Pro', async () => {
17-
const bin = await goreleaser.install('goreleaser-pro', 'v0.182.0-pro');
19+
const githubToken = process.env.GITHUB_TOKEN || '';
20+
const bin = await goreleaser.install('goreleaser-pro', 'v0.182.0-pro', githubToken);
1821
expect(fs.existsSync(bin)).toBe(true);
1922
}, 100000);
2023

2124
it('acquires latest version of GoReleaser Pro', async () => {
22-
const bin = await goreleaser.install('goreleaser-pro', 'latest');
25+
const githubToken = process.env.GITHUB_TOKEN || '';
26+
const bin = await goreleaser.install('goreleaser-pro', 'latest', githubToken);
2327
expect(fs.existsSync(bin)).toBe(true);
2428
}, 100000);
2529
});

action.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ inputs:
2626
description: 'Just install GoReleaser'
2727
default: 'false'
2828
required: false
29+
github-token:
30+
description: >
31+
Used to verifiy the Git tag exists on goreleaser/goreleaser repo. Since there's a
32+
default, this is typically not supplied by the user. When running this
33+
action on github.com, the default value is sufficient. When running on
34+
GHES, you can pass a personal access token for github.com if you are
35+
experiencing rate limiting.
36+
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
37+
required: false
2938

3039
outputs:
3140
artifacts:

dev.Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ ENV RUNNER_TEMP=/tmp/github_runner
6565
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
6666
RUN --mount=type=bind,target=.,rw \
6767
--mount=type=cache,target=/src/node_modules \
68-
yarn run test --coverageDirectory=/tmp/coverage
68+
--mount=type=secret,id=GITHUB_TOKEN \
69+
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) yarn run test --coverageDirectory=/tmp/coverage
6970

7071
FROM scratch AS test-coverage
7172
COPY --from=test /tmp/coverage /

dist/index.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)