9 Commits
v4.0.0 ... v4

Author SHA1 Message Date
fe7b79cd5e build 2024-04-15 19:42:43 +00:00
df50d879fa Release v4.2.0 (#134)
* Update CHANGELOG.md

* Update package.json

* Update README.md
2024-04-15 15:41:59 -04:00
08d7123a4a Bump undici from 5.28.2 to 5.28.4 (#133)
Bumps [undici](https://github.com/nodejs/undici) from 5.28.2 to 5.28.4.
- [Release notes](https://github.com/nodejs/undici/releases)
- [Commits](https://github.com/nodejs/undici/compare/v5.28.2...v5.28.4)

---
updated-dependencies:
- dependency-name: undici
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-12 16:23:04 -04:00
0a0c55a4c3 Fix os detection and archive extension (#124) 2024-04-12 15:46:47 -04:00
d00ce1cb5e update to release workflow major version tag (#132) 2024-03-08 13:33:11 -05:00
4c255dde26 publish version 4.1.0 (#131)
* publish version 4.1.0

* update version
2024-03-01 11:45:44 -05:00
ec8dd7c209 switching to fetching latest version from the dedicated file (#130) 2024-03-01 10:15:56 -06:00
efbd96d464 Fix action version in README.md (#129)
`v4` is not a valid tag, `v4.0.0` is.

See https://github.com/Azure/setup-helm/tags
2024-02-27 17:32:24 -05:00
859dc38e9a v4 readme update (#127) 2024-02-13 16:11:44 -05:00
9 changed files with 421 additions and 28089 deletions

View File

@ -13,6 +13,6 @@ jobs:
permissions:
actions: read
contents: write
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@a705b2ab6a3ee889f2b0d925ad0bd2f9eb733ce6
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@v1
with:
changelogPath: ./CHANGELOG.md

View File

@ -1,5 +1,13 @@
# Change Log
## [4.2.0] - 2024-04-15
- #124 Fix OS detection and download OS-native archive extension
## [4.1.0] - 2024-03-01
- #130 switches to use Helm published file to read latest version instead of using GitHub releases
## [4.0.0] - 2024-02-12
- #121 update to node20 as node16 is deprecated

View File

@ -4,18 +4,17 @@ Install a specific version of helm binary on the runner.
## Example
Acceptable values are latest or any semantic version string like v3.5.0 Use this action in workflow to define which version of helm will be used. v2 and v3 of this action only support Helm3.
Acceptable values are latest or any semantic version string like v3.5.0 Use this action in workflow to define which version of helm will be used. v2+ of this action only support Helm3.
```yaml
- uses: azure/setup-helm@v3
- uses: azure/setup-helm@v4.2.0
with:
version: '<version>' # default is latest (stable)
token: ${{ secrets.GITHUB_TOKEN }} # only needed if version is 'latest'
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.13.3). If you rely on a certain version higher than the default, you should use that version instead of latest.
> If something goes wrong with fetching the latest version the action will use the hardcoded default stable version (currently v3.13.3). If you rely on a certain version higher than the default, you should explicitly 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.
Refer to the action metadata file for details about all the inputs https://github.com/Azure/setup-helm/blob/master/action.yml

View File

@ -6,8 +6,9 @@ inputs:
required: true
default: 'latest'
token:
description: GitHub token. Required only if 'version' == 'latest'
description: GitHub token. Used to be required to fetch the latest version
required: false
deprecationMessage: 'GitHub token is no longer required'
default: '${{ github.token }}'
downloadBaseURL:
description: 'Set the download base URL'

28206
lib/index.js

File diff suppressed because one or more lines are too long

19
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "setuphelm",
"version": "0.0.0",
"version": "4.2.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "setuphelm",
"version": "0.0.0",
"version": "4.2.0",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
@ -1117,12 +1117,9 @@
}
},
"node_modules/@octokit/action/node_modules/undici": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/undici/-/undici-6.5.0.tgz",
"integrity": "sha512-/MUmPb2ptTvp1j7lPvdMSofMdqPxcOhAaKZi4k55sqm6XMeKI3n1dZJ5cnD4gLjpt2l7CIlthR1IXM59xKhpxw==",
"dependencies": {
"@fastify/busboy": "^2.0.0"
},
"version": "6.11.1",
"resolved": "https://registry.npmjs.org/undici/-/undici-6.11.1.tgz",
"integrity": "sha512-KyhzaLJnV1qa3BSHdj4AZ2ndqI0QWPxYzaIOio0WzcEJB9gvuysprJSLtpvc2D9mhR9jPDUk7xlJlZbH2KR5iw==",
"engines": {
"node": ">=18.0"
}
@ -3840,9 +3837,9 @@
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og=="
},
"node_modules/undici": {
"version": "5.28.2",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.2.tgz",
"integrity": "sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==",
"version": "5.28.4",
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz",
"integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==",
"dependencies": {
"@fastify/busboy": "^2.0.0"
},

View File

@ -1,6 +1,6 @@
{
"name": "setuphelm",
"version": "0.0.0",
"version": "4.2.0",
"private": true,
"description": "Setup helm",
"author": "Anumita Shenoy",

View File

@ -6,90 +6,95 @@ import * as path from 'path'
import * as core from '@actions/core'
describe('run.ts', () => {
const downloadBaseURL = 'https://test.tld'
// Cleanup mocks after each test to ensure that subsequent tests are not affected by the mocks.
afterEach(() => {
jest.restoreAllMocks()
})
test('getExecutableExtension() - return .exe when os is Windows', () => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(os, 'platform').mockReturnValue('win32')
expect(run.getExecutableExtension()).toBe('.exe')
expect(os.type).toHaveBeenCalled()
expect(os.platform).toHaveBeenCalled()
})
test('getExecutableExtension() - return empty string for non-windows OS', () => {
jest.spyOn(os, 'type').mockReturnValue('Darwin')
jest.spyOn(os, 'platform').mockReturnValue('darwin')
expect(run.getExecutableExtension()).toBe('')
expect(os.type).toHaveBeenCalled()
expect(os.platform).toHaveBeenCalled()
})
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
const downloadBaseURL = 'https://test.tld'
test('getHelmDownloadURL() - return the URL to download helm for Linux amd64', () => {
jest.spyOn(os, 'platform').mockReturnValue('linux')
jest.spyOn(os, 'arch').mockReturnValue('x64')
const expected = 'https://test.tld/helm-v3.8.0-linux-amd64.tar.gz'
jest.spyOn(os, 'type').mockReturnValue('Linux')
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
const helmLinuxUrl = 'https://test.tld/helm-v3.8.0-linux-amd64.zip'
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmLinuxUrl
)
expect(os.type).toHaveBeenCalled()
expect(os.arch).toHaveBeenCalled()
// arm64
jest.spyOn(os, 'type').mockReturnValue('Linux')
jest.spyOn(os, 'arch').mockReturnValueOnce('arm64')
const helmLinuxArm64Url = 'https://test.tld/helm-v3.8.0-linux-arm64.zip'
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmLinuxArm64Url
)
expect(os.type).toHaveBeenCalled()
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
expect(os.platform).toHaveBeenCalled()
expect(os.arch).toHaveBeenCalled()
})
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
const downloadBaseURL = 'https://test.tld'
test('getHelmDownloadURL() - return the URL to download helm for Linux arm64', () => {
jest.spyOn(os, 'platform').mockReturnValue('linux')
jest.spyOn(os, 'arch').mockReturnValue('arm64')
const expected = 'https://test.tld/helm-v3.8.0-linux-arm64.tar.gz'
jest.spyOn(os, 'type').mockReturnValue('Darwin')
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
const helmDarwinUrl = 'https://test.tld/helm-v3.8.0-darwin-amd64.zip'
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmDarwinUrl
)
expect(os.type).toHaveBeenCalled()
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
expect(os.platform).toHaveBeenCalled()
expect(os.arch).toHaveBeenCalled()
})
// arm64
jest.spyOn(os, 'type').mockReturnValue('Darwin')
jest.spyOn(os, 'arch').mockReturnValueOnce('arm64')
const helmDarwinArm64Url = 'https://test.tld/helm-v3.8.0-darwin-arm64.zip'
test('getHelmDownloadURL() - return the URL to download helm for Darwin x64', () => {
jest.spyOn(os, 'platform').mockReturnValue('darwin')
jest.spyOn(os, 'arch').mockReturnValue('x64')
const expected = 'https://test.tld/helm-v3.8.0-darwin-amd64.tar.gz'
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmDarwinArm64Url
)
expect(os.type).toHaveBeenCalled()
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
expect(os.platform).toHaveBeenCalled()
expect(os.arch).toHaveBeenCalled()
})
test('getHelmDownloadURL() - return the URL to download helm for Darwin arm64', () => {
jest.spyOn(os, 'platform').mockReturnValue('darwin')
jest.spyOn(os, 'arch').mockReturnValue('arm64')
const expected = 'https://test.tld/helm-v3.8.0-darwin-arm64.tar.gz'
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
expect(os.platform).toHaveBeenCalled()
expect(os.arch).toHaveBeenCalled()
})
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
jest.spyOn(os, 'platform').mockReturnValue('win32')
jest.spyOn(os, 'arch').mockReturnValue('x64')
const expected = 'https://test.tld/helm-v3.8.0-windows-amd64.zip'
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
expect(os.platform).toHaveBeenCalled()
})
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
const res = {
status: 200,
text: async () => 'v9.99.999'
} as Response
global.fetch = jest.fn().mockReturnValue(res)
expect(await run.getLatestHelmVersion()).toBe('v9.99.999')
})
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')
})
test('getValidVersion() - return version with v prepended', () => {
expect(run.getValidVersion('3.8.0')).toBe('v3.8.0')
})
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
const downloadBaseURL = 'https://test.tld'
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
const helmWindowsUrl = 'https://test.tld/helm-v3.8.0-windows-amd64.zip'
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
helmWindowsUrl
)
expect(os.type).toHaveBeenCalled()
})
test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => {
expect(await run.getLatestHelmVersion()).toBe('v3.13.3')
})
test('walkSync() - return path to the all files matching fileToFind in dir', () => {
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
if (file == 'mainFolder')
@ -109,6 +114,7 @@ describe('run.ts', () => {
'file21' as unknown as fs.Dirent,
'file22' as unknown as fs.Dirent
]
return []
})
jest.spyOn(core, 'debug').mockImplementation()
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
@ -143,6 +149,7 @@ describe('run.ts', () => {
'file21' as unknown as fs.Dirent,
'file22' as unknown as fs.Dirent
]
return []
})
jest.spyOn(core, 'debug').mockImplementation()
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
@ -160,13 +167,14 @@ describe('run.ts', () => {
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
if (file == 'mainFolder') return ['helm.exe' as unknown as fs.Dirent]
return []
})
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
const isDirectory =
(file as string).indexOf('folder') == -1 ? false : true
return {isDirectory: () => isDirectory} as fs.Stats
})
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(os, 'platform').mockReturnValue('win32')
expect(run.findHelm('mainFolder')).toBe(
path.join('mainFolder', 'helm.exe')
@ -177,11 +185,13 @@ describe('run.ts', () => {
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
if (file == 'mainFolder') return []
return []
})
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
return {isDirectory: () => true} as fs.Stats
})
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(os, 'platform').mockReturnValue('win32')
expect(() => run.findHelm('mainFolder')).toThrow(
'Helm executable not found in path mainFolder'
)
@ -192,11 +202,9 @@ describe('run.ts', () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
const response = JSON.stringify([{tag_name: 'v4.0.0'}])
jest.spyOn(fs, 'readFileSync').mockReturnValue(response)
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(os, 'platform').mockReturnValue('win32')
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
jest
.spyOn(toolCache, 'extractZip')
.mockResolvedValue('pathToUnzippedHelm')
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('extractedPath')
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
jest
.spyOn(fs, 'readdirSync')
@ -207,9 +215,7 @@ describe('run.ts', () => {
return {isDirectory: () => isDirectory} as fs.Stats
})
const baseURL = 'https://test.tld'
expect(await run.downloadHelm(baseURL, 'v4.0.0')).toBe(
expect(await run.downloadHelm(downloadBaseURL, 'v4.0.0')).toBe(
path.join('pathToCachedDir', 'helm.exe')
)
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v4.0.0')
@ -229,26 +235,33 @@ describe('run.ts', () => {
jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => {
throw 'Unable to download'
})
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(os, 'platform').mockReturnValue('win32')
const baseURL = 'https://test.tld'
await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow(
'Failed to download Helm from location https://test.tld/helm-v3.2.1-windows-amd64.zip'
const downloadUrl = 'https://test.tld/helm-v3.2.1-windows-amd64.zip'
await expect(run.downloadHelm(downloadBaseURL, 'v3.2.1')).rejects.toThrow(
`Failed to download Helm from location ${downloadUrl}`
)
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
expect(toolCache.downloadTool).toHaveBeenCalledWith(
'https://test.tld/helm-v3.2.1-windows-amd64.zip'
)
expect(toolCache.downloadTool).toHaveBeenCalledWith(`${downloadUrl}`)
})
test('downloadHelm() - return path to helm tool with same version from toolCache', async () => {
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir')
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('extractedPath')
jest.spyOn(os, 'platform').mockReturnValue('win32')
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
jest
.spyOn(fs, 'readdirSync')
.mockReturnValue(['helm.exe' as unknown as fs.Dirent])
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
const isDirectory =
(file as string).indexOf('folder') == -1 ? false : true
return {isDirectory: () => isDirectory} as fs.Stats
})
const baseURL = 'https://test.tld'
expect(await run.downloadHelm(baseURL, 'v3.2.1')).toBe(
expect(await run.downloadHelm(downloadBaseURL, 'v3.2.1')).toBe(
path.join('pathToCachedDir', 'helm.exe')
)
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
@ -261,12 +274,11 @@ describe('run.ts', () => {
test('downloadHelm() - throw error is helm is not found in path', async () => {
jest.spyOn(toolCache, 'find').mockReturnValue('')
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(fs, 'chmodSync').mockImplementation()
jest
.spyOn(toolCache, 'extractZip')
.mockResolvedValue('pathToUnzippedHelm')
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('extractedPath')
jest.spyOn(os, 'platform').mockReturnValue('win32')
jest.spyOn(fs, 'chmodSync').mockImplementation()
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => [])
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
const isDirectory =
@ -274,9 +286,7 @@ describe('run.ts', () => {
return {isDirectory: () => isDirectory} as fs.Stats
})
const baseURL = 'https://test.tld'
await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow(
await expect(run.downloadHelm(downloadBaseURL, 'v3.2.1')).rejects.toThrow(
'Helm executable not found in path pathToCachedDir'
)
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')

View File

@ -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'
@ -51,75 +50,35 @@ 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 getArch(): string {
return os.arch() === 'x64' ? 'amd64' : os.arch()
}
export function getPlatform(): string {
return os.platform() === 'win32' ? 'windows' : os.platform()
}
export function getArchiveExtension(): string {
return os.platform() === 'win32' ? 'zip' : 'tar.gz'
}
export function getExecutableExtension(): string {
if (os.type().match(/^Win/)) {
return '.exe'
}
return ''
return os.platform() === 'win32' ? '.exe' : ''
}
const LINUX = 'Linux'
const MAC_OS = 'Darwin'
const WINDOWS = 'Windows_NT'
const ARM64 = 'arm64'
export function getHelmDownloadURL(baseURL: string, version: string): string {
const arch = os.arch()
const operatingSystem = os.type()
let urlPath = ''
switch (true) {
case operatingSystem == LINUX && arch == ARM64:
urlPath = util.format(`/helm-%s-linux-arm64.zip`, version)
break
case operatingSystem == LINUX:
urlPath = util.format(`/helm-%s-linux-amd64.zip`, version)
break
case operatingSystem == MAC_OS && arch == ARM64:
urlPath = util.format(`/helm-%s-darwin-arm64.zip`, version)
break
case operatingSystem == MAC_OS:
urlPath = util.format(`/helm-%s-darwin-amd64.zip`, version)
break
case operatingSystem == WINDOWS:
default:
urlPath = util.format(`/helm-%s-windows-amd64.zip`, version)
}
const urlPath = `helm-${version}-${getPlatform()}-${getArch()}.${getArchiveExtension()}`
const url = new URL(urlPath, baseURL)
return url.toString()
}
@ -145,9 +104,13 @@ export async function downloadHelm(
}
fs.chmodSync(helmDownloadPath, '777')
const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath)
const extractedPath =
getPlatform() === 'windows'
? await toolCache.extractZip(helmDownloadPath)
: await toolCache.extractTar(helmDownloadPath)
cachedToolpath = await toolCache.cacheDir(
unzipedHelmPath,
extractedPath,
helmToolName,
version
)