diff --git a/action.yml b/action.yml index a06dbbe..b67b5fb 100644 --- a/action.yml +++ b/action.yml @@ -6,8 +6,9 @@ inputs: required: true default: 'latest' token: - description: GitHub token. Required only if 'version' == 'latest' + description: GitHub token. Used to be required to fetch the latest version required: false + deprecationMessage: 'GitHub token is no longer required' default: '${{ github.token }}' downloadBaseURL: description: 'Set the download base URL' diff --git a/src/run.test.ts b/src/run.test.ts index b9e2d24..fc324ab 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -86,7 +86,18 @@ describe('run.ts', () => { expect(os.type).toHaveBeenCalled() }) - test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => { + test('getLatestHelmVersion() - return the latest version of HELM', async () => { + const res = { + status: 200, + text: async () => 'v9.99.999' + } as Response + global.fetch = jest.fn().mockReturnValue(res) + expect(await run.getLatestHelmVersion()).toBe('v9.99.999') + }) + + test('getLatestHelmVersion() - return the stable version of HELM when simulating a network error', async () => { + const errorMessage: string = 'Network Error' + global.fetch = jest.fn().mockRejectedValueOnce(new Error(errorMessage)) expect(await run.getLatestHelmVersion()).toBe('v3.13.3') }) diff --git a/src/run.ts b/src/run.ts index 839eeac..aaab9ec 100644 --- a/src/run.ts +++ b/src/run.ts @@ -9,7 +9,6 @@ import * as fs from 'fs' import * as toolCache from '@actions/tool-cache' import * as core from '@actions/core' -import {Octokit} from '@octokit/action' const helmToolName = 'helm' const stableHelmVersion = 'v3.13.3' @@ -51,38 +50,15 @@ export function getValidVersion(version: string): string { // Gets the latest helm version or returns a default stable if getting latest fails export async function getLatestHelmVersion(): Promise { try { - const octokit = new Octokit() - const response = await octokit.rest.repos.listReleases({ - owner: 'helm', - repo: 'helm', - per_page: 100, - order: 'desc', - sort: 'created' - }) - - const releases = response.data - const latestValidRelease: string = releases.find( - ({tag_name, draft, prerelease}) => - isValidVersion(tag_name) && !draft && !prerelease - )?.tag_name - - if (latestValidRelease) return latestValidRelease + const response = await fetch('https://get.helm.sh/helm-latest-version') + const release = (await response.text()).trim() + return release } catch (err) { core.warning( `Error while fetching latest Helm release: ${err.toString()}. Using default version ${stableHelmVersion}` ) return stableHelmVersion } - - core.warning( - `Could not find valid release. Using default version ${stableHelmVersion}` - ) - return stableHelmVersion -} - -// isValidVersion checks if verison is a stable release -function isValidVersion(version: string): boolean { - return version.indexOf('rc') == -1 } export function getExecutableExtension(): string {