Compare commits
27 Commits
releases/v
...
v4.1.0
Author | SHA1 | Date | |
---|---|---|---|
b7246b12e7 | |||
4c255dde26 | |||
ec8dd7c209 | |||
efbd96d464 | |||
859dc38e9a | |||
0788eb3317 | |||
208de6bd49 | |||
1f87a575d0 | |||
d336b89352 | |||
ac5ee1fca8 | |||
638a523e0c | |||
0a7ec47357 | |||
3419a8fa8f | |||
f77071b246 | |||
a4617735aa | |||
2dafda840c | |||
b70d33f56d | |||
3c00c0152f | |||
22d14750db | |||
a22741c887 | |||
f850d12cb3 | |||
17cd77473c | |||
484a64052d | |||
6e32762c2e | |||
17c21ab68c | |||
7f0153c54c | |||
a14110f6e6 |
4
.github/workflows/defaultLabels.yml
vendored
4
.github/workflows/defaultLabels.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v9
|
||||
name: Setting issue as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@ -24,7 +24,7 @@ jobs:
|
||||
operations-per-run: 100
|
||||
exempt-issue-labels: 'backlog'
|
||||
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v9
|
||||
name: Setting PR as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
24
.github/workflows/integration-tests.yml
vendored
24
.github/workflows/integration-tests.yml
vendored
@ -15,7 +15,7 @@ jobs:
|
||||
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
- name: npm install and build
|
||||
id: action-npm-build
|
||||
run: |
|
||||
@ -63,3 +63,25 @@ jobs:
|
||||
else
|
||||
echo "HELM VERSION $HELM_3_5_0 INSTALLED SUCCESSFULLY"
|
||||
fi
|
||||
- name: Setup helm latest version
|
||||
uses: ./
|
||||
with:
|
||||
version: latest
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Validate latest
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
HELM_LATEST=$(gh release list \
|
||||
--repo helm/helm \
|
||||
--exclude-drafts \
|
||||
--exclude-pre-releases \
|
||||
--limit 1 | awk '{print $4}')
|
||||
|
||||
if [[ $(helm version) != *$HELM_LATEST* ]]; then
|
||||
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN $HELM_LATEST"
|
||||
echo "HELM VERSION OUTPUT: $(helm version)"
|
||||
exit 1
|
||||
else
|
||||
echo "HELM VERSION $HELM_LATEST INSTALLED SUCCESSFULLY"
|
||||
fi
|
||||
|
4
.github/workflows/prettify-code.yml
vendored
4
.github/workflows/prettify-code.yml
vendored
@ -10,9 +10,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Enforce Prettier
|
||||
uses: actionsx/prettier@v2
|
||||
uses: actionsx/prettier@v3
|
||||
with:
|
||||
args: --check .
|
||||
|
20
.github/workflows/release-pr.yml
vendored
20
.github/workflows/release-pr.yml
vendored
@ -1,14 +1,18 @@
|
||||
name: Create release PR
|
||||
name: Release Project
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- CHANGELOG.md
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release:
|
||||
description: 'Define release version (ex: v1, v2, v3)'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
release-pr:
|
||||
uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main
|
||||
release:
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@a705b2ab6a3ee889f2b0d925ad0bd2f9eb733ce6
|
||||
with:
|
||||
release: ${{ github.event.inputs.release }}
|
||||
changelogPath: ./CHANGELOG.md
|
||||
|
2
.github/workflows/unit-tests.yml
vendored
2
.github/workflows/unit-tests.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
build: # make sure build/ci works properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Run L0 tests.
|
||||
run: |
|
||||
|
9
CHANGELOG.md
Normal file
9
CHANGELOG.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Change Log
|
||||
|
||||
## [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
|
@ -4,17 +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.1.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.9.0). If you rely on a certain version higher than the default, you should use that version instead of latest.
|
||||
> [!NOTE]
|
||||
> 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
|
||||
|
10
action.yml
10
action.yml
@ -6,13 +6,19 @@ 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'
|
||||
required: false
|
||||
default: 'https://get.helm.sh'
|
||||
outputs:
|
||||
helm-path:
|
||||
description: 'Path to the cached helm binary'
|
||||
branding:
|
||||
color: 'blue'
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: 'lib/index.js'
|
||||
|
30311
lib/index.js
30311
lib/index.js
File diff suppressed because one or more lines are too long
10220
package-lock.json
generated
10220
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "setuphelm",
|
||||
"version": "0.0.0",
|
||||
"version": "4.1.0",
|
||||
"private": true,
|
||||
"description": "Setup helm",
|
||||
"author": "Anumita Shenoy",
|
||||
@ -10,12 +10,13 @@
|
||||
"@actions/exec": "^1.1.1",
|
||||
"@actions/io": "^1.1.2",
|
||||
"@actions/tool-cache": "2.0.1",
|
||||
"@octokit/auth-action": "^2.0.0",
|
||||
"@octokit/graphql": "^4.6.1",
|
||||
"semver": "^6.1.0"
|
||||
"@octokit/action": "^6.0.7",
|
||||
"ncc": "^0.3.6",
|
||||
"semver": "^7.5.4"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"prebuild": "npm i ncc",
|
||||
"build": "ncc build src/run.ts -o lib",
|
||||
"test": "jest",
|
||||
"test-coverage": "jest --coverage",
|
||||
@ -23,11 +24,12 @@
|
||||
"format-check": "prettier --check ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/node": "^12.0.10",
|
||||
"@vercel/ncc": "^0.34.0",
|
||||
"jest": "^26.0.1",
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "^3.5.2"
|
||||
"@types/jest": "^29.5.11",
|
||||
"@types/node": "^20.11.8",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.2.5",
|
||||
"ts-jest": "^29.1.2",
|
||||
"typescript": "^5.3.3"
|
||||
}
|
||||
}
|
||||
|
135
src/run.test.ts
135
src/run.test.ts
@ -10,55 +10,64 @@ describe('run.ts', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('.exe')
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.type).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('getExecutableExtension() - return empty string for non-windows OS', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin')
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('')
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.type).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
||||
const downloadBaseURL = 'https://test.tld'
|
||||
|
||||
jest.spyOn(os, 'type').mockReturnValue('Linux')
|
||||
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
|
||||
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.8.0-linux-amd64.zip'
|
||||
const helmLinuxUrl = 'https://test.tld/helm-v3.8.0-linux-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.arch).toBeCalled()
|
||||
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 kubectlLinuxArm64Url =
|
||||
'https://get.helm.sh/helm-v3.8.0-linux-arm64.zip'
|
||||
const helmLinuxArm64Url = 'https://test.tld/helm-v3.8.0-linux-arm64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxArm64Url)
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.arch).toBeCalled()
|
||||
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
|
||||
helmLinuxArm64Url
|
||||
)
|
||||
expect(os.type).toHaveBeenCalled()
|
||||
expect(os.arch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
|
||||
const downloadBaseURL = 'https://test.tld'
|
||||
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin')
|
||||
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
|
||||
const kubectlDarwinUrl =
|
||||
'https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip'
|
||||
const helmDarwinUrl = 'https://test.tld/helm-v3.8.0-darwin-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.arch).toBeCalled()
|
||||
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 kubectlDarwinArm64Url =
|
||||
'https://get.helm.sh/helm-v3.8.0-darwin-arm64.zip'
|
||||
const helmDarwinArm64Url = 'https://test.tld/helm-v3.8.0-darwin-arm64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinArm64Url)
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.arch).toBeCalled()
|
||||
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(
|
||||
helmDarwinArm64Url
|
||||
)
|
||||
expect(os.type).toHaveBeenCalled()
|
||||
expect(os.arch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('getValidVersion() - return version with v prepended', () => {
|
||||
@ -66,16 +75,30 @@ describe('run.ts', () => {
|
||||
})
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
|
||||
const downloadBaseURL = 'https://test.tld'
|
||||
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
const kubectlWindowsUrl =
|
||||
'https://get.helm.sh/helm-v3.8.0-windows-amd64.zip'
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlWindowsUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
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.9.0')
|
||||
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('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
||||
@ -108,8 +131,8 @@ describe('run.ts', () => {
|
||||
expect(run.walkSync('mainFolder', null, 'file21')).toEqual([
|
||||
path.join('mainFolder', 'folder2', 'file21')
|
||||
])
|
||||
expect(fs.readdirSync).toBeCalledTimes(3)
|
||||
expect(fs.statSync).toBeCalledTimes(8)
|
||||
expect(fs.readdirSync).toHaveBeenCalledTimes(3)
|
||||
expect(fs.statSync).toHaveBeenCalledTimes(8)
|
||||
})
|
||||
|
||||
test('walkSync() - return empty array if no file with name fileToFind exists', () => {
|
||||
@ -140,8 +163,8 @@ describe('run.ts', () => {
|
||||
})
|
||||
|
||||
expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([])
|
||||
expect(fs.readdirSync).toBeCalledTimes(3)
|
||||
expect(fs.statSync).toBeCalledTimes(8)
|
||||
expect(fs.readdirSync).toHaveBeenCalledTimes(3)
|
||||
expect(fs.statSync).toHaveBeenCalledTimes(8)
|
||||
})
|
||||
|
||||
test('findHelm() - change access permissions and find the helm in given directory', () => {
|
||||
@ -195,16 +218,18 @@ describe('run.ts', () => {
|
||||
return {isDirectory: () => isDirectory} as fs.Stats
|
||||
})
|
||||
|
||||
expect(await run.downloadHelm('v4.0.0')).toBe(
|
||||
const baseURL = 'https://test.tld'
|
||||
|
||||
expect(await run.downloadHelm(baseURL, 'v4.0.0')).toBe(
|
||||
path.join('pathToCachedDir', 'helm.exe')
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0')
|
||||
expect(toolCache.downloadTool).toBeCalledWith(
|
||||
'https://get.helm.sh/helm-v4.0.0-windows-amd64.zip'
|
||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v4.0.0')
|
||||
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
||||
'https://test.tld/helm-v4.0.0-windows-amd64.zip'
|
||||
)
|
||||
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777')
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool')
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
expect(fs.chmodSync).toHaveBeenCalledWith('pathToTool', '777')
|
||||
expect(toolCache.extractZip).toHaveBeenCalledWith('pathToTool')
|
||||
expect(fs.chmodSync).toHaveBeenCalledWith(
|
||||
path.join('pathToCachedDir', 'helm.exe'),
|
||||
'777'
|
||||
)
|
||||
@ -217,12 +242,14 @@ describe('run.ts', () => {
|
||||
})
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
await expect(run.downloadHelm('v3.2.1')).rejects.toThrow(
|
||||
'Failed to download Helm from location https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
|
||||
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'
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1')
|
||||
expect(toolCache.downloadTool).toBeCalledWith(
|
||||
'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
|
||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
||||
'https://test.tld/helm-v3.2.1-windows-amd64.zip'
|
||||
)
|
||||
})
|
||||
|
||||
@ -230,11 +257,13 @@ describe('run.ts', () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
|
||||
expect(await run.downloadHelm('v3.2.1')).toBe(
|
||||
const baseURL = 'https://test.tld'
|
||||
|
||||
expect(await run.downloadHelm(baseURL, 'v3.2.1')).toBe(
|
||||
path.join('pathToCachedDir', 'helm.exe')
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1')
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||
expect(fs.chmodSync).toHaveBeenCalledWith(
|
||||
path.join('pathToCachedDir', 'helm.exe'),
|
||||
'777'
|
||||
)
|
||||
@ -256,14 +285,16 @@ describe('run.ts', () => {
|
||||
return {isDirectory: () => isDirectory} as fs.Stats
|
||||
})
|
||||
|
||||
await expect(run.downloadHelm('v3.2.1')).rejects.toThrow(
|
||||
const baseURL = 'https://test.tld'
|
||||
|
||||
await expect(run.downloadHelm(baseURL, 'v3.2.1')).rejects.toThrow(
|
||||
'Helm executable not found in path pathToCachedDir'
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1')
|
||||
expect(toolCache.downloadTool).toBeCalledWith(
|
||||
'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
|
||||
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
||||
'https://test.tld/helm-v3.2.1-windows-amd64.zip'
|
||||
)
|
||||
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777')
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool')
|
||||
expect(fs.chmodSync).toHaveBeenCalledWith('pathToTool', '777')
|
||||
expect(toolCache.extractZip).toHaveBeenCalledWith('pathToTool')
|
||||
})
|
||||
})
|
||||
|
94
src/run.ts
94
src/run.ts
@ -9,12 +9,9 @@ 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 {create} from 'domain'
|
||||
|
||||
const helmToolName = 'helm'
|
||||
const stableHelmVersion = 'v3.9.0'
|
||||
const stableHelmVersion = 'v3.13.3'
|
||||
|
||||
export async function run() {
|
||||
let version = core.getInput('version', {required: true})
|
||||
@ -27,8 +24,10 @@ export async function run() {
|
||||
version = await getLatestHelmVersion()
|
||||
}
|
||||
|
||||
const downloadBaseURL = core.getInput('downloadBaseURL', {required: false})
|
||||
|
||||
core.startGroup(`Downloading ${version}`)
|
||||
const cachedPath = await downloadHelm(version)
|
||||
const cachedPath = await downloadHelm(downloadBaseURL, version)
|
||||
core.endGroup()
|
||||
|
||||
try {
|
||||
@ -51,48 +50,15 @@ 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 latestValidRelease: string = repository.releases.nodes.find(
|
||||
({tagName, isLatest, isDraft, isPreRelease}) =>
|
||||
isValidVersion(tagName) && isLatest && !isDraft && !isPreRelease
|
||||
)?.tagName
|
||||
|
||||
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 getExecutableExtension(): string {
|
||||
@ -106,53 +72,49 @@ const LINUX = 'Linux'
|
||||
const MAC_OS = 'Darwin'
|
||||
const WINDOWS = 'Windows_NT'
|
||||
const ARM64 = 'arm64'
|
||||
export function getHelmDownloadURL(version: string): string {
|
||||
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:
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-linux-arm64.zip',
|
||||
version
|
||||
)
|
||||
urlPath = util.format(`/helm-%s-linux-arm64.zip`, version)
|
||||
break
|
||||
case operatingSystem == LINUX:
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-linux-amd64.zip',
|
||||
version
|
||||
)
|
||||
|
||||
urlPath = util.format(`/helm-%s-linux-amd64.zip`, version)
|
||||
break
|
||||
case operatingSystem == MAC_OS && arch == ARM64:
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-darwin-arm64.zip',
|
||||
version
|
||||
)
|
||||
urlPath = util.format(`/helm-%s-darwin-arm64.zip`, version)
|
||||
break
|
||||
case operatingSystem == MAC_OS:
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-darwin-amd64.zip',
|
||||
version
|
||||
)
|
||||
|
||||
urlPath = util.format(`/helm-%s-darwin-amd64.zip`, version)
|
||||
break
|
||||
case operatingSystem == WINDOWS:
|
||||
default:
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-windows-amd64.zip',
|
||||
version
|
||||
)
|
||||
urlPath = util.format(`/helm-%s-windows-amd64.zip`, version)
|
||||
}
|
||||
|
||||
const url = new URL(urlPath, baseURL)
|
||||
return url.toString()
|
||||
}
|
||||
|
||||
export async function downloadHelm(version: string): Promise<string> {
|
||||
export async function downloadHelm(
|
||||
baseURL: string,
|
||||
version: string
|
||||
): Promise<string> {
|
||||
let cachedToolpath = toolCache.find(helmToolName, version)
|
||||
if (!cachedToolpath) {
|
||||
let helmDownloadPath
|
||||
try {
|
||||
helmDownloadPath = await toolCache.downloadTool(
|
||||
getHelmDownloadURL(version)
|
||||
getHelmDownloadURL(baseURL, version)
|
||||
)
|
||||
} catch (exception) {
|
||||
throw new Error(
|
||||
`Failed to download Helm from location ${getHelmDownloadURL(
|
||||
baseURL,
|
||||
version
|
||||
)}`
|
||||
)
|
||||
|
Reference in New Issue
Block a user