Skip to content

Commit

Permalink
fix: use @action/github (#390)
Browse files Browse the repository at this point in the history
* fix: use @action/github

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* Update README.md

Co-authored-by: CrazyMax <github@crazymax.dev>

* Update action.yml

Co-authored-by: CrazyMax <github@crazymax.dev>

---------

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
Co-authored-by: CrazyMax <github@crazymax.dev>
  • Loading branch information
3 people committed Jan 28, 2023
1 parent b1a2381 commit 9754a25
Show file tree
Hide file tree
Showing 16 changed files with 834 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
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
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
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
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
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
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.

0 comments on commit 9754a25

Please sign in to comment.