mirror of
https://github.com/Azure/setup-helm.git
synced 2026-04-14 10:34:47 +00:00
Action update:
- Bump all dependencies - Rewrite `getLatestHelmVersion()` function without graphql
This commit is contained in:
parent
1f87a575d0
commit
80968fd4ae
4 changed files with 1241 additions and 8763 deletions
|
|
@ -86,8 +86,8 @@ describe('run.ts', () => {
|
|||
expect(os.type).toBeCalled()
|
||||
})
|
||||
|
||||
test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => {
|
||||
expect(await run.getLatestHelmVersion()).toBe('v3.11.1')
|
||||
test('getLatestHelmVersion() - check that returned value matches helm version regex', async () => {
|
||||
expect(await run.getLatestHelmVersion()).toMatch(/^v\d+\.\d+\.\d+$/)
|
||||
})
|
||||
|
||||
test('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
||||
|
|
|
|||
37
src/run.ts
37
src/run.ts
|
|
@ -9,8 +9,7 @@ import * as fs from 'fs'
|
|||
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
import * as core from '@actions/core'
|
||||
import {graphql} from '@octokit/graphql'
|
||||
import {createActionAuth} from '@octokit/auth-action'
|
||||
import * as http from '@actions/http-client'
|
||||
|
||||
const helmToolName = 'helm'
|
||||
const stableHelmVersion = 'v3.11.1'
|
||||
|
|
@ -52,43 +51,17 @@ 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 auth = createActionAuth()
|
||||
const graphqlAuthenticated = graphql.defaults({
|
||||
request: {hook: auth.hook}
|
||||
})
|
||||
const {repository} = await graphqlAuthenticated(
|
||||
`
|
||||
{
|
||||
repository(name: "helm", owner: "helm") {
|
||||
releases(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||
nodes {
|
||||
tagName
|
||||
isLatest
|
||||
isDraft
|
||||
isPrerelease
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
const httpClient = new http.HttpClient()
|
||||
const response = await httpClient.getJson<any>(
|
||||
'https://github.com/helm/helm/releases/latest'
|
||||
)
|
||||
const latestValidRelease: string = repository.releases.nodes.find(
|
||||
({tagName, isLatest, isDraft, isPreRelease}) =>
|
||||
isValidVersion(tagName) && isLatest && !isDraft && !isPreRelease
|
||||
)?.tagName
|
||||
|
||||
if (latestValidRelease) return latestValidRelease
|
||||
return response.result.tag_name
|
||||
} 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue