Skip to content

Commit

Permalink
Pass the token input through on GHES for Microsoft Build of OpenJDK (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-shibanov committed Nov 18, 2022
1 parent de1bb2b commit bf2f02c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions action.yml
Expand Up @@ -59,8 +59,8 @@ inputs:
description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting'
default: ${{ job.status }}
token:
description: Used to pull java versions from setup-java. Since there is a default value, token is typically not supplied by the user.
default: ${{ github.token }}
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.
default: ${{ github.server_url == 'https://github.com' && github.token || '' }}
mvn-toolchain-id:
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'
required: false
Expand Down
3 changes: 2 additions & 1 deletion dist/setup/index.js
Expand Up @@ -104539,14 +104539,15 @@ class MicrosoftDistributions extends base_installer_1.JavaBase {
// TODO get these dynamically!
// We will need Microsoft to add an endpoint where we can query for versions.
const token = core.getInput('token');
const auth = !token ? undefined : `token ${token}`;
const owner = 'actions';
const repository = 'setup-java';
const branch = 'main';
const filePath = 'src/distributions/microsoft/microsoft-openjdk-versions.json';
let releases = null;
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;
const headers = {
authorization: token,
authorization: auth,
accept: 'application/vnd.github.VERSION.raw'
};
let response = null;
Expand Down
16 changes: 16 additions & 0 deletions docs/advanced-usage.md
Expand Up @@ -80,6 +80,22 @@ steps:
- run: java -cp java HelloWorldApp
```

### Using Microsoft distribution on GHES

`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...`.

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:

```yaml
uses: actions/setup-java@v3
with:
token: ${{ secrets.GH_DOTCOM_TOKEN }}
distribution: 'microsoft'
java-version: '11'
```

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.

### Amazon Corretto
**NOTE:** Amazon Corretto only supports the major version specification.

Expand Down
3 changes: 2 additions & 1 deletion src/distributions/microsoft/installer.ts
Expand Up @@ -73,6 +73,7 @@ export class MicrosoftDistributions extends JavaBase {
// TODO get these dynamically!
// We will need Microsoft to add an endpoint where we can query for versions.
const token = core.getInput('token');
const auth = !token ? undefined : `token ${token}`;
const owner = 'actions';
const repository = 'setup-java';
const branch = 'main';
Expand All @@ -82,7 +83,7 @@ export class MicrosoftDistributions extends JavaBase {
const fileUrl = `https://api.github.com/repos/${owner}/${repository}/contents/${filePath}?ref=${branch}`;

const headers: OutgoingHttpHeaders = {
authorization: token,
authorization: auth,
accept: 'application/vnd.github.VERSION.raw'
};

Expand Down

0 comments on commit bf2f02c

Please sign in to comment.