mirror of
https://github.com/Azure/setup-helm.git
synced 2025-11-07 21:16:57 +00:00
swap to graphql
This commit is contained in:
parent
6e32762c2e
commit
42a468462c
3 changed files with 30 additions and 21 deletions
|
|
@ -9,14 +9,16 @@ Acceptable values are latest or any semantic version string like v3.5.0 Use this
|
||||||
```yaml
|
```yaml
|
||||||
- uses: azure/setup-helm@v3
|
- uses: azure/setup-helm@v3
|
||||||
with:
|
with:
|
||||||
version: '<version>' # default is latest stable
|
version: '<version>' # default is latest (stable)
|
||||||
id: install
|
id: install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> Note: When using latest version you might hit the GitHub GraphQL API hourly rate limit of 5,000. The action will then return the hardcoded default stable version (currently v3.9.0). If you rely on a certain version higher than the default, you should use that version instead of latest.
|
||||||
|
|
||||||
The cached helm binary path is prepended to the PATH environment variable as well as stored in the helm-path output variable.
|
The cached helm binary path is prepended to the PATH environment variable as well as stored in the helm-path output variable.
|
||||||
Refer to the action metadata file for details about all the inputs https://github.com/Azure/setup-helm/blob/master/action.yml
|
Refer to the action metadata file for details about all the inputs https://github.com/Azure/setup-helm/blob/master/action.yml
|
||||||
|
|
||||||
# Contributing
|
## Contributing
|
||||||
|
|
||||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
||||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ describe('run.ts', () => {
|
||||||
expect(os.type).toBeCalled()
|
expect(os.type).toBeCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
|
test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => {
|
||||||
try {
|
try {
|
||||||
expect(await run.getLatestHelmVersion()).toBe('v3.8.0')
|
expect(await run.getLatestHelmVersion()).toBe('v3.8.0')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
43
src/run.ts
43
src/run.ts
|
|
@ -9,10 +9,10 @@ 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'
|
||||||
|
|
||||||
const helmToolName = 'helm'
|
const helmToolName = 'helm'
|
||||||
const stableHelmVersion = 'v3.8.0'
|
const stableHelmVersion = 'v3.9.0'
|
||||||
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases'
|
|
||||||
|
|
||||||
export async function run() {
|
export async function run() {
|
||||||
let version = core.getInput('version', {required: true})
|
let version = core.getInput('version', {required: true})
|
||||||
|
|
@ -46,30 +46,37 @@ export function getValidVersion(version: string): string {
|
||||||
return 'v' + version
|
return 'v' + version
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downloads the helm releases JSON and parses all the recent versions of helm from it.
|
// Gets the latest helm version or returns a default stable if getting latest fails
|
||||||
// Defaults to sending stable helm version if none are valid or if it fails
|
|
||||||
|
|
||||||
export async function getLatestHelmVersion(): Promise<string> {
|
export async function getLatestHelmVersion(): Promise<string> {
|
||||||
const helmJSONPath: string = await toolCache.downloadTool(helmAllReleasesUrl)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'))
|
const {repository} = await graphql(
|
||||||
for (let i in helmJSON) {
|
`
|
||||||
if (isValidVersion(helmJSON[i].tag_name)) {
|
{
|
||||||
return helmJSON[i].tag_name
|
repository(name: "helm", owner: "helm") {
|
||||||
}
|
releases(last: 100) {
|
||||||
}
|
nodes {
|
||||||
|
tagName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
const releases = repository.releases.nodes.reverse()
|
||||||
|
const latestValidRelease = releases.find((release: {tagName: string}) =>
|
||||||
|
isValidVersion(release.tagName)
|
||||||
|
)
|
||||||
|
if (latestValidRelease) return latestValidRelease
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.warning(
|
core.warning(
|
||||||
util.format(
|
`Error while fetching latest Helm release: ${err.toString()}. Using default version ${stableHelmVersion}`
|
||||||
'Error while fetching the latest Helm release. Error: %s. Using default Helm version %s',
|
|
||||||
err.toString(),
|
|
||||||
stableHelmVersion
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
return stableHelmVersion
|
return stableHelmVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
core.debug(
|
||||||
|
`Could not find valid release. Using default version ${stableHelmVersion}`
|
||||||
|
)
|
||||||
return stableHelmVersion
|
return stableHelmVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue