switching to fetching latest version from the dedicated file (#130)

This commit is contained in:
elProxy 2024-03-01 17:15:56 +01:00 committed by GitHub
parent efbd96d464
commit ec8dd7c209
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 29 deletions

View File

@ -6,8 +6,9 @@ inputs:
required: true required: true
default: 'latest' default: 'latest'
token: token:
description: GitHub token. Required only if 'version' == 'latest' description: GitHub token. Used to be required to fetch the latest version
required: false required: false
deprecationMessage: 'GitHub token is no longer required'
default: '${{ github.token }}' default: '${{ github.token }}'
downloadBaseURL: downloadBaseURL:
description: 'Set the download base URL' description: 'Set the download base URL'

View File

@ -86,7 +86,18 @@ describe('run.ts', () => {
expect(os.type).toHaveBeenCalled() 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') expect(await run.getLatestHelmVersion()).toBe('v3.13.3')
}) })

View File

@ -9,7 +9,6 @@ import * as fs from 'fs'
import * as toolCache from '@actions/tool-cache' import * as toolCache from '@actions/tool-cache'
import * as core from '@actions/core' import * as core from '@actions/core'
import {Octokit} from '@octokit/action'
const helmToolName = 'helm' const helmToolName = 'helm'
const stableHelmVersion = 'v3.13.3' 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 // Gets the latest helm version or returns a default stable if getting latest fails
export async function getLatestHelmVersion(): Promise<string> { export async function getLatestHelmVersion(): Promise<string> {
try { try {
const octokit = new Octokit() const response = await fetch('https://get.helm.sh/helm-latest-version')
const response = await octokit.rest.repos.listReleases({ const release = (await response.text()).trim()
owner: 'helm', return release
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
} catch (err) { } catch (err) {
core.warning( core.warning(
`Error while fetching latest Helm release: ${err.toString()}. Using default version ${stableHelmVersion}` `Error while fetching latest Helm release: ${err.toString()}. Using default version ${stableHelmVersion}`
) )
return 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 { export function getExecutableExtension(): string {