Skip to content

Commit 39322d9

Browse files
committed
don't depend on the GitHub API to check release
Signed-off-by: CrazyMax <[email protected]>
1 parent 0648fd6 commit 39322d9

File tree

13 files changed

+60
-261
lines changed

13 files changed

+60
-261
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ jobs:
3030
uses: docker/bake-action@v2
3131
with:
3232
targets: test
33-
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3533
-
3634
name: Upload coverage
3735
uses: codecov/codecov-action@v3

README.md

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ ___
2828
* [Notes](#notes)
2929
* [`nodes` output](#nodes-output)
3030
* [BuildKit container logs](#buildkit-container-logs)
31-
* [Using on GHES](#using-on-ghes)
3231
* [Contributing](#contributing)
3332

3433
## Usage
@@ -175,35 +174,6 @@ The following [official docker environment variables](https://docs.docker.com/en
175174

176175
See https://docs.docker.com/build/ci/github-actions/configure-builder/#buildkit-container-logs
177176

178-
## Using on GHES
179-
180-
GitHub Runners come [pre-installed with Docker Buildx](https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md)
181-
following your virtual environment. If you specify a version or `latest` of
182-
Docker Buildx in your workflow, the version will be downloaded from [GitHub Releases in `docker/buildx`](https://github.com/docker/buildx/releases)
183-
repository. These calls to `docker/buildx` are made via unauthenticated requests,
184-
which are limited to [60 requests per hour per IP](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting).
185-
186-
If more requests are made within the time frame, then you will start to see
187-
rate-limit errors during downloading that looks like:
188-
189-
```
190-
##[error]API rate limit exceeded for...
191-
```
192-
193-
To get a higher rate limit, you can [generate a personal access token on github.com](https://github.com/settings/tokens/new)
194-
and pass it as the `github_token` input for the action:
195-
196-
```yaml
197-
uses: docker/setup-buildx-action@v2
198-
with:
199-
github_token: ${{ secrets.GH_DOTCOM_TOKEN }}
200-
version: v0.10.1
201-
```
202-
203-
If the runner is not able to access `github.com`, it will take the default one
204-
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/admin/github-actions/managing-access-to-actions-from-githubcom/setting-up-the-tool-cache-on-self-hosted-runners-without-internet-access)"
205-
for more information.
206-
207177
## Contributing
208178

209179
Want to contribute? Awesome! You can find information about contributing to

__tests__/buildx.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ describe('isAvailable', () => {
2828
});
2929
});
3030

31+
describe('getRelease', () => {
32+
it('returns latest buildx GitHub release', async () => {
33+
const release = await buildx.getRelease('latest');
34+
expect(release).not.toBeNull();
35+
expect(release?.tag_name).not.toEqual('');
36+
});
37+
38+
it('returns v0.10.1 buildx GitHub release', async () => {
39+
const release = await buildx.getRelease('v0.10.1');
40+
expect(release).not.toBeNull();
41+
expect(release?.id).toEqual(90346950);
42+
expect(release?.tag_name).toEqual('v0.10.1');
43+
expect(release?.html_url).toEqual('https://github.com/docker/buildx/releases/tag/v0.10.1');
44+
});
45+
46+
it('returns v0.2.2 buildx GitHub release', async () => {
47+
const release = await buildx.getRelease('v0.2.2');
48+
expect(release).not.toBeNull();
49+
expect(release?.id).toEqual(17671545);
50+
expect(release?.tag_name).toEqual('v0.2.2');
51+
expect(release?.html_url).toEqual('https://github.com/docker/buildx/releases/tag/v0.2.2');
52+
});
53+
54+
it('unknown release', async () => {
55+
await expect(buildx.getRelease('foo')).rejects.toThrowError(new Error('Cannot find Buildx release foo in https://raw.githubusercontent.com/docker/buildx/master/.github/releases.json'));
56+
});
57+
});
58+
3159
describe('isAvailable standalone', () => {
3260
const execSpy = jest.spyOn(exec, 'getExecOutput');
3361
buildx.isAvailable(true);
@@ -221,7 +249,7 @@ describe('install', () => {
221249
])(
222250
'acquires %p of buildx (standalone: %p)',
223251
async (version, standalone) => {
224-
const buildxBin = await buildx.install(version, process.env.GITHUB_TOKEN || '', tmpDir, standalone);
252+
const buildxBin = await buildx.install(version, tmpDir, standalone);
225253
expect(fs.existsSync(buildxBin)).toBe(true);
226254
},
227255
100000

__tests__/github.test.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

action.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ inputs:
4444
append:
4545
description: 'Append additional nodes to the builder'
4646
required: false
47-
github_token:
48-
# https://github.com/actions/setup-go/blob/21459d0b7b1d63741429b748885bf5a4974593b4/action.yml#L12-L14
49-
description: >
50-
Used to verifiy the Git tag exists on docker/buildx repo. Since there's a
51-
default, this is typically not supplied by the user. When running this
52-
action on github.com, the default value is sufficient. When running on
53-
GHES, you can pass a personal access token for github.com if you are
54-
experiencing rate limiting.
55-
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
5647

5748
outputs:
5849
name:

dev.Dockerfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ RUN --mount=type=bind,target=.,rw \
7272
--mount=type=cache,target=/src/node_modules \
7373
--mount=type=bind,from=docker,source=/usr/local/bin/docker,target=/usr/bin/docker \
7474
--mount=type=bind,from=buildx,source=/buildx,target=/usr/libexec/docker/cli-plugins/docker-buildx \
75-
--mount=type=secret,id=GITHUB_TOKEN \
76-
GITHUB_TOKEN=$(cat /run/secrets/GITHUB_TOKEN) yarn run test --coverageDirectory=/tmp/coverage
75+
yarn run test --coverageDirectory=/tmp/coverage
7776

7877
FROM scratch AS test-coverage
7978
COPY --from=test /tmp/coverage /

docker-bake.hcl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ target "test" {
5050
dockerfile = "dev.Dockerfile"
5151
target = "test-coverage"
5252
output = ["./coverage"]
53-
secret = ["id=GITHUB_TOKEN,env=GITHUB_TOKEN"]
5453
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"dependencies": {
3030
"@actions/core": "^1.10.0",
3131
"@actions/exec": "^1.1.1",
32-
"@actions/github": "^5.1.1",
32+
"@actions/http-client": "^2.0.1",
3333
"@actions/tool-cache": "^2.0.1",
3434
"csv-parse": "^5.3.3",
3535
"js-yaml": "^4.1.0",

src/buildx.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as semver from 'semver';
44
import * as util from 'util';
55
import * as context from './context';
66
import * as git from './git';
7-
import * as github from './github';
87
import * as core from '@actions/core';
98
import * as exec from '@actions/exec';
9+
import * as httpm from '@actions/http-client';
1010
import * as tc from '@actions/tool-cache';
1111

1212
export type Builder = {
@@ -25,6 +25,29 @@ export type Node = {
2525
platforms?: string;
2626
};
2727

28+
export interface GitHubRelease {
29+
id: number;
30+
tag_name: string;
31+
html_url: string;
32+
assets: Array<string>;
33+
}
34+
35+
export const getRelease = async (version: string): Promise<GitHubRelease> => {
36+
const url = `https://raw.githubusercontent.com/docker/buildx/master/.github/releases.json`;
37+
const http: httpm.HttpClient = new httpm.HttpClient('setup-buildx');
38+
const resp: httpm.HttpClientResponse = await http.get(url);
39+
const body = await resp.readBody();
40+
const statusCode = resp.message.statusCode || 500;
41+
if (statusCode >= 400) {
42+
throw new Error(`Failed to get Buildx release ${version} from ${url} with status code ${statusCode}: ${body}`);
43+
}
44+
const releases = <Record<string, GitHubRelease>>JSON.parse(body);
45+
if (!releases[version]) {
46+
throw new Error(`Cannot find Buildx release ${version} in ${url}`);
47+
}
48+
return releases[version];
49+
};
50+
2851
export async function getConfigInline(s: string): Promise<string> {
2952
return getConfig(s, false);
3053
}
@@ -237,13 +260,8 @@ export async function build(inputBuildRef: string, dest: string, standalone: boo
237260
return setPlugin(toolPath, dest);
238261
}
239262

240-
export async function install(inputVersion: string, githubToken: string, dest: string, standalone: boolean): Promise<string> {
241-
let release: github.Release;
242-
if (inputVersion == 'latest') {
243-
release = await github.getLatestRelease(githubToken);
244-
} else {
245-
release = await github.getReleaseTag(inputVersion, githubToken);
246-
}
263+
export async function install(inputVersion: string, dest: string, standalone: boolean): Promise<string> {
264+
const release: GitHubRelease = await getRelease(inputVersion);
247265
core.debug(`Release ${release.tag_name} found`);
248266
const version = release.tag_name.replace(/^v+|v+$/g, '');
249267

src/context.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export interface Inputs {
3636
config: string;
3737
configInline: string;
3838
append: string;
39-
githubToken: string;
4039
}
4140

4241
export async function getInputs(): Promise<Inputs> {
@@ -52,8 +51,7 @@ export async function getInputs(): Promise<Inputs> {
5251
endpoint: core.getInput('endpoint'),
5352
config: core.getInput('config'),
5453
configInline: core.getInput('config-inline'),
55-
append: core.getInput('append'),
56-
githubToken: core.getInput('github_token')
54+
append: core.getInput('append')
5755
};
5856
}
5957

0 commit comments

Comments
 (0)