mirror of
https://github.com/Azure/setup-helm.git
synced 2025-07-16 19:00:35 +00:00
Compare commits
60 Commits
Vidyareddy
...
main
Author | SHA1 | Date | |
---|---|---|---|
50d615e7a7 | |||
0147554077 | |||
4eee2cd0ed | |||
8527f3ee39 | |||
c9a6a97d7f | |||
027e8cdfd7 | |||
df342a2656 | |||
230641be01 | |||
f57bbf1821 | |||
5b950139b7 | |||
28f285563b | |||
d030d7f717 | |||
05502a08f2 | |||
24eca957cf | |||
56195efbb1 | |||
babfb8676f | |||
c757a812df | |||
d5f1fcb584 | |||
cc690771a5 | |||
c4cd5ccdf7 | |||
740f020522 | |||
5976fc8a1b | |||
0e8654bb94 | |||
b48e1dfac1 | |||
855ae7a03c | |||
124c6d88e7 | |||
048f4e7eae | |||
8618769467 | |||
4eb898eef0 | |||
7a2001c0f6 | |||
e90c86ceea | |||
4675ea6b05 | |||
df50d879fa | |||
08d7123a4a | |||
0a0c55a4c3 | |||
d00ce1cb5e | |||
4c255dde26 | |||
ec8dd7c209 | |||
efbd96d464 | |||
859dc38e9a | |||
0788eb3317 | |||
208de6bd49 | |||
1f87a575d0 | |||
d336b89352 | |||
ac5ee1fca8 | |||
638a523e0c | |||
0a7ec47357 | |||
3419a8fa8f | |||
f77071b246 | |||
a4617735aa | |||
2dafda840c | |||
b70d33f56d | |||
3c00c0152f | |||
22d14750db | |||
a22741c887 | |||
f850d12cb3 | |||
17cd77473c | |||
484a64052d | |||
6e32762c2e | |||
17c21ab68c |
36
.github/ISSUE_TEMPLATE/bugReportForm.yml
vendored
Normal file
36
.github/ISSUE_TEMPLATE/bugReportForm.yml
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: File a bug report specifying all inputs you provided for the action, we will respond to this thread with any questions.
|
||||||
|
title: 'Bug: '
|
||||||
|
labels: ['bug', 'triage']
|
||||||
|
assignees: '@Azure/aks-atlanta'
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: What-happened
|
||||||
|
attributes:
|
||||||
|
label: What happened?
|
||||||
|
description: Tell us what happened and how is it different from the expected?
|
||||||
|
placeholder: Tell us what you see!
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: checkboxes
|
||||||
|
id: Version
|
||||||
|
attributes:
|
||||||
|
label: Version
|
||||||
|
options:
|
||||||
|
- label: I am using the latest version
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: Runner
|
||||||
|
attributes:
|
||||||
|
label: Runner
|
||||||
|
description: What runner are you using?
|
||||||
|
placeholder: Mention the runner info (self-hosted, operating system)
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: Logs
|
||||||
|
attributes:
|
||||||
|
label: Relevant log output
|
||||||
|
description: Run in debug mode for the most verbose logs. Please feel free to attach a screenshot of the logs
|
||||||
|
validations:
|
||||||
|
required: true
|
6
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
6
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: GitHub Action "setup-helm" Support
|
||||||
|
url: https://github.com/Azure/setup-helm
|
||||||
|
security: https://github.com/Azure/setup-helm/blob/main/SECURITY.md
|
||||||
|
about: Please ask and answer questions here.
|
13
.github/ISSUE_TEMPLATE/featureRequestForm.yml
vendored
Normal file
13
.github/ISSUE_TEMPLATE/featureRequestForm.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
name: Feature Request
|
||||||
|
description: File a Feature Request form, we will respond to this thread with any questions.
|
||||||
|
title: 'Feature Request: '
|
||||||
|
labels: ['Feature']
|
||||||
|
assignees: '@Azure/aks-atlanta'
|
||||||
|
body:
|
||||||
|
- type: textarea
|
||||||
|
id: Feature_request
|
||||||
|
attributes:
|
||||||
|
label: Feature request
|
||||||
|
description: Provide example functionality and links to relevant docs
|
||||||
|
validations:
|
||||||
|
required: true
|
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:
|
||||||
|
- '*'
|
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 represent a sequence of tasks that will be executed as part of the job
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 #v9.1.0
|
||||||
name: Setting issue as idle
|
name: Setting issue as idle
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@ -24,7 +24,7 @@ jobs:
|
|||||||
operations-per-run: 100
|
operations-per-run: 100
|
||||||
exempt-issue-labels: 'backlog'
|
exempt-issue-labels: 'backlog'
|
||||||
|
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 #v9.1.0
|
||||||
name: Setting PR as idle
|
name: Setting PR as idle
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
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 }}
|
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
- name: npm install and build
|
- name: npm install and build
|
||||||
id: action-npm-build
|
id: action-npm-build
|
||||||
run: |
|
run: |
|
||||||
@ -63,3 +63,25 @@ jobs:
|
|||||||
else
|
else
|
||||||
echo "HELM VERSION $HELM_3_5_0 INSTALLED SUCCESSFULLY"
|
echo "HELM VERSION $HELM_3_5_0 INSTALLED SUCCESSFULLY"
|
||||||
fi
|
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
|
||||||
|
6
.github/workflows/prettify-code.yml
vendored
6
.github/workflows/prettify-code.yml
vendored
@ -10,9 +10,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Repository
|
- name: Checkout Repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
|
||||||
- name: Enforce Prettier
|
- name: Enforce Prettier
|
||||||
uses: actionsx/prettier@v2
|
run: npx prettier --check .
|
||||||
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:
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- CHANGELOG.md
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
|
||||||
release:
|
|
||||||
description: 'Define release version (ex: v1, v2, v3)'
|
|
||||||
required: true
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-pr:
|
release:
|
||||||
uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: write
|
||||||
|
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@3c677ba5ab58f5c5c1a6f0cfb176b333b1f27405 # v1.0.3
|
||||||
with:
|
with:
|
||||||
release: ${{ github.event.inputs.release }}
|
changelogPath: ./CHANGELOG.md
|
||||||
|
2
.github/workflows/tag-and-draft.yml
vendored
2
.github/workflows/tag-and-draft.yml
vendored
@ -7,4 +7,4 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tag-and-release:
|
tag-and-release:
|
||||||
uses: OliverMKing/javascript-release-workflow/.github/workflows/tag-and-release.yml@main
|
uses: OliverMKing/javascript-release-workflow/.github/workflows/tag-and-release.yml@c753e1545b144562237cd1177a95bab21a785cff # main
|
||||||
|
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
|
build: # make sure build/ci works properly
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
|
|
||||||
- name: Run L0 tests.
|
- name: Run L0 tests.
|
||||||
run: |
|
run: |
|
||||||
|
7
.husky/pre-commit
Normal file
7
.husky/pre-commit
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
npm test
|
||||||
|
npm run format-check || {
|
||||||
|
echo ""
|
||||||
|
echo "❌ Formatting check failed."
|
||||||
|
echo "đź’ˇ Run 'npm run format' or 'prettier --write .' to fix formatting issues."
|
||||||
|
exit 1
|
||||||
|
}
|
19
CHANGELOG.md
Normal file
19
CHANGELOG.md
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Change Log
|
||||||
|
|
||||||
|
## [4.3.0] - 2025-02-15
|
||||||
|
|
||||||
|
- #152 feat: log when restoring from cache
|
||||||
|
- #157 Dependencies Update
|
||||||
|
- #137 Add dependabot
|
||||||
|
|
||||||
|
## [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
|
@ -4,6 +4,6 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
|
|||||||
|
|
||||||
Resources:
|
Resources:
|
||||||
|
|
||||||
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
|
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
|
||||||
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
||||||
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
|
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
|
||||||
|
15
README.md
15
README.md
@ -4,19 +4,22 @@ Install a specific version of helm binary on the runner.
|
|||||||
|
|
||||||
## Example
|
## 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 supports 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@v3
|
- uses: azure/setup-helm@v4.3.0
|
||||||
with:
|
with:
|
||||||
version: '<version>' # default is latest stable
|
version: '<version>' # default is latest (stable)
|
||||||
id: install
|
id: install
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> [!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.
|
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
|
||||||
@ -29,3 +32,7 @@ provided by the bot. You will only need to do this once across all repos using o
|
|||||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
||||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
setup-helm is an open source project that is [**not** covered by the Microsoft Azure support policy](https://support.microsoft.com/en-us/help/2941892/support-for-linux-and-open-source-technology-in-azure). [Please search open issues here](https://github.com/Azure/setup-helm/issues), and if your issue isn't already represented please [open a new one](https://github.com/Azure/setup-helm/issues/new/choose). The project maintainers will respond to the best of their abilities.
|
||||||
|
14
SECURITY.md
14
SECURITY.md
@ -18,13 +18,13 @@ You should receive a response within 24 hours. If for some reason you do not, pl
|
|||||||
|
|
||||||
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
|
||||||
|
|
||||||
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
||||||
- Full paths of source file(s) related to the manifestation of the issue
|
- Full paths of source file(s) related to the manifestation of the issue
|
||||||
- The location of the affected source code (tag/branch/commit or direct URL)
|
- The location of the affected source code (tag/branch/commit or direct URL)
|
||||||
- Any special configuration required to reproduce the issue
|
- Any special configuration required to reproduce the issue
|
||||||
- Step-by-step instructions to reproduce the issue
|
- Step-by-step instructions to reproduce the issue
|
||||||
- Proof-of-concept or exploit code (if possible)
|
- Proof-of-concept or exploit code (if possible)
|
||||||
- Impact of the issue, including how an attacker might exploit the issue
|
- Impact of the issue, including how an attacker might exploit the issue
|
||||||
|
|
||||||
This information will help us triage your report more quickly.
|
This information will help us triage your report more quickly.
|
||||||
|
|
||||||
|
11
action.yml
11
action.yml
@ -5,11 +5,20 @@ inputs:
|
|||||||
description: 'Version of helm'
|
description: 'Version of helm'
|
||||||
required: true
|
required: true
|
||||||
default: 'latest'
|
default: 'latest'
|
||||||
|
token:
|
||||||
|
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:
|
outputs:
|
||||||
helm-path:
|
helm-path:
|
||||||
description: 'Path to the cached helm binary'
|
description: 'Path to the cached helm binary'
|
||||||
branding:
|
branding:
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node20'
|
||||||
main: 'lib/index.js'
|
main: 'lib/index.js'
|
||||||
|
11614
package-lock.json
generated
11614
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@ -1,32 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "setuphelm",
|
"name": "setuphelm",
|
||||||
"version": "0.0.0",
|
"version": "4.3.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Setup helm",
|
"description": "Setup helm",
|
||||||
"author": "Anumita Shenoy",
|
"author": "Anumita Shenoy",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.11.1",
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.1.1",
|
||||||
"@actions/io": "^1.0.0",
|
"@actions/io": "^1.1.2",
|
||||||
"@actions/tool-cache": "1.1.2",
|
"@actions/tool-cache": "2.0.2",
|
||||||
"@octokit/graphql": "^4.6.1",
|
"@octokit/action": "^8.0.2",
|
||||||
"semver": "^6.1.0"
|
"semver": "^7.7.2"
|
||||||
},
|
},
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "ncc build src/run.ts -o lib",
|
"prebuild": "npm i ncc",
|
||||||
|
"build": "ncc build src/index.ts -o lib",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"test-coverage": "jest --coverage",
|
"test-coverage": "jest --coverage",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format-check": "prettier --check ."
|
"format-check": "prettier --check .",
|
||||||
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/node": "^12.0.10",
|
"@types/node": "^24.0.13",
|
||||||
"@vercel/ncc": "^0.34.0",
|
"@vercel/ncc": "^0.38.3",
|
||||||
"jest": "^26.0.1",
|
"husky": "^9.1.7",
|
||||||
"ts-jest": "^26.0.0",
|
"jest": "^30.0.4",
|
||||||
"typescript": "^3.5.2"
|
"prettier": "^3.6.2",
|
||||||
|
"ts-jest": "^29.4.0",
|
||||||
|
"typescript": "^5.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
src/index.ts
Normal file
4
src/index.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import {run} from './run'
|
||||||
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
|
run().catch(core.setFailed)
|
251
src/run.test.ts
251
src/run.test.ts
@ -6,101 +6,115 @@ 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).toBeCalled()
|
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).toBeCalled()
|
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', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Linux')
|
jest.spyOn(os, 'platform').mockReturnValue('linux')
|
||||||
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
|
jest.spyOn(os, 'arch').mockReturnValue('x64')
|
||||||
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.8.0-linux-amd64.zip'
|
const expected = 'https://test.tld/helm-v3.8.0-linux-amd64.tar.gz'
|
||||||
|
|
||||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl)
|
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
|
||||||
expect(os.type).toBeCalled()
|
expect(os.platform).toHaveBeenCalled()
|
||||||
expect(os.arch).toBeCalled()
|
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'
|
|
||||||
|
|
||||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxArm64Url)
|
|
||||||
expect(os.type).toBeCalled()
|
|
||||||
expect(os.arch).toBeCalled()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
|
test('getHelmDownloadURL() - return the URL to download helm for Linux arm64', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Darwin')
|
jest.spyOn(os, 'platform').mockReturnValue('linux')
|
||||||
jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
|
jest.spyOn(os, 'arch').mockReturnValue('arm64')
|
||||||
const kubectlDarwinUrl =
|
const expected = 'https://test.tld/helm-v3.8.0-linux-arm64.tar.gz'
|
||||||
'https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip'
|
|
||||||
|
|
||||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl)
|
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
|
||||||
expect(os.type).toBeCalled()
|
expect(os.platform).toHaveBeenCalled()
|
||||||
expect(os.arch).toBeCalled()
|
expect(os.arch).toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
// arm64
|
test('getHelmDownloadURL() - return the URL to download helm for Darwin x64', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Darwin')
|
jest.spyOn(os, 'platform').mockReturnValue('darwin')
|
||||||
jest.spyOn(os, 'arch').mockReturnValueOnce('arm64')
|
jest.spyOn(os, 'arch').mockReturnValue('x64')
|
||||||
const kubectlDarwinArm64Url =
|
const expected = 'https://test.tld/helm-v3.8.0-darwin-amd64.tar.gz'
|
||||||
'https://get.helm.sh/helm-v3.8.0-darwin-arm64.zip'
|
|
||||||
|
|
||||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinArm64Url)
|
expect(run.getHelmDownloadURL(downloadBaseURL, 'v3.8.0')).toBe(expected)
|
||||||
expect(os.type).toBeCalled()
|
expect(os.platform).toHaveBeenCalled()
|
||||||
expect(os.arch).toBeCalled()
|
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', () => {
|
test('getValidVersion() - return version with v prepended', () => {
|
||||||
expect(run.getValidVersion('3.8.0')).toBe('v3.8.0')
|
expect(run.getValidVersion('3.8.0')).toBe('v3.8.0')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
|
|
||||||
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()
|
|
||||||
})
|
|
||||||
|
|
||||||
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
|
|
||||||
try {
|
|
||||||
expect(await run.getLatestHelmVersion()).toBe('v3.8.0')
|
|
||||||
} catch (e) {
|
|
||||||
return e
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
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')
|
||||||
return [
|
return [
|
||||||
'file1' as unknown as fs.Dirent,
|
'file1' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'file2' as unknown as fs.Dirent,
|
'file2' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'folder1' as unknown as fs.Dirent,
|
'folder1' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'folder2' as unknown as fs.Dirent
|
'folder2' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>
|
||||||
]
|
]
|
||||||
if (file == path.join('mainFolder', 'folder1'))
|
if (file == path.join('mainFolder', 'folder1'))
|
||||||
return [
|
return [
|
||||||
'file11' as unknown as fs.Dirent,
|
'file11' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'file12' as unknown as fs.Dirent
|
'file12' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>
|
||||||
]
|
]
|
||||||
if (file == path.join('mainFolder', 'folder2'))
|
if (file == path.join('mainFolder', 'folder2'))
|
||||||
return [
|
return [
|
||||||
'file21' as unknown as fs.Dirent,
|
'file21' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'file22' as unknown as fs.Dirent
|
'file22' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>
|
||||||
]
|
]
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
jest.spyOn(core, 'debug').mockImplementation()
|
jest.spyOn(core, 'debug').mockImplementation()
|
||||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
@ -112,29 +126,30 @@ describe('run.ts', () => {
|
|||||||
expect(run.walkSync('mainFolder', null, 'file21')).toEqual([
|
expect(run.walkSync('mainFolder', null, 'file21')).toEqual([
|
||||||
path.join('mainFolder', 'folder2', 'file21')
|
path.join('mainFolder', 'folder2', 'file21')
|
||||||
])
|
])
|
||||||
expect(fs.readdirSync).toBeCalledTimes(3)
|
expect(fs.readdirSync).toHaveBeenCalledTimes(3)
|
||||||
expect(fs.statSync).toBeCalledTimes(8)
|
expect(fs.statSync).toHaveBeenCalledTimes(8)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('walkSync() - return empty array if no file with name fileToFind exists', () => {
|
test('walkSync() - return empty array if no file with name fileToFind exists', () => {
|
||||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||||
if (file == 'mainFolder')
|
if (file == 'mainFolder')
|
||||||
return [
|
return [
|
||||||
'file1' as unknown as fs.Dirent,
|
'file1' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'file2' as unknown as fs.Dirent,
|
'file2' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'folder1' as unknown as fs.Dirent,
|
'folder1' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'folder2' as unknown as fs.Dirent
|
'folder2' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>
|
||||||
]
|
]
|
||||||
if (file == path.join('mainFolder', 'folder1'))
|
if (file == path.join('mainFolder', 'folder1'))
|
||||||
return [
|
return [
|
||||||
'file11' as unknown as fs.Dirent,
|
'file11' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'file12' as unknown as fs.Dirent
|
'file12' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>
|
||||||
]
|
]
|
||||||
if (file == path.join('mainFolder', 'folder2'))
|
if (file == path.join('mainFolder', 'folder2'))
|
||||||
return [
|
return [
|
||||||
'file21' as unknown as fs.Dirent,
|
'file21' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>,
|
||||||
'file22' as unknown as fs.Dirent
|
'file22' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>
|
||||||
]
|
]
|
||||||
|
return []
|
||||||
})
|
})
|
||||||
jest.spyOn(core, 'debug').mockImplementation()
|
jest.spyOn(core, 'debug').mockImplementation()
|
||||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
@ -144,21 +159,23 @@ describe('run.ts', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([])
|
expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([])
|
||||||
expect(fs.readdirSync).toBeCalledTimes(3)
|
expect(fs.readdirSync).toHaveBeenCalledTimes(3)
|
||||||
expect(fs.statSync).toBeCalledTimes(8)
|
expect(fs.statSync).toHaveBeenCalledTimes(8)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('findHelm() - change access permissions and find the helm in given directory', () => {
|
test('findHelm() - change access permissions and find the helm in given directory', () => {
|
||||||
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<Buffer<ArrayBufferLike>>]
|
||||||
|
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')
|
||||||
@ -169,11 +186,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'
|
||||||
)
|
)
|
||||||
@ -184,31 +203,31 @@ 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')
|
||||||
.mockImplementation((file, _) => ['helm.exe' as unknown as fs.Dirent])
|
.mockImplementation((file, _) => [
|
||||||
|
'helm.exe' as unknown as fs.Dirent<Buffer<ArrayBufferLike>>
|
||||||
|
])
|
||||||
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
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(await run.downloadHelm('v4.0.0')).toBe(
|
expect(await run.downloadHelm(downloadBaseURL, 'v4.0.0')).toBe(
|
||||||
path.join('pathToCachedDir', 'helm.exe')
|
path.join('pathToCachedDir', 'helm.exe')
|
||||||
)
|
)
|
||||||
expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0')
|
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v4.0.0')
|
||||||
expect(toolCache.downloadTool).toBeCalledWith(
|
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
||||||
'https://get.helm.sh/helm-v4.0.0-windows-amd64.zip'
|
'https://test.tld/helm-v4.0.0-windows-amd64.zip'
|
||||||
)
|
)
|
||||||
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777')
|
expect(fs.chmodSync).toHaveBeenCalledWith('pathToTool', '777')
|
||||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool')
|
expect(toolCache.extractZip).toHaveBeenCalledWith('pathToTool')
|
||||||
expect(fs.chmodSync).toBeCalledWith(
|
expect(fs.chmodSync).toHaveBeenCalledWith(
|
||||||
path.join('pathToCachedDir', 'helm.exe'),
|
path.join('pathToCachedDir', 'helm.exe'),
|
||||||
'777'
|
'777'
|
||||||
)
|
)
|
||||||
@ -219,26 +238,39 @@ 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')
|
||||||
|
|
||||||
await expect(run.downloadHelm('v3.2.1')).rejects.toThrow(
|
const downloadUrl = 'https://test.tld/helm-v3.2.1-windows-amd64.zip'
|
||||||
'Failed to download Helm from location https://get.helm.sh/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).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(`${downloadUrl}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
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<Buffer<ArrayBufferLike>>
|
||||||
|
])
|
||||||
|
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||||
|
const isDirectory =
|
||||||
|
(file as string).indexOf('folder') == -1 ? false : true
|
||||||
|
return {isDirectory: () => isDirectory} as fs.Stats
|
||||||
|
})
|
||||||
|
|
||||||
expect(await run.downloadHelm('v3.2.1')).toBe(
|
expect(await run.downloadHelm(downloadBaseURL, 'v3.2.1')).toBe(
|
||||||
path.join('pathToCachedDir', 'helm.exe')
|
path.join('pathToCachedDir', 'helm.exe')
|
||||||
)
|
)
|
||||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1')
|
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||||
expect(fs.chmodSync).toBeCalledWith(
|
expect(fs.chmodSync).toHaveBeenCalledWith(
|
||||||
path.join('pathToCachedDir', 'helm.exe'),
|
path.join('pathToCachedDir', 'helm.exe'),
|
||||||
'777'
|
'777'
|
||||||
)
|
)
|
||||||
@ -247,12 +279,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 =
|
||||||
@ -260,14 +291,14 @@ describe('run.ts', () => {
|
|||||||
return {isDirectory: () => isDirectory} as fs.Stats
|
return {isDirectory: () => isDirectory} as fs.Stats
|
||||||
})
|
})
|
||||||
|
|
||||||
await expect(run.downloadHelm('v3.2.1')).rejects.toThrow(
|
await expect(run.downloadHelm(downloadBaseURL, 'v3.2.1')).rejects.toThrow(
|
||||||
'Helm executable not found in path pathToCachedDir'
|
'Helm executable not found in path pathToCachedDir'
|
||||||
)
|
)
|
||||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1')
|
expect(toolCache.find).toHaveBeenCalledWith('helm', 'v3.2.1')
|
||||||
expect(toolCache.downloadTool).toBeCalledWith(
|
expect(toolCache.downloadTool).toHaveBeenCalledWith(
|
||||||
'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
|
'https://test.tld/helm-v3.2.1-windows-amd64.zip'
|
||||||
)
|
)
|
||||||
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777')
|
expect(fs.chmodSync).toHaveBeenCalledWith('pathToTool', '777')
|
||||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool')
|
expect(toolCache.extractZip).toHaveBeenCalledWith('pathToTool')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
131
src/run.ts
131
src/run.ts
@ -1,5 +1,4 @@
|
|||||||
// Copyright (c) Microsoft Corporation.
|
// Copyright (c) Microsoft Corporation.
|
||||||
// Copyright (c) Microsoft Corporation.
|
|
||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
@ -11,21 +10,24 @@ import * as toolCache from '@actions/tool-cache'
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
|
||||||
const helmToolName = 'helm'
|
const helmToolName = 'helm'
|
||||||
const stableHelmVersion = 'v3.8.0'
|
const stableHelmVersion = 'v3.13.3'
|
||||||
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})
|
||||||
|
|
||||||
if (version !== 'latest' && version[0] !== 'v') {
|
if (version !== 'latest' && version[0] !== 'v') {
|
||||||
|
core.info('Getting latest Helm version')
|
||||||
version = getValidVersion(version)
|
version = getValidVersion(version)
|
||||||
}
|
}
|
||||||
if (version.toLocaleLowerCase() === 'latest') {
|
if (version.toLocaleLowerCase() === 'latest') {
|
||||||
version = await getLatestHelmVersion()
|
version = await getLatestHelmVersion()
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(util.format('Downloading %s', version))
|
const downloadBaseURL = core.getInput('downloadBaseURL', {required: false})
|
||||||
let cachedPath = await downloadHelm(version)
|
|
||||||
|
core.startGroup(`Installing ${version}`)
|
||||||
|
const cachedPath = await downloadHelm(downloadBaseURL, version)
|
||||||
|
core.endGroup()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
||||||
@ -35,117 +37,82 @@ export async function run() {
|
|||||||
//do nothing, set as output variable
|
//do nothing, set as output variable
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
core.info(`Helm tool version '${version}' has been cached at ${cachedPath}`)
|
||||||
`Helm tool version: '${version}' has been cached at ${cachedPath}`
|
|
||||||
)
|
|
||||||
core.setOutput('helm-path', cachedPath)
|
core.setOutput('helm-path', cachedPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns version with proper v before it
|
// Prefixes version with v
|
||||||
export function getValidVersion(version: string): string {
|
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 response = await fetch('https://get.helm.sh/helm-latest-version')
|
||||||
for (let i in helmJSON) {
|
const release = (await response.text()).trim()
|
||||||
if (isValidVersion(helmJSON[i].tag_name)) {
|
return release
|
||||||
return helmJSON[i].tag_name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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
|
||||||
}
|
}
|
||||||
|
|
||||||
return stableHelmVersion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// isValidVersion checks if verison is a stable release
|
export function getArch(): string {
|
||||||
function isValidVersion(version: string): boolean {
|
return os.arch() === 'x64' ? 'amd64' : os.arch()
|
||||||
return version.indexOf('rc') == -1
|
}
|
||||||
|
|
||||||
|
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'
|
export function getHelmDownloadURL(baseURL: string, version: string): string {
|
||||||
const MAC_OS = 'Darwin'
|
const urlPath = `helm-${version}-${getPlatform()}-${getArch()}.${getArchiveExtension()}`
|
||||||
const WINDOWS = 'Windows_NT'
|
const url = new URL(urlPath, baseURL)
|
||||||
const ARM64 = 'arm64'
|
return url.toString()
|
||||||
export function getHelmDownloadURL(version: string): string {
|
|
||||||
const arch = os.arch()
|
|
||||||
const operatingSystem = os.type()
|
|
||||||
|
|
||||||
switch (true) {
|
|
||||||
case operatingSystem == LINUX && arch == ARM64:
|
|
||||||
return util.format(
|
|
||||||
'https://get.helm.sh/helm-%s-linux-arm64.zip',
|
|
||||||
version
|
|
||||||
)
|
|
||||||
case operatingSystem == LINUX:
|
|
||||||
return util.format(
|
|
||||||
'https://get.helm.sh/helm-%s-linux-amd64.zip',
|
|
||||||
version
|
|
||||||
)
|
|
||||||
|
|
||||||
case operatingSystem == MAC_OS && arch == ARM64:
|
|
||||||
return util.format(
|
|
||||||
'https://get.helm.sh/helm-%s-darwin-arm64.zip',
|
|
||||||
version
|
|
||||||
)
|
|
||||||
case operatingSystem == MAC_OS:
|
|
||||||
return util.format(
|
|
||||||
'https://get.helm.sh/helm-%s-darwin-amd64.zip',
|
|
||||||
version
|
|
||||||
)
|
|
||||||
|
|
||||||
case operatingSystem == WINDOWS:
|
|
||||||
default:
|
|
||||||
return util.format(
|
|
||||||
'https://get.helm.sh/helm-%s-windows-amd64.zip',
|
|
||||||
version
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function downloadHelm(version: string): Promise<string> {
|
export async function downloadHelm(
|
||||||
|
baseURL: string,
|
||||||
|
version: string
|
||||||
|
): Promise<string> {
|
||||||
let cachedToolpath = toolCache.find(helmToolName, version)
|
let cachedToolpath = toolCache.find(helmToolName, version)
|
||||||
if (!cachedToolpath) {
|
if (cachedToolpath) {
|
||||||
|
core.info(`Restoring '${version}' from cache`)
|
||||||
|
} else {
|
||||||
|
core.info(`Downloading '${version}' from '${baseURL}'`)
|
||||||
let helmDownloadPath
|
let helmDownloadPath
|
||||||
try {
|
try {
|
||||||
helmDownloadPath = await toolCache.downloadTool(
|
helmDownloadPath = await toolCache.downloadTool(
|
||||||
getHelmDownloadURL(version)
|
getHelmDownloadURL(baseURL, version)
|
||||||
)
|
)
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
util.format(
|
`Failed to download Helm from location ${getHelmDownloadURL(
|
||||||
'Failed to download Helm from location',
|
baseURL,
|
||||||
getHelmDownloadURL(version)
|
version
|
||||||
)
|
)}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
)
|
)
|
||||||
@ -190,5 +157,3 @@ export var walkSync = function (dir, filelist, fileToFind) {
|
|||||||
})
|
})
|
||||||
return filelist
|
return filelist
|
||||||
}
|
}
|
||||||
|
|
||||||
run().catch(core.setFailed)
|
|
||||||
|
Reference in New Issue
Block a user