Skip to content

Commit ec8dd7c

Browse files
authored
switching to fetching latest version from the dedicated file (#130)
1 parent efbd96d commit ec8dd7c

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

action.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ inputs:
66
required: true
77
default: 'latest'
88
token:
9-
description: GitHub token. Required only if 'version' == 'latest'
9+
description: GitHub token. Used to be required to fetch the latest version
1010
required: false
11+
deprecationMessage: 'GitHub token is no longer required'
1112
default: '${{ github.token }}'
1213
downloadBaseURL:
1314
description: 'Set the download base URL'

src/run.test.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,18 @@ describe('run.ts', () => {
8686
expect(os.type).toHaveBeenCalled()
8787
})
8888

89-
test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => {
89+
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
90+
const res = {
91+
status: 200,
92+
text: async () => 'v9.99.999'
93+
} as Response
94+
global.fetch = jest.fn().mockReturnValue(res)
95+
expect(await run.getLatestHelmVersion()).toBe('v9.99.999')
96+
})
97+
98+
test('getLatestHelmVersion() - return the stable version of HELM when simulating a network error', async () => {
99+
const errorMessage: string = 'Network Error'
100+
global.fetch = jest.fn().mockRejectedValueOnce(new Error(errorMessage))
90101
expect(await run.getLatestHelmVersion()).toBe('v3.13.3')
91102
})
92103

src/run.ts

+3-27
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as fs from 'fs'
99

1010
import * as toolCache from '@actions/tool-cache'
1111
import * as core from '@actions/core'
12-
import {Octokit} from '@octokit/action'
1312

1413
const helmToolName = 'helm'
1514
const stableHelmVersion = 'v3.13.3'
@@ -51,38 +50,15 @@ export function getValidVersion(version: string): string {
5150
// Gets the latest helm version or returns a default stable if getting latest fails
5251
export async function getLatestHelmVersion(): Promise<string> {
5352
try {
54-
const octokit = new Octokit()
55-
const response = await octokit.rest.repos.listReleases({
56-
owner: 'helm',
57-
repo: 'helm',
58-
per_page: 100,
59-
order: 'desc',
60-
sort: 'created'
61-
})
62-
63-
const releases = response.data
64-
const latestValidRelease: string = releases.find(
65-
({tag_name, draft, prerelease}) =>
66-
isValidVersion(tag_name) && !draft && !prerelease
67-
)?.tag_name
68-
69-
if (latestValidRelease) return latestValidRelease
53+
const response = await fetch('https://get.helm.sh/helm-latest-version')
54+
const release = (await response.text()).trim()
55+
return release
7056
} catch (err) {
7157
core.warning(
7258
`Error while fetching latest Helm release: ${err.toString()}. Using default version ${stableHelmVersion}`
7359
)
7460
return stableHelmVersion
7561
}
76-
77-
core.warning(
78-
`Could not find valid release. Using default version ${stableHelmVersion}`
79-
)
80-
return stableHelmVersion
81-
}
82-
83-
// isValidVersion checks if verison is a stable release
84-
function isValidVersion(version: string): boolean {
85-
return version.indexOf('rc') == -1
8662
}
8763

8864
export function getExecutableExtension(): string {

0 commit comments

Comments
 (0)