Skip to content

Commit bf2f02c

Browse files
Pass the token input through on GHES for Microsoft Build of OpenJDK (actions#395)
1 parent de1bb2b commit bf2f02c

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ inputs:
5959
description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting'
6060
default: ${{ job.status }}
6161
token:
62-
description: Used to pull java versions from setup-java. Since there is a default value, token is typically not supplied by the user.
63-
default: ${{ github.token }}
62+
description: The token used to authenticate when fetching version manifests hosted on github.com, such as for the Microsoft Build of OpenJDK. 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.
63+
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
6464
mvn-toolchain-id:
6565
description: 'Name of Maven Toolchain ID if the default name of "${distribution}_${java-version}" is not wanted. See examples of supported syntax in Advanced Usage file'
6666
required: false

dist/setup/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104539,14 +104539,15 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
104539104539
// TODO get these dynamically!
104540104540
// We will need Microsoft to add an endpoint where we can query for versions.
104541104541
const token = core.getInput('token');
104542+
const auth = !token ? undefined : `token ${token}`;
104542104543
const owner = 'actions';
104543104544
const repository = 'setup-java';
104544104545
const branch = 'main';
104545104546
const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json';
104546104547
let releases = null;
104547104548
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
104548104549
const headers = {
104549-
authorization: token,
104550+
authorization: auth,
104550104551
accept: 'application/vnd.github.VERSION.raw'
104551104552
};
104552104553
let response = null;

docs/advanced-usage.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ steps:
8080
- run: java -cp java HelloWorldApp
8181
```
8282

83+
### Using Microsoft distribution on GHES
84+
85+
`setup-java` comes pre-installed on the appliance with GHES if Actions is enabled. When dynamically downloading the Microsoft Build of OpenJDK distribution, `setup-java` makes a request to `actions/setup-java` to get available versions on github.com (outside of the appliance). These calls to `actions/setup-java` 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...`.
86+
87+
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 `token` input for the action:
88+
89+
```yaml
90+
uses: actions/setup-java@v3
91+
with:
92+
token: ${{ secrets.GH_DOTCOM_TOKEN }}
93+
distribution: 'microsoft'
94+
java-version: '11'
95+
```
96+
97+
If the runner is not able to access github.com, any Java versions requested during a workflow run must come from the 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.
98+
8399
### Amazon Corretto
84100
**NOTE:** Amazon Corretto only supports the major version specification.
85101

src/distributions/microsoft/installer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class MicrosoftDistributions extends JavaBase {
7373
// TODO get these dynamically!
7474
// We will need Microsoft to add an endpoint where we can query for versions.
7575
const token = core.getInput('token');
76+
const auth = !token ? undefined : `token ${token}`;
7677
const owner = 'actions';
7778
const repository = 'setup-java';
7879
const branch = 'main';
@@ -82,7 +83,7 @@ export class MicrosoftDistributions extends JavaBase {
8283
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
8384

8485
const headers: OutgoingHttpHeaders = {
85-
authorization: token,
86+
authorization: auth,
8687
accept: 'application/vnd.github.VERSION.raw'
8788
};
8889

0 commit comments

Comments
 (0)