From 6d2c5e1f82f180ae79f799f0ed6e3e5efb4e664d Mon Sep 17 00:00:00 2001 From: Gregory Mitchell <54124162+gmitch215@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:33:58 -0500 Subject: [PATCH] Update Authorization, Add Documentation --- dist/setup/index.js | 8 ++++---- docs/advanced-usage.md | 15 +++++++++++++++ src/distributions/jetbrains/installer.ts | 8 +++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 9ba0192..0f960d3 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -124201,10 +124201,10 @@ class JetBrainsDistribution extends base_installer_1.JavaBase { const rawVersions = []; while (true) { const requestArguments = `per_page=100&page=${page_index}`; - const requestHeaders = { - "User-Agent": "jetbrains-jbr-installer", - "Authorization": `Token ${process.env.GITHUB_TOKEN}`, - }; + const requestHeaders = {}; + if (process.env.GITHUB_TOKEN) { + requestHeaders['Authorization'] = `Bearer ${process.env.GITHUB_TOKEN}`; + } const rawUrl = `https://api.github.com/repos/JetBrains/JetBrainsRuntime/releases?${requestArguments}`; if (core.isDebug() && page_index === 1) { // url is identical except page_index so print it once for debug diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 62ead09..c0b73be 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -156,6 +156,21 @@ steps: - run: java -cp java HelloWorldApp ``` +The JetBrains installer uses the GitHub API to fetch the latest version. If you believe your project is going to be running into rate limits, you can provide a +GitHub token to the action to increase the rate limit. Set the `GITHUB_TOKEN` environment variable to the value of your GitHub token in the workflow file. + +```yaml +steps: +- uses: actions/checkout@v4 +- uses: actions/setup-java@v4 + with: + distribution: 'jetbrains' + java-version: '11' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +- run: java -cp java HelloWorldApp +``` + ## Installing custom Java package type ```yaml steps: diff --git a/src/distributions/jetbrains/installer.ts b/src/distributions/jetbrains/installer.ts index 6bcc713..a4ea614 100644 --- a/src/distributions/jetbrains/installer.ts +++ b/src/distributions/jetbrains/installer.ts @@ -98,10 +98,12 @@ export class JetBrainsDistribution extends JavaBase { const rawVersions: IJetBrainsRawVersion[] = []; while (true) { const requestArguments = `per_page=100&page=${page_index}`; - const requestHeaders: OutgoingHttpHeaders = { - "User-Agent": "jetbrains-jbr-installer", - "Authorization": `Token ${process.env.GITHUB_TOKEN}`, + const requestHeaders: OutgoingHttpHeaders = {} + + if (process.env.GITHUB_TOKEN) { + requestHeaders['Authorization'] = `Bearer ${process.env.GITHUB_TOKEN}`; } + const rawUrl = `https://api.github.com/repos/JetBrains/JetBrainsRuntime/releases?${requestArguments}`; if (core.isDebug() && page_index === 1) {