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: don't depend on the GitHub API to check release #391

Merged
merged 2 commits into from
Jan 30, 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
5 changes: 0 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ on:
- 'master'
- 'releases/v*'
pull_request:
branches:
- 'master'
- 'releases/v*'

jobs:
test:
Expand All @@ -29,8 +26,6 @@ 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
44 changes: 6 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ ___
* [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 @@ -163,37 +162,6 @@ 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/[email protected]/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 All @@ -215,17 +183,17 @@ Following inputs can be used as `step.with` keys

Following outputs are available

| Name | Type | Description |
|-------------------|---------|---------------------------------------|
| `artifacts` | JSON | Build result artifacts |
| `metadata` | JSON | Build result metadata |
| Name | Type | Description |
|-------------|------|------------------------|
| `artifacts` | JSON | Build result artifacts |
| `metadata` | JSON | Build result metadata |

### environment variables

Following environment variables can be used as `step.env` keys

| Name | Description |
|------------------|---------------------------------------|
| Name | Description |
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `GITHUB_TOKEN` | [GITHUB_TOKEN](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) as provided by `secrets` |
| `GORELEASER_KEY` | Your [GoReleaser Pro](https://goreleaser.com/pro) License Key, in case you are using the `goreleaser-pro` distribution |

Expand Down
36 changes: 21 additions & 15 deletions __tests__/github.test.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
import {describe, expect, it} from '@jest/globals';
import * as github from '../src/github';

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

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

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

it('unknown GoReleaser release', async () => {
await expect(github.getRelease('goreleaser', 'foo')).rejects.toThrowError(
new Error('Cannot find GoReleaser release foo in https://goreleaser.com/static/releases.json')
);
});

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

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

it('unknown GoReleaser Pro release', async () => {
await expect(github.getRelease('goreleaser-pro', 'foo')).rejects.toThrowError(
new Error('Cannot find GoReleaser release foo-pro in https://goreleaser.com/static/releases-pro.json')
);
});
});
12 changes: 4 additions & 8 deletions __tests__/goreleaser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,22 @@ import * as goreleaser from '../src/goreleaser';

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

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

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

it('acquires latest version of GoReleaser Pro', async () => {
const githubToken = process.env.GITHUB_TOKEN || '';
const bin = await goreleaser.install('goreleaser-pro', 'latest', githubToken);
const bin = await goreleaser.install('goreleaser-pro', 'latest');
expect(fs.existsSync(bin)).toBe(true);
}, 100000);
});
Expand Down
9 changes: 0 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ 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: 1 addition & 2 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ 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 \
--mount=type=secret,id=GITHUB_TOKEN \
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) yarn run test --coverageDirectory=/tmp/coverage
yarn run test --coverageDirectory=/tmp/coverage

FROM scratch AS test-coverage
COPY --from=test /tmp/coverage /
8 changes: 1 addition & 7 deletions 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