4
0
Fork 0
mirror of https://github.com/Azure/setup-helm.git synced 2025-11-07 13:06:56 +00:00

Action update:

- Bump all dependencies
- Rewrite `getLatestHelmVersion()` function without graphql
This commit is contained in:
Dmytro Bondar 2024-01-27 22:27:03 +01:00
parent 1f87a575d0
commit 80968fd4ae
No known key found for this signature in database
GPG key ID: 8CC54FADB0C40187
4 changed files with 1241 additions and 8763 deletions

9946
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -8,11 +8,10 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/http-client": "^2.2.0",
"@actions/io": "^1.1.2", "@actions/io": "^1.1.2",
"@actions/tool-cache": "2.0.1", "@actions/tool-cache": "2.0.1",
"@octokit/auth-action": "^2.0.0", "semver": "^7.5.4"
"@octokit/graphql": "^4.6.1",
"semver": "^6.1.0"
}, },
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
@ -23,11 +22,11 @@
"format-check": "prettier --check ." "format-check": "prettier --check ."
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.0", "@types/jest": "^29.5.11",
"@types/node": "^12.0.10", "@types/node": "^20.11.8",
"@vercel/ncc": "^0.34.0", "@vercel/ncc": "^0.38.1",
"jest": "^26.0.1", "jest": "^29.7.0",
"ts-jest": "^26.0.0", "ts-jest": "^29.1.2",
"typescript": "^3.5.2" "typescript": "^5.3.3"
} }
} }

View file

@ -86,8 +86,8 @@ describe('run.ts', () => {
expect(os.type).toBeCalled() expect(os.type).toBeCalled()
}) })
test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => { test('getLatestHelmVersion() - check that returned value matches helm version regex', async () => {
expect(await run.getLatestHelmVersion()).toBe('v3.11.1') expect(await run.getLatestHelmVersion()).toMatch(/^v\d+\.\d+\.\d+$/)
}) })
test('walkSync() - return path to the all files matching fileToFind in dir', () => { test('walkSync() - return path to the all files matching fileToFind in dir', () => {

View file

@ -9,8 +9,7 @@ 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 {graphql} from '@octokit/graphql' import * as http from '@actions/http-client'
import {createActionAuth} from '@octokit/auth-action'
const helmToolName = 'helm' const helmToolName = 'helm'
const stableHelmVersion = 'v3.11.1' 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 // 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 auth = createActionAuth() const httpClient = new http.HttpClient()
const graphqlAuthenticated = graphql.defaults({ const response = await httpClient.getJson<any>(
request: {hook: auth.hook} 'https://github.com/helm/helm/releases/latest'
})
const {repository} = await graphqlAuthenticated(
`
{
repository(name: "helm", owner: "helm") {
releases(first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
nodes {
tagName
isLatest
isDraft
isPrerelease
}
}
}
}
`
) )
const latestValidRelease: string = repository.releases.nodes.find( return response.result.tag_name
({tagName, isLatest, isDraft, isPreRelease}) =>
isValidVersion(tagName) && isLatest && !isDraft && !isPreRelease
)?.tagName
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 // isValidVersion checks if verison is a stable release