Skip to content

Commit

Permalink
Simply fetch latest version from the dedicated file
Browse files Browse the repository at this point in the history
It gets updated as part of the helm release workflow:
https://github.com/helm/helm/blob/c5698e5e51949c4ab86a22c5566fac20e13d6f73/.github/workflows/release.yml#L49

This means the github token is no longer required, making it much nicer
for composite actions wanting to leverage this one.
  • Loading branch information
elProxy committed Feb 26, 2024
1 parent 859dc38 commit cb38b0b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ inputs:
required: true
default: 'latest'
token:
description: GitHub token. Required only if 'version' == 'latest'
description: GitHub token. Used to be reuired to fetch the latest version
required: false
deprecationMessage: 'GitHub token is no longer required'
default: '${{ github.token }}'
downloadBaseURL:
description: 'Set the download base URL'
Expand Down
8 changes: 7 additions & 1 deletion src/run.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ 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 () => {
expect(await run.getLatestHelmVersion()).toBe('v3.14.2')
})

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')
})

Expand Down
30 changes: 3 additions & 27 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<string> {
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 {
Expand Down

0 comments on commit cb38b0b

Please sign in to comment.