Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use @action/github #390

Merged
merged 3 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
uses: docker/bake-action@v2
with:
targets: test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Upload coverage
uses: codecov/codecov-action@v3
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ___
* [Signing](#signing)
* [Upload artifacts](#upload-artifacts)
* [Install Only](#install-only)
* [Using on GHES](#using-on-ghes)
* [Customizing](#customizing)
* [inputs](#inputs)
* [outputs](#outputs)
Expand Down Expand Up @@ -162,6 +163,37 @@ steps:
name: Show GoReleaser version
run: goreleaser -v
```
### Using on GHES

If you specify a version or `latest` of GoReleaser in your workflow, the
version will be downloaded from [GitHub Releases in
`goreleaser/goreleaser`](https://github.com/goreleaser/goreleaser/releases)
repository. These calls to `goreleaser/goreleaser` are made via unauthenticated
requests, which are limited to [60 requests per hour per
IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting).

If more requests are made within the time frame, then you will start to see
rate-limit errors during downloading that looks like:

```
##[error]API rate limit exceeded for...
```

To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new)
and pass it as the `github_token` input for the action:

```yaml
uses: goreleaser/goreleaser-action@v4
with:
github_token: ${{ secrets.GH_DOTCOM_TOKEN }}
version: v1.14.1
```

If the runner is not able to access `github.com`, it will take the default one
available on the GitHub Runner or runner's tool cache. See "[Setting up the
tool cache on self-hosted runners without internet
access](https://docs.github.com/en/enterprise-server@3.2/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
for more information.

## Customizing

Expand Down
18 changes: 12 additions & 6 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,43 @@ import * as github from '../src/github';

describe('github', () => {
it('returns latest GoReleaser GitHub release', async () => {
const release = await github.getRelease('goreleaser', 'latest');
const githubToken = process.env.GITHUB_TOKEN || '';
const release = await github.getRelease('goreleaser', 'latest', githubToken);
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});

it('returns v0.182.0 GoReleaser GitHub release', async () => {
const release = await github.getRelease('goreleaser', 'v0.182.0');
const githubToken = process.env.GITHUB_TOKEN || '';
const release = await github.getRelease('goreleaser', 'v0.182.0', githubToken);
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v0.182.0');
});

it('returns v0.182.1 GoReleaser GitHub release', async () => {
const release = await github.getRelease('goreleaser', '~> 0.182');
const githubToken = process.env.GITHUB_TOKEN || '';
const release = await github.getRelease('goreleaser', '~> 0.182', githubToken);
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v0.182.1');
});

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

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

it('returns v0.182.1-pro GoReleaser Pro GitHub release when using semver', async () => {
const release = await github.getRelease('goreleaser-pro', '~> 0.182');
const githubToken = process.env.GITHUB_TOKEN || '';
const release = await github.getRelease('goreleaser-pro', '~> 0.182', githubToken);
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v0.182.1-pro');
});
Expand Down
12 changes: 8 additions & 4 deletions __tests__/goreleaser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ import * as goreleaser from '../src/goreleaser';

describe('install', () => {
it('acquires v0.182.0 version of GoReleaser', async () => {
const bin = await goreleaser.install('goreleaser', 'v0.182.0');
const githubToken = process.env.GITHUB_TOKEN || '';
const bin = await goreleaser.install('goreleaser', 'v0.182.0', githubToken);
expect(fs.existsSync(bin)).toBe(true);
}, 100000);

it('acquires latest version of GoReleaser', async () => {
const bin = await goreleaser.install('goreleaser', 'latest');
const githubToken = process.env.GITHUB_TOKEN || '';
const bin = await goreleaser.install('goreleaser', 'latest', githubToken);
expect(fs.existsSync(bin)).toBe(true);
}, 100000);

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

it('acquires latest version of GoReleaser Pro', async () => {
const bin = await goreleaser.install('goreleaser-pro', 'latest');
const githubToken = process.env.GITHUB_TOKEN || '';
const bin = await goreleaser.install('goreleaser-pro', 'latest', githubToken);
expect(fs.existsSync(bin)).toBe(true);
}, 100000);
});
Expand Down
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ inputs:
description: 'Just install GoReleaser'
default: 'false'
required: false
github-token:
description: >
Used to verifiy the Git tag exists on goreleaser/goreleaser repo. Since there's a
default, this is typically not supplied by the user. When running this
action on github.com, the default value is sufficient. When running on
GHES, you can pass a personal access token for github.com if you are
experiencing rate limiting.
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
required: false

outputs:
artifacts:
Expand Down
3 changes: 2 additions & 1 deletion dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ ENV RUNNER_TEMP=/tmp/github_runner
ENV RUNNER_TOOL_CACHE=/tmp/github_tool_cache
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/src/node_modules \
yarn run test --coverageDirectory=/tmp/coverage
--mount=type=secret,id=GITHUB_TOKEN \
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) yarn run test --coverageDirectory=/tmp/coverage

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage /
8 changes: 7 additions & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

Loading