mirror of
https://github.com/Azure/setup-helm.git
synced 2025-12-23 15:55:43 +00:00
Compare commits
6 Commits
version4.1
...
brfole/dep
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40c5d3d7ec | ||
|
|
df50d879fa | ||
|
|
08d7123a4a | ||
|
|
0a0c55a4c3 | ||
|
|
d00ce1cb5e | ||
|
|
4c255dde26 |
18
.github/dependabot.yml
vendored
Normal file
18
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: npm
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
groups:
|
||||||
|
actions:
|
||||||
|
patterns:
|
||||||
|
- '*'
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: .github/workflows
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
groups:
|
||||||
|
actions:
|
||||||
|
patterns:
|
||||||
|
- '*'
|
||||||
2
.github/workflows/release-pr.yml
vendored
2
.github/workflows/release-pr.yml
vendored
@@ -13,6 +13,6 @@ jobs:
|
|||||||
permissions:
|
permissions:
|
||||||
actions: read
|
actions: read
|
||||||
contents: write
|
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:
|
with:
|
||||||
changelogPath: ./CHANGELOG.md
|
changelogPath: ./CHANGELOG.md
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# Change Log
|
# 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
|
## [4.0.0] - 2024-02-12
|
||||||
|
|
||||||
- #121 update to node20 as node16 is deprecated
|
- #121 update to node20 as node16 is deprecated
|
||||||
|
|||||||
@@ -7,15 +7,14 @@ Install a specific version of helm binary on the runner.
|
|||||||
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.
|
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
|
```yaml
|
||||||
- uses: azure/setup-helm@v4.0.0
|
- uses: azure/setup-helm@v4.2.0
|
||||||
with:
|
with:
|
||||||
version: '<version>' # default is latest (stable)
|
version: '<version>' # default is latest (stable)
|
||||||
token: ${{ secrets.GITHUB_TOKEN }} # only needed if version is 'latest'
|
|
||||||
id: install
|
id: install
|
||||||
```
|
```
|
||||||
|
|
||||||
> [!NOTE]
|
> [!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.
|
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
|
||||||
|
|||||||
19
package-lock.json
generated
19
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "setuphelm",
|
"name": "setuphelm",
|
||||||
"version": "0.0.0",
|
"version": "4.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "setuphelm",
|
"name": "setuphelm",
|
||||||
"version": "0.0.0",
|
"version": "4.1.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
@@ -1116,12 +1116,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@octokit/action/node_modules/undici": {
|
"node_modules/@octokit/action/node_modules/undici": {
|
||||||
"version": "6.5.0",
|
"version": "6.11.1",
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-6.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/undici/-/undici-6.11.1.tgz",
|
||||||
"integrity": "sha512-/MUmPb2ptTvp1j7lPvdMSofMdqPxcOhAaKZi4k55sqm6XMeKI3n1dZJ5cnD4gLjpt2l7CIlthR1IXM59xKhpxw==",
|
"integrity": "sha512-KyhzaLJnV1qa3BSHdj4AZ2ndqI0QWPxYzaIOio0WzcEJB9gvuysprJSLtpvc2D9mhR9jPDUk7xlJlZbH2KR5iw==",
|
||||||
"dependencies": {
|
|
||||||
"@fastify/busboy": "^2.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0"
|
"node": ">=18.0"
|
||||||
}
|
}
|
||||||
@@ -3759,9 +3756,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici": {
|
"node_modules/undici": {
|
||||||
"version": "5.28.2",
|
"version": "5.28.4",
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.2.tgz",
|
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz",
|
||||||
"integrity": "sha512-wh1pHJHnUeQV5Xa8/kyQhO7WFa8M34l026L5P/+2TYiakvGy5Rdc8jWZVyG7ieht/0WgJLEd3kcU5gKx+6GC8w==",
|
"integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fastify/busboy": "^2.0.0"
|
"@fastify/busboy": "^2.0.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "setuphelm",
|
"name": "setuphelm",
|
||||||
"version": "0.0.0",
|
"version": "4.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Setup helm",
|
"description": "Setup helm",
|
||||||
"author": "Anumita Shenoy",
|
"author": "Anumita Shenoy",
|
||||||
|
|||||||
167
src/run.test.ts
167
src/run.test.ts
@@ -6,84 +6,74 @@ import * as path from 'path'
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
describe('run.ts', () => {
|
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', () => {
|
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(run.getExecutableExtension()).toBe('.exe')
|
||||||
expect(os.type).toHaveBeenCalled()
|
expect(os.platform).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getExecutableExtension() - return empty string for non-windows OS', () => {
|
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(run.getExecutableExtension()).toBe('')
|
||||||
expect(os.type).toHaveBeenCalled()
|
expect(os.platform).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Linux amd64', () => {
|
||||||
const downloadBaseURL = 'https://test.tld'
|
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')
|
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
|
||||||
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
|
expect(os.platform).toHaveBeenCalled()
|
||||||
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(os.arch).toHaveBeenCalled()
|
expect(os.arch).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Linux arm64', () => {
|
||||||
const downloadBaseURL = 'https://test.tld'
|
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')
|
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
|
||||||
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
|
expect(os.platform).toHaveBeenCalled()
|
||||||
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(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'
|
|
||||||
|
|
||||||
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
|
|
||||||
helmDarwinArm64Url
|
|
||||||
)
|
|
||||||
expect(os.type).toHaveBeenCalled()
|
|
||||||
expect(os.arch).toHaveBeenCalled()
|
expect(os.arch).toHaveBeenCalled()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getValidVersion() - return version with v prepended', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Darwin x64', () => {
|
||||||
expect(run.getValidVersion('3.8.0')).toBe('v3.8.0')
|
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(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', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
|
||||||
const downloadBaseURL = 'https://test.tld'
|
jest.spyOn(os, 'platform').mockReturnValue('win32')
|
||||||
|
jest.spyOn(os, 'arch').mockReturnValue('x64')
|
||||||
|
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
const expected = 'https://test.tld/helm-v3.8.0-windows-amd64.zip'
|
||||||
|
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
|
||||||
const helmWindowsUrl = 'https://test.tld/helm-v3.8.0-windows-amd64.zip'
|
expect(os.platform).toHaveBeenCalled()
|
||||||
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
|
|
||||||
helmWindowsUrl
|
|
||||||
)
|
|
||||||
expect(os.type).toHaveBeenCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
|
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
|
||||||
@@ -101,6 +91,10 @@ describe('run.ts', () => {
|
|||||||
expect(await run.getLatestHelmVersion()).toBe('v3.13.3')
|
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('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
test('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
||||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||||
if (file == 'mainFolder')
|
if (file == 'mainFolder')
|
||||||
@@ -120,6 +114,7 @@ describe('run.ts', () => {
|
|||||||
'file21' as unknown as fs.Dirent,
|
'file21' as unknown as fs.Dirent,
|
||||||
'file22' as unknown as fs.Dirent
|
'file22' as unknown as fs.Dirent
|
||||||
]
|
]
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
jest.spyOn(core, 'debug').mockImplementation()
|
jest.spyOn(core, 'debug').mockImplementation()
|
||||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
@@ -154,6 +149,7 @@ describe('run.ts', () => {
|
|||||||
'file21' as unknown as fs.Dirent,
|
'file21' as unknown as fs.Dirent,
|
||||||
'file22' as unknown as fs.Dirent
|
'file22' as unknown as fs.Dirent
|
||||||
]
|
]
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
jest.spyOn(core, 'debug').mockImplementation()
|
jest.spyOn(core, 'debug').mockImplementation()
|
||||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
@@ -171,13 +167,14 @@ describe('run.ts', () => {
|
|||||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||||
if (file == 'mainFolder') return ['helm.exe' as unknown as fs.Dirent]
|
if (file == 'mainFolder') return ['helm.exe' as unknown as fs.Dirent]
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
const isDirectory =
|
const isDirectory =
|
||||||
(file as string).indexOf('folder') == -1 ? false : true
|
(file as string).indexOf('folder') == -1 ? false : true
|
||||||
return {isDirectory: () => isDirectory} as fs.Stats
|
return {isDirectory: () => isDirectory} as fs.Stats
|
||||||
})
|
})
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
jest.spyOn(os, 'platform').mockReturnValue('win32')
|
||||||
|
|
||||||
expect(run.findHelm('mainFolder')).toBe(
|
expect(run.findHelm('mainFolder')).toBe(
|
||||||
path.join('mainFolder', 'helm.exe')
|
path.join('mainFolder', 'helm.exe')
|
||||||
@@ -188,11 +185,13 @@ describe('run.ts', () => {
|
|||||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||||
if (file == 'mainFolder') return []
|
if (file == 'mainFolder') return []
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
return {isDirectory: () => true} as fs.Stats
|
return {isDirectory: () => true} as fs.Stats
|
||||||
})
|
})
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
jest.spyOn(os, 'platform').mockReturnValue('win32')
|
||||||
|
|
||||||
expect(() => run.findHelm('mainFolder')).toThrow(
|
expect(() => run.findHelm('mainFolder')).toThrow(
|
||||||
'Helm executable not found in path mainFolder'
|
'Helm executable not found in path mainFolder'
|
||||||
)
|
)
|
||||||
@@ -203,11 +202,9 @@ describe('run.ts', () => {
|
|||||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
||||||
const response = JSON.stringify([{tag_name: 'v4.0.0'}])
|
const response = JSON.stringify([{tag_name: 'v4.0.0'}])
|
||||||
jest.spyOn(fs, 'readFileSync').mockReturnValue(response)
|
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(fs, 'chmodSync').mockImplementation(() => {})
|
||||||
jest
|
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('extractedPath')
|
||||||
.spyOn(toolCache, 'extractZip')
|
|
||||||
.mockResolvedValue('pathToUnzippedHelm')
|
|
||||||
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
|
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
|
||||||
jest
|
jest
|
||||||
.spyOn(fs, 'readdirSync')
|
.spyOn(fs, 'readdirSync')
|
||||||
@@ -218,9 +215,7 @@ describe('run.ts', () => {
|
|||||||
return {isDirectory: () => isDirectory} as fs.Stats
|
return {isDirectory: () => isDirectory} as fs.Stats
|
||||||
})
|
})
|
||||||
|
|
||||||
const baseURL = 'https://test.tld'
|
expect(await run.downloadHelm(downloadBaseURL, 'v4.0.0')).toBe(
|
||||||
|
|
||||||
expect(await run.downloadHelm(baseURL, 'v4.0.0')).toBe(
|
|
||||||
path.join('pathToCachedDir', 'helm.exe')
|
path.join('pathToCachedDir', 'helm.exe')
|
||||||
)
|
)
|
||||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v4.0.0')
|
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v4.0.0')
|
||||||
@@ -240,26 +235,33 @@ describe('run.ts', () => {
|
|||||||
jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => {
|
jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => {
|
||||||
throw 'Unable to download'
|
throw 'Unable to download'
|
||||||
})
|
})
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
jest.spyOn(os, 'platform').mockReturnValue('win32')
|
||||||
|
|
||||||
const baseURL = 'https://test.tld'
|
const downloadUrl = 'https://test.tld/helm-v3.2.1-windows-amd64.zip'
|
||||||
|
await expect(run.downloadHelm(downloadBaseURL, 'v3.2.1')).rejects.toThrow(
|
||||||
await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow(
|
`Failed to download Helm from location ${downloadUrl}`
|
||||||
'Failed to download Helm from location https://test.tld/helm-v3.2.1-windows-amd64.zip'
|
|
||||||
)
|
)
|
||||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||||
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
expect(toolCache.downloadTool).toHaveBeenCalledWith(`${downloadUrl}`)
|
||||||
'https://test.tld/helm-v3.2.1-windows-amd64.zip'
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('downloadHelm() - return path to helm tool with same version from toolCache', async () => {
|
test('downloadHelm() - return path to helm tool with same version from toolCache', async () => {
|
||||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir')
|
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, '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(downloadBaseURL, 'v3.2.1')).toBe(
|
||||||
|
|
||||||
expect(await run.downloadHelm(baseURL, 'v3.2.1')).toBe(
|
|
||||||
path.join('pathToCachedDir', 'helm.exe')
|
path.join('pathToCachedDir', 'helm.exe')
|
||||||
)
|
)
|
||||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||||
@@ -272,12 +274,11 @@ describe('run.ts', () => {
|
|||||||
test('downloadHelm() - throw error is helm is not found in path', async () => {
|
test('downloadHelm() - throw error is helm is not found in path', async () => {
|
||||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
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, '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, 'readdirSync').mockImplementation((file, _) => [])
|
||||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
const isDirectory =
|
const isDirectory =
|
||||||
@@ -285,9 +286,7 @@ describe('run.ts', () => {
|
|||||||
return {isDirectory: () => isDirectory} as fs.Stats
|
return {isDirectory: () => isDirectory} as fs.Stats
|
||||||
})
|
})
|
||||||
|
|
||||||
const baseURL = 'https://test.tld'
|
await expect(run.downloadHelm(downloadBaseURL, 'v3.2.1')).rejects.toThrow(
|
||||||
|
|
||||||
await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow(
|
|
||||||
'Helm executable not found in path pathToCachedDir'
|
'Helm executable not found in path pathToCachedDir'
|
||||||
)
|
)
|
||||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||||
|
|||||||
53
src/run.ts
53
src/run.ts
@@ -61,41 +61,24 @@ export async function getLatestHelmVersion(): Promise<string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
export function getExecutableExtension(): string {
|
||||||
if (os.type().match(/^Win/)) {
|
return os.platform() === 'win32' ? '.exe' : ''
|
||||||
return '.exe'
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const LINUX = 'Linux'
|
|
||||||
const MAC_OS = 'Darwin'
|
|
||||||
const WINDOWS = 'Windows_NT'
|
|
||||||
const ARM64 = 'arm64'
|
|
||||||
export function getHelmDownloadURL(baseURL: string, version: string): string {
|
export function getHelmDownloadURL(baseURL: string, version: string): string {
|
||||||
const arch = os.arch()
|
const urlPath = `helm-${version}-${getPlatform()}-${getArch()}.${getArchiveExtension()}`
|
||||||
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 url = new URL(urlPath, baseURL)
|
const url = new URL(urlPath, baseURL)
|
||||||
return url.toString()
|
return url.toString()
|
||||||
}
|
}
|
||||||
@@ -121,9 +104,13 @@ export async function downloadHelm(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fs.chmodSync(helmDownloadPath, '777')
|
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(
|
cachedToolpath = await toolCache.cacheDir(
|
||||||
unzipedHelmPath,
|
extractedPath,
|
||||||
helmToolName,
|
helmToolName,
|
||||||
version
|
version
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user