Compare commits
16 Commits
v2.1
...
releases/v
Author | SHA1 | Date | |
---|---|---|---|
9130a7accc | |||
5119fcb908 | |||
f382f75448 | |||
b5b231a831 | |||
84b304dfb7 | |||
e4f3964f67 | |||
20d2b4f98d | |||
a767c8d3a1 | |||
97c3a3f138 | |||
0a86c98d61 | |||
39f78708c2 | |||
fa870ea9a2 | |||
e00756a00e | |||
2998c83e16 | |||
5876560d6c | |||
7e6f48e5b4 |
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@ -1 +1 @@
|
||||
* @Azure/aksatlanta
|
||||
* @Azure/aks-atlanta
|
||||
|
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
|
@ -4,7 +4,4 @@ about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: need-to-triage
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
3
.github/workflows/defaultLabels.yml
vendored
3
.github/workflows/defaultLabels.yml
vendored
@ -3,7 +3,7 @@ name: setting-default-labels
|
||||
# Controls when the action will run.
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0/3 * * *"
|
||||
- cron: '0 0/3 * * *'
|
||||
|
||||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
|
||||
jobs:
|
||||
@ -13,7 +13,6 @@ jobs:
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
|
||||
- uses: actions/stale@v3
|
||||
name: Setting issue as idle
|
||||
with:
|
||||
|
18
.github/workflows/integration-tests.yml
vendored
18
.github/workflows/integration-tests.yml
vendored
@ -1,17 +1,17 @@
|
||||
name: "Trigger Integration tests"
|
||||
name: 'Trigger Integration tests'
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- 'releases/*'
|
||||
jobs:
|
||||
trigger-integration-tests:
|
||||
name: Trigger Integration tests
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
HELM_3_8_0: "v3.8.0"
|
||||
HELM_3_7_2: "v3.7.2"
|
||||
HELM_3_5_0: "v3.5.0"
|
||||
HELM_3_8_0: 'v3.8.0'
|
||||
HELM_3_7_2: 'v3.7.2'
|
||||
HELM_NO_V: '3.5.0'
|
||||
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||
steps:
|
||||
- name: Check out repository
|
||||
@ -50,13 +50,13 @@ jobs:
|
||||
else
|
||||
echo "HELM VERSION $HELM_3_7_2 INSTALLED SUCCESSFULLY"
|
||||
fi
|
||||
- name: Setup helm 3.5.0
|
||||
- name: Setup helm 3.5.0 with no v in version
|
||||
uses: ./
|
||||
with:
|
||||
version: ${{ env.HELM_3_5_0 }}
|
||||
- name: Validate 3.5.0
|
||||
version: ${{ env.HELM_NO_V }}
|
||||
- name: Validate 3.5.0 without v in version
|
||||
run: |
|
||||
if [[ $(helm version) != *$HELM_3_5_0* ]]; then
|
||||
if [[ $(helm version) != *$HELM_NO_V* ]]; then
|
||||
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.5.0"
|
||||
echo "HELM VERSION OUTPUT: $(helm version)"
|
||||
exit 1
|
||||
|
18
.github/workflows/prettify-code.yml
vendored
Normal file
18
.github/workflows/prettify-code.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: 'Run prettify'
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
prettier:
|
||||
name: Prettier Check
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Enforce Prettier
|
||||
uses: actionsx/prettier@v2
|
||||
with:
|
||||
args: --check .
|
51
.github/workflows/release-pr.yml
vendored
51
.github/workflows/release-pr.yml
vendored
@ -1,55 +1,14 @@
|
||||
name: "Create release PR"
|
||||
name: Create release PR
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release:
|
||||
description: "Define release version (ex: v1, v2, v3)"
|
||||
description: 'Define release version (ex: v1, v2, v3)'
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
createPullRequest:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
release-pr:
|
||||
uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Check if remote branch exists
|
||||
env:
|
||||
BRANCH: releases/${{ github.event.inputs.release }}
|
||||
run: |
|
||||
echo "##[set-output name=exists;]$(echo $(if [[ -z $(git ls-remote --heads origin ${BRANCH}) ]]; then echo false; else echo true; fi;))"
|
||||
id: extract-branch-status
|
||||
# these two only need to occur if the branch exists
|
||||
- name: Checkout proper branch
|
||||
if: ${{ steps.extract-branch-status.outputs.exists == 'true' }}
|
||||
env:
|
||||
BRANCH: releases/${{ github.event.inputs.release }}
|
||||
run: git checkout ${BRANCH}
|
||||
- name: Reset promotion branch
|
||||
if: ${{ steps.extract-branch-status.outputs.exists == 'true' }}
|
||||
run: |
|
||||
git fetch origin master:master
|
||||
git reset --hard master
|
||||
- name: Install packages
|
||||
run: |
|
||||
rm -rf node_modules/
|
||||
npm install --no-bin-links
|
||||
npm run build
|
||||
- name: Remove node_modules from gitignore
|
||||
run: |
|
||||
sed -i '/node_modules/d' ./.gitignore
|
||||
- name: Create branch
|
||||
uses: peterjgrainger/action-create-branch@v2.0.1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
branch: releases/${{ github.event.inputs.release }}
|
||||
- name: Create pull request
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
commit-message: Add node modules and new code for release
|
||||
title: ${{ github.event.inputs.release }} new release
|
||||
base: releases/${{ github.event.inputs.release }}
|
||||
branch: create-release
|
||||
release: ${{ github.event.inputs.release }}
|
||||
|
10
.github/workflows/tag-and-draft.yml
vendored
Normal file
10
.github/workflows/tag-and-draft.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
name: Tag and create release draft
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- releases/*
|
||||
|
||||
jobs:
|
||||
tag-and-release:
|
||||
uses: OliverMKing/javascript-release-workflow/.github/workflows/tag-and-release.yml@main
|
77
.github/workflows/tag-and-release.yml
vendored
77
.github/workflows/tag-and-release.yml
vendored
@ -1,77 +0,0 @@
|
||||
name: "Tag and create release draft"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- releases/*
|
||||
|
||||
jobs:
|
||||
gh_tagged_release:
|
||||
runs-on: "ubuntu-latest"
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Test release
|
||||
run: |
|
||||
sudo npm install n
|
||||
sudo n latest
|
||||
npm test
|
||||
- name: Get branch ending
|
||||
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/} | sed 's:.*/::')"
|
||||
id: extract-branch
|
||||
- name: Get tags
|
||||
run: |
|
||||
echo "##[set-output name=tags;]$(echo $(git tag))"
|
||||
id: extract-tags
|
||||
- name: Get latest tag
|
||||
uses: actions/github-script@v5
|
||||
env:
|
||||
TAGS: ${{ steps.extract-tags.outputs.tags }}
|
||||
BRANCH: ${{ steps.extract-branch.outputs.branch }}
|
||||
with:
|
||||
script: |
|
||||
const tags = process.env["TAGS"]
|
||||
.split(" ")
|
||||
.map((x) => x.trim());
|
||||
const branch = process.env["BRANCH"];
|
||||
const splitTag = (x) =>
|
||||
x
|
||||
.substring(branch.length + 1)
|
||||
.split(".")
|
||||
.map((x) => Number(x));
|
||||
function compareTags(nums1, nums2, position = 0) {
|
||||
if (nums1.length < position && nums2.length < position) return nums2;
|
||||
const num1 = splitTag(nums1)[position] || 0;
|
||||
const num2 = splitTag(nums2)[position] || 0;
|
||||
if (num1 === num2) return compareTags(nums1, nums2, position + 1);
|
||||
else if (num1 > num2) return nums1;
|
||||
else return nums2;
|
||||
}
|
||||
const branchTags = tags.filter((tag) => tag.startsWith(branch));
|
||||
if (branchTags.length < 1) return branch + ".-1"
|
||||
return branchTags.reduce((prev, curr) => compareTags(prev, curr));
|
||||
result-encoding: string
|
||||
id: get-latest-tag
|
||||
- name: Get new tag
|
||||
uses: actions/github-script@v5
|
||||
env:
|
||||
PREV: ${{ steps.get-latest-tag.outputs.result }}
|
||||
with:
|
||||
script: |
|
||||
let version = process.env["PREV"]
|
||||
if (!version.includes(".")) version += ".0"; // case of v1 or v2
|
||||
const prefix = /^([a-zA-Z]+)/.exec(version)[0];
|
||||
const numbers = version.substring(prefix.length);
|
||||
let split = numbers.split(".");
|
||||
split[split.length - 1] = parseInt(split[split.length - 1]) + 1;
|
||||
return prefix + split.join(".");
|
||||
result-encoding: string
|
||||
id: get-new-tag
|
||||
- uses: "marvinpinto/action-automatic-releases@v1.2.1"
|
||||
with:
|
||||
title: ${{ steps.get-new-tag.outputs.result }} release
|
||||
automatic_release_tag: ${{ steps.get-new-tag.outputs.result }}
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
draft: true
|
6
.github/workflows/unit-tests.yml
vendored
6
.github/workflows/unit-tests.yml
vendored
@ -1,12 +1,12 @@
|
||||
name: "Run unit tests."
|
||||
name: 'Run unit tests.'
|
||||
on: # rebuild any PRs and main branch changes
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- 'releases/*'
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- 'releases/*'
|
||||
|
||||
jobs:
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,8 +11,6 @@ pids
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
@ -62,3 +60,5 @@ typings/
|
||||
|
||||
node_modules
|
||||
coverage
|
||||
|
||||
# Transpiled JS
|
||||
|
4
.prettierignore
Normal file
4
.prettierignore
Normal file
@ -0,0 +1,4 @@
|
||||
# dependencies
|
||||
/node_modules
|
||||
coverage
|
||||
/lib
|
8
.prettierrc.json
Normal file
8
.prettierrc.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"tabWidth": 3,
|
||||
"singleQuote": true,
|
||||
"printWidth": 80
|
||||
}
|
17
README.md
17
README.md
@ -1,20 +1,25 @@
|
||||
# Setup Helm
|
||||
|
||||
Install a specific version of helm binary on the runner.
|
||||
|
||||
## Example
|
||||
|
||||
Acceptable values are latest or any semantic version string like v2.16.7 Use this action in workflow to define which version of helm will be used.
|
||||
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.
|
||||
|
||||
```yaml
|
||||
- uses: azure/setup-helm@v1
|
||||
- uses: azure/setup-helm@v3
|
||||
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
|
||||
```
|
||||
|
||||
> Note: When using latest version you might hit the GitHub GraphQL API hourly rate limit of 5,000. The action will then return the hardcoded default stable version (currently v3.9.0). If you rely on a certain version higher than the default, you should use that version instead of latest.
|
||||
|
||||
The cached helm binary path is prepended to the PATH environment variable as well as stored in the helm-path output variable.
|
||||
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
|
||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
||||
@ -27,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/).
|
||||
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.
|
||||
|
||||
## 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.
|
||||
|
16
SECURITY.md
16
SECURITY.md
@ -4,7 +4,7 @@
|
||||
|
||||
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [many more](https://opensource.microsoft.com/).
|
||||
|
||||
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [definition](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)) of a security vulnerability, please report it to us as described below.
|
||||
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets Microsoft's [definition](<https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)>) of a security vulnerability, please report it to us as described below.
|
||||
|
||||
## Reporting Security Issues
|
||||
|
||||
@ -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:
|
||||
|
||||
* 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
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Any special configuration required to reproduce the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
- 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
|
||||
- The location of the affected source code (tag/branch/commit or direct URL)
|
||||
- Any special configuration required to reproduce the issue
|
||||
- Step-by-step instructions to reproduce the issue
|
||||
- Proof-of-concept or exploit code (if possible)
|
||||
- Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
This information will help us triage your report more quickly.
|
||||
|
||||
|
@ -1,174 +0,0 @@
|
||||
import * as run from '../src/run'
|
||||
import * as os from 'os';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
describe('run.ts', () => {
|
||||
test('getExecutableExtension() - return .exe when os is Windows', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('.exe');
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getExecutableExtension() - return empty string for non-windows OS', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('');
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
||||
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.8.0-linux-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
||||
const kubectlDarwinUrl = 'https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
|
||||
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', () => {
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return ['file1' as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder1')) return ['file11' as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder2')) return ['file21' as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent];
|
||||
});
|
||||
jest.spyOn(core, 'debug').mockImplementation();
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).toLowerCase().indexOf('file') == -1 ? true: false
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
|
||||
expect(run.walkSync('mainFolder', null, 'file21')).toEqual([path.join('mainFolder', 'folder2', 'file21')]);
|
||||
expect(fs.readdirSync).toBeCalledTimes(3);
|
||||
expect(fs.statSync).toBeCalledTimes(8);
|
||||
});
|
||||
|
||||
test('walkSync() - return empty array if no file with name fileToFind exists', () => {
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return ['file1' as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder1')) return ['file11' as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent];
|
||||
if (file == path.join('mainFolder', 'folder2')) return ['file21' as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent];
|
||||
});
|
||||
jest.spyOn(core, 'debug').mockImplementation();
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).toLowerCase().indexOf('file') == -1 ? true: false
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
|
||||
expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([]);
|
||||
expect(fs.readdirSync).toBeCalledTimes(3);
|
||||
expect(fs.statSync).toBeCalledTimes(8);
|
||||
});
|
||||
|
||||
test('findHelm() - change access permissions and find the helm in given directory', () => {
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return ['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;
|
||||
});
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
|
||||
expect(run.findHelm('mainFolder')).toBe(path.join('mainFolder', 'helm.exe'));
|
||||
});
|
||||
|
||||
test('findHelm() - throw error if executable not found', () => {
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return [];
|
||||
});
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => { return { isDirectory: () => true } as fs.Stats});
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
expect(() => run.findHelm('mainFolder')).toThrow('Helm executable not found in path mainFolder');
|
||||
});
|
||||
|
||||
test('downloadHelm() - download helm and return path to it', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');
|
||||
const response = JSON.stringify([{'tag_name': 'v4.0.0'}]);
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue(response);
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('pathToUnzippedHelm');
|
||||
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir');
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => ['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;
|
||||
});
|
||||
|
||||
expect(await run.downloadHelm("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(fs.chmodSync).toBeCalledWith('pathToTool', '777');
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool');
|
||||
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedDir', 'helm.exe'), '777');
|
||||
});
|
||||
|
||||
test('downloadHelm() - throw error if unable to download', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => { throw 'Unable to download'});
|
||||
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');
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1');
|
||||
expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v3.2.1-windows-amd64.zip');
|
||||
});
|
||||
|
||||
test('downloadHelm() - return path to helm tool with same version from toolCache', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {});
|
||||
|
||||
expect(await run.downloadHelm('v3.2.1')).toBe(path.join('pathToCachedDir', 'helm.exe'));
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1');
|
||||
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedDir', 'helm.exe'), '777');
|
||||
});
|
||||
|
||||
test('downloadHelm() - throw error is helm is not found in path', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation();
|
||||
jest.spyOn(toolCache, 'extractZip').mockResolvedValue('pathToUnzippedHelm');
|
||||
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir');
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => []);
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory = (file as string).indexOf('folder') == -1 ? false: true
|
||||
return { isDirectory: () => isDirectory } as fs.Stats;
|
||||
});
|
||||
|
||||
await expect(run.downloadHelm('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(fs.chmodSync).toBeCalledWith('pathToTool', '777');
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool');
|
||||
});
|
||||
});
|
@ -5,11 +5,14 @@ inputs:
|
||||
description: 'Version of helm'
|
||||
required: true
|
||||
default: 'latest'
|
||||
token:
|
||||
description: GitHub token. Required only if 'version' == 'latest'
|
||||
required: false
|
||||
outputs:
|
||||
helm-path:
|
||||
description: 'Path to the cached helm binary'
|
||||
branding:
|
||||
color: 'blue'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/run.js'
|
||||
using: 'node16'
|
||||
main: 'lib/index.js'
|
||||
|
@ -8,11 +8,11 @@ module.exports = {
|
||||
},
|
||||
verbose: true,
|
||||
coverageThreshold: {
|
||||
"global": {
|
||||
"branches": 0,
|
||||
"functions": 14,
|
||||
"lines": 27,
|
||||
"statements": 27
|
||||
global: {
|
||||
branches: 0,
|
||||
functions: 14,
|
||||
lines: 27,
|
||||
statements: 27
|
||||
}
|
||||
}
|
||||
}
|
11879
lib/index.js
Normal file
11879
lib/index.js
Normal file
File diff suppressed because one or more lines are too long
142
lib/run.js
142
lib/run.js
@ -1,142 +0,0 @@
|
||||
"use strict";
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.walkSync = exports.findHelm = exports.downloadHelm = exports.getHelmDownloadURL = exports.getExecutableExtension = exports.getLatestHelmVersion = exports.run = void 0;
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const util = require("util");
|
||||
const fs = require("fs");
|
||||
const toolCache = require("@actions/tool-cache");
|
||||
const core = require("@actions/core");
|
||||
const helmToolName = 'helm';
|
||||
const stableHelmVersion = 'v3.8.0';
|
||||
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = yield getLatestHelmVersion();
|
||||
}
|
||||
core.debug(util.format("Downloading %s", version));
|
||||
let cachedPath = yield downloadHelm(version);
|
||||
try {
|
||||
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
||||
core.addPath(path.dirname(cachedPath));
|
||||
}
|
||||
}
|
||||
catch (_a) {
|
||||
//do nothing, set as output variable
|
||||
}
|
||||
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
|
||||
core.setOutput('helm-path', cachedPath);
|
||||
});
|
||||
}
|
||||
exports.run = run;
|
||||
// Downloads the helm releases JSON and parses all the recent versions of helm from it.
|
||||
// Defaults to sending stable helm version if none are valid or if it fails
|
||||
function getLatestHelmVersion() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const helmJSONPath = yield toolCache.downloadTool(helmAllReleasesUrl);
|
||||
try {
|
||||
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'));
|
||||
for (let i in helmJSON) {
|
||||
if (isValidVersion(helmJSON[i].tag_name)) {
|
||||
return helmJSON[i].tag_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
core.warning(util.format("Error while fetching the latest Helm release. Error: %s. Using default Helm version %s", err.toString(), stableHelmVersion));
|
||||
return stableHelmVersion;
|
||||
}
|
||||
return stableHelmVersion;
|
||||
});
|
||||
}
|
||||
exports.getLatestHelmVersion = getLatestHelmVersion;
|
||||
// isValidVersion checks if verison is a stable release
|
||||
function isValidVersion(version) {
|
||||
return version.indexOf('rc') == -1;
|
||||
}
|
||||
function getExecutableExtension() {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
exports.getExecutableExtension = getExecutableExtension;
|
||||
function getHelmDownloadURL(version) {
|
||||
switch (os.type()) {
|
||||
case 'Linux':
|
||||
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version);
|
||||
case 'Darwin':
|
||||
return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version);
|
||||
case 'Windows_NT':
|
||||
default:
|
||||
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
||||
}
|
||||
}
|
||||
exports.getHelmDownloadURL = getHelmDownloadURL;
|
||||
function downloadHelm(version) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||
if (!cachedToolpath) {
|
||||
let helmDownloadPath;
|
||||
try {
|
||||
helmDownloadPath = yield toolCache.downloadTool(getHelmDownloadURL(version));
|
||||
}
|
||||
catch (exception) {
|
||||
throw new Error(util.format("Failed to download Helm from location", getHelmDownloadURL(version)));
|
||||
}
|
||||
fs.chmodSync(helmDownloadPath, '777');
|
||||
const unzipedHelmPath = yield toolCache.extractZip(helmDownloadPath);
|
||||
cachedToolpath = yield toolCache.cacheDir(unzipedHelmPath, helmToolName, version);
|
||||
}
|
||||
const helmpath = findHelm(cachedToolpath);
|
||||
if (!helmpath) {
|
||||
throw new Error(util.format("Helm executable not found in path", cachedToolpath));
|
||||
}
|
||||
fs.chmodSync(helmpath, '777');
|
||||
return helmpath;
|
||||
});
|
||||
}
|
||||
exports.downloadHelm = downloadHelm;
|
||||
function findHelm(rootFolder) {
|
||||
fs.chmodSync(rootFolder, '777');
|
||||
var filelist = [];
|
||||
exports.walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
||||
if (!filelist || filelist.length == 0) {
|
||||
throw new Error(util.format("Helm executable not found in path", rootFolder));
|
||||
}
|
||||
else {
|
||||
return filelist[0];
|
||||
}
|
||||
}
|
||||
exports.findHelm = findHelm;
|
||||
exports.walkSync = function (dir, filelist, fileToFind) {
|
||||
var files = fs.readdirSync(dir);
|
||||
filelist = filelist || [];
|
||||
files.forEach(function (file) {
|
||||
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||
filelist = exports.walkSync(path.join(dir, file), filelist, fileToFind);
|
||||
}
|
||||
else {
|
||||
core.debug(file);
|
||||
if (file == fileToFind) {
|
||||
filelist.push(path.join(dir, file));
|
||||
}
|
||||
}
|
||||
});
|
||||
return filelist;
|
||||
};
|
||||
run().catch(core.setFailed);
|
2714
package-lock.json
generated
2714
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -6,24 +6,28 @@
|
||||
"author": "Anumita Shenoy",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/io": "^1.0.0",
|
||||
"@actions/tool-cache": "1.1.2",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@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"
|
||||
},
|
||||
"main": "lib/run.js",
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "tsc --outDir ./lib --rootDir ./src",
|
||||
"build": "ncc build src/run.ts -o lib",
|
||||
"test": "jest",
|
||||
"test-coverage": "jest --coverage"
|
||||
"test-coverage": "jest --coverage",
|
||||
"format": "prettier --write .",
|
||||
"format-check": "prettier --check ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/node": "^12.0.10",
|
||||
"typescript": "^3.5.2",
|
||||
"@vercel/ncc": "^0.34.0",
|
||||
"jest": "^26.0.1",
|
||||
"@types/jest": "^25.2.2",
|
||||
"ts-jest": "^25.5.1"
|
||||
"ts-jest": "^26.0.0",
|
||||
"typescript": "^3.5.2"
|
||||
}
|
||||
}
|
||||
|
269
src/run.test.ts
Normal file
269
src/run.test.ts
Normal file
@ -0,0 +1,269 @@
|
||||
import * as run from './run'
|
||||
import * as os from 'os'
|
||||
import * as toolCache from '@actions/tool-cache'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
describe('run.ts', () => {
|
||||
test('getExecutableExtension() - return .exe when os is Windows', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('.exe')
|
||||
expect(os.type).toBeCalled()
|
||||
})
|
||||
|
||||
test('getExecutableExtension() - return empty string for non-windows OS', () => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin')
|
||||
|
||||
expect(run.getExecutableExtension()).toBe('')
|
||||
expect(os.type).toBeCalled()
|
||||
})
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
|
||||
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'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.arch).toBeCalled()
|
||||
|
||||
// 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', () => {
|
||||
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'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.arch).toBeCalled()
|
||||
|
||||
// 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'
|
||||
|
||||
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinArm64Url)
|
||||
expect(os.type).toBeCalled()
|
||||
expect(os.arch).toBeCalled()
|
||||
})
|
||||
|
||||
test('getValidVersion() - return version with v prepended', () => {
|
||||
expect(run.getValidVersion('3.8.0')).toBe('v3.8.0')
|
||||
})
|
||||
|
||||
test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
|
||||
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 stable version of HELM since its not authenticated', async () => {
|
||||
expect(await run.getLatestHelmVersion()).toBe('v3.9.0')
|
||||
})
|
||||
|
||||
test('walkSync() - return path to the all files matching fileToFind in dir', () => {
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder')
|
||||
return [
|
||||
'file1' as unknown as fs.Dirent,
|
||||
'file2' as unknown as fs.Dirent,
|
||||
'folder1' as unknown as fs.Dirent,
|
||||
'folder2' as unknown as fs.Dirent
|
||||
]
|
||||
if (file == path.join('mainFolder', 'folder1'))
|
||||
return [
|
||||
'file11' as unknown as fs.Dirent,
|
||||
'file12' as unknown as fs.Dirent
|
||||
]
|
||||
if (file == path.join('mainFolder', 'folder2'))
|
||||
return [
|
||||
'file21' as unknown as fs.Dirent,
|
||||
'file22' as unknown as fs.Dirent
|
||||
]
|
||||
})
|
||||
jest.spyOn(core, 'debug').mockImplementation()
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory =
|
||||
(file as string).toLowerCase().indexOf('file') == -1 ? true : false
|
||||
return {isDirectory: () => isDirectory} as fs.Stats
|
||||
})
|
||||
|
||||
expect(run.walkSync('mainFolder', null, 'file21')).toEqual([
|
||||
path.join('mainFolder', 'folder2', 'file21')
|
||||
])
|
||||
expect(fs.readdirSync).toBeCalledTimes(3)
|
||||
expect(fs.statSync).toBeCalledTimes(8)
|
||||
})
|
||||
|
||||
test('walkSync() - return empty array if no file with name fileToFind exists', () => {
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder')
|
||||
return [
|
||||
'file1' as unknown as fs.Dirent,
|
||||
'file2' as unknown as fs.Dirent,
|
||||
'folder1' as unknown as fs.Dirent,
|
||||
'folder2' as unknown as fs.Dirent
|
||||
]
|
||||
if (file == path.join('mainFolder', 'folder1'))
|
||||
return [
|
||||
'file11' as unknown as fs.Dirent,
|
||||
'file12' as unknown as fs.Dirent
|
||||
]
|
||||
if (file == path.join('mainFolder', 'folder2'))
|
||||
return [
|
||||
'file21' as unknown as fs.Dirent,
|
||||
'file22' as unknown as fs.Dirent
|
||||
]
|
||||
})
|
||||
jest.spyOn(core, 'debug').mockImplementation()
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory =
|
||||
(file as string).toLowerCase().indexOf('file') == -1 ? true : false
|
||||
return {isDirectory: () => isDirectory} as fs.Stats
|
||||
})
|
||||
|
||||
expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([])
|
||||
expect(fs.readdirSync).toBeCalledTimes(3)
|
||||
expect(fs.statSync).toBeCalledTimes(8)
|
||||
})
|
||||
|
||||
test('findHelm() - change access permissions and find the helm in given directory', () => {
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return ['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
|
||||
})
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
expect(run.findHelm('mainFolder')).toBe(
|
||||
path.join('mainFolder', 'helm.exe')
|
||||
)
|
||||
})
|
||||
|
||||
test('findHelm() - throw error if executable not found', () => {
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => {
|
||||
if (file == 'mainFolder') return []
|
||||
})
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
return {isDirectory: () => true} as fs.Stats
|
||||
})
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
expect(() => run.findHelm('mainFolder')).toThrow(
|
||||
'Helm executable not found in path mainFolder'
|
||||
)
|
||||
})
|
||||
|
||||
test('downloadHelm() - download helm and return path to it', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
||||
const response = JSON.stringify([{tag_name: 'v4.0.0'}])
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue(response)
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
jest
|
||||
.spyOn(toolCache, 'extractZip')
|
||||
.mockResolvedValue('pathToUnzippedHelm')
|
||||
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
|
||||
jest
|
||||
.spyOn(fs, 'readdirSync')
|
||||
.mockImplementation((file, _) => ['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
|
||||
})
|
||||
|
||||
expect(await run.downloadHelm('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(fs.chmodSync).toBeCalledWith('pathToTool', '777')
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool')
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
path.join('pathToCachedDir', 'helm.exe'),
|
||||
'777'
|
||||
)
|
||||
})
|
||||
|
||||
test('downloadHelm() - throw error if unable to download', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest.spyOn(toolCache, 'downloadTool').mockImplementation(async () => {
|
||||
throw 'Unable to download'
|
||||
})
|
||||
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'
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1')
|
||||
expect(toolCache.downloadTool).toBeCalledWith(
|
||||
'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
|
||||
)
|
||||
})
|
||||
|
||||
test('downloadHelm() - return path to helm tool with same version from toolCache', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
|
||||
expect(await run.downloadHelm('v3.2.1')).toBe(
|
||||
path.join('pathToCachedDir', 'helm.exe')
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('helm', 'v3.2.1')
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
path.join('pathToCachedDir', 'helm.exe'),
|
||||
'777'
|
||||
)
|
||||
})
|
||||
|
||||
test('downloadHelm() - throw error is helm is not found in path', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool')
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation()
|
||||
jest
|
||||
.spyOn(toolCache, 'extractZip')
|
||||
.mockResolvedValue('pathToUnzippedHelm')
|
||||
jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
|
||||
jest.spyOn(fs, 'readdirSync').mockImplementation((file, _) => [])
|
||||
jest.spyOn(fs, 'statSync').mockImplementation((file) => {
|
||||
const isDirectory =
|
||||
(file as string).indexOf('folder') == -1 ? false : true
|
||||
return {isDirectory: () => isDirectory} as fs.Stats
|
||||
})
|
||||
|
||||
await expect(run.downloadHelm('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(fs.chmodSync).toBeCalledWith('pathToTool', '777')
|
||||
expect(toolCache.extractZip).toBeCalledWith('pathToTool')
|
||||
})
|
||||
})
|
207
src/run.ts
207
src/run.ts
@ -2,140 +2,209 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
import * as util from 'util'
|
||||
import * as fs from 'fs'
|
||||
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
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.8.0';
|
||||
const helmAllReleasesUrl = 'https://api.github.com/repos/helm/helm/releases';
|
||||
const helmToolName = 'helm'
|
||||
const stableHelmVersion = 'v3.9.0'
|
||||
|
||||
export async function run() {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
let version = core.getInput('version', {required: true})
|
||||
|
||||
if (version !== 'latest' && version[0] !== 'v') {
|
||||
core.info('Getting latest Helm version')
|
||||
version = getValidVersion(version)
|
||||
}
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = await getLatestHelmVersion();
|
||||
version = await getLatestHelmVersion()
|
||||
}
|
||||
|
||||
core.debug(util.format("Downloading %s", version));
|
||||
let cachedPath = await downloadHelm(version);
|
||||
core.startGroup(`Downloading ${version}`)
|
||||
const cachedPath = await downloadHelm(version)
|
||||
core.endGroup()
|
||||
|
||||
try {
|
||||
|
||||
if (!process.env['PATH'].startsWith(path.dirname(cachedPath))) {
|
||||
core.addPath(path.dirname(cachedPath));
|
||||
core.addPath(path.dirname(cachedPath))
|
||||
}
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
//do nothing, set as output variable
|
||||
}
|
||||
|
||||
console.log(`Helm tool version: '${version}' has been cached at ${cachedPath}`);
|
||||
core.setOutput('helm-path', cachedPath);
|
||||
core.info(`Helm tool version '${version}' has been cached at ${cachedPath}`)
|
||||
core.setOutput('helm-path', cachedPath)
|
||||
}
|
||||
|
||||
// Downloads the helm releases JSON and parses all the recent versions of helm from it.
|
||||
// Defaults to sending stable helm version if none are valid or if it fails
|
||||
// Prefixes version with v
|
||||
export function getValidVersion(version: string): string {
|
||||
return 'v' + version
|
||||
}
|
||||
|
||||
// Gets the latest helm version or returns a default stable if getting latest fails
|
||||
export async function getLatestHelmVersion(): Promise<string> {
|
||||
const helmJSONPath: string = await toolCache.downloadTool(helmAllReleasesUrl);
|
||||
|
||||
try {
|
||||
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'))
|
||||
for(let i in helmJSON) {
|
||||
if(isValidVersion(helmJSON[i].tag_name)) {
|
||||
return helmJSON[i].tag_name;
|
||||
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
|
||||
} catch (err) {
|
||||
core.warning(util.format("Error while fetching the latest Helm release. Error: %s. Using default Helm version %s", err.toString(), stableHelmVersion));
|
||||
return stableHelmVersion;
|
||||
core.warning(
|
||||
`Error while fetching latest Helm release: ${err.toString()}. Using default version ${stableHelmVersion}`
|
||||
)
|
||||
return 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;
|
||||
return version.indexOf('rc') == -1
|
||||
}
|
||||
|
||||
export function getExecutableExtension(): string {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
return '.exe'
|
||||
}
|
||||
return '';
|
||||
return ''
|
||||
}
|
||||
|
||||
const LINUX = 'Linux'
|
||||
const MAC_OS = 'Darwin'
|
||||
const WINDOWS = 'Windows_NT'
|
||||
const ARM64 = 'arm64'
|
||||
export function getHelmDownloadURL(version: string): string {
|
||||
switch (os.type()) {
|
||||
case 'Linux':
|
||||
return util.format('https://get.helm.sh/helm-%s-linux-amd64.zip', version);
|
||||
const arch = os.arch()
|
||||
const operatingSystem = os.type()
|
||||
|
||||
case 'Darwin':
|
||||
return util.format('https://get.helm.sh/helm-%s-darwin-amd64.zip', version);
|
||||
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
|
||||
)
|
||||
case operatingSystem == LINUX:
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-linux-amd64.zip',
|
||||
version
|
||||
)
|
||||
|
||||
case 'Windows_NT':
|
||||
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
|
||||
)
|
||||
case operatingSystem == MAC_OS:
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-darwin-amd64.zip',
|
||||
version
|
||||
)
|
||||
|
||||
case operatingSystem == WINDOWS:
|
||||
default:
|
||||
return util.format('https://get.helm.sh/helm-%s-windows-amd64.zip', version);
|
||||
return util.format(
|
||||
'https://gitea.icodef.com/actions/binary-repo/raw/branch/main/helm/helm-%s-windows-amd64.zip',
|
||||
version
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadHelm(version: string): Promise<string> {
|
||||
let cachedToolpath = toolCache.find(helmToolName, version);
|
||||
let cachedToolpath = toolCache.find(helmToolName, version)
|
||||
if (!cachedToolpath) {
|
||||
let helmDownloadPath;
|
||||
let helmDownloadPath
|
||||
try {
|
||||
helmDownloadPath = await toolCache.downloadTool(getHelmDownloadURL(version));
|
||||
helmDownloadPath = await toolCache.downloadTool(
|
||||
getHelmDownloadURL(version)
|
||||
)
|
||||
} catch (exception) {
|
||||
throw new Error(util.format("Failed to download Helm from location", getHelmDownloadURL(version)));
|
||||
throw new Error(
|
||||
`Failed to download Helm from location ${getHelmDownloadURL(
|
||||
version
|
||||
)}`
|
||||
)
|
||||
}
|
||||
|
||||
fs.chmodSync(helmDownloadPath, '777');
|
||||
const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath);
|
||||
cachedToolpath = await toolCache.cacheDir(unzipedHelmPath, helmToolName, version);
|
||||
fs.chmodSync(helmDownloadPath, '777')
|
||||
const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath)
|
||||
cachedToolpath = await toolCache.cacheDir(
|
||||
unzipedHelmPath,
|
||||
helmToolName,
|
||||
version
|
||||
)
|
||||
}
|
||||
|
||||
const helmpath = findHelm(cachedToolpath);
|
||||
const helmpath = findHelm(cachedToolpath)
|
||||
if (!helmpath) {
|
||||
throw new Error(util.format("Helm executable not found in path", cachedToolpath));
|
||||
throw new Error(
|
||||
util.format('Helm executable not found in path', cachedToolpath)
|
||||
)
|
||||
}
|
||||
|
||||
fs.chmodSync(helmpath, '777');
|
||||
return helmpath;
|
||||
fs.chmodSync(helmpath, '777')
|
||||
return helmpath
|
||||
}
|
||||
|
||||
export function findHelm(rootFolder: string): string {
|
||||
fs.chmodSync(rootFolder, '777');
|
||||
var filelist: string[] = [];
|
||||
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension());
|
||||
fs.chmodSync(rootFolder, '777')
|
||||
var filelist: string[] = []
|
||||
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension())
|
||||
if (!filelist || filelist.length == 0) {
|
||||
throw new Error(util.format("Helm executable not found in path", rootFolder));
|
||||
}
|
||||
else {
|
||||
return filelist[0];
|
||||
throw new Error(
|
||||
util.format('Helm executable not found in path', rootFolder)
|
||||
)
|
||||
} else {
|
||||
return filelist[0]
|
||||
}
|
||||
}
|
||||
|
||||
export var walkSync = function (dir, filelist, fileToFind) {
|
||||
var files = fs.readdirSync(dir);
|
||||
filelist = filelist || [];
|
||||
var files = fs.readdirSync(dir)
|
||||
filelist = filelist || []
|
||||
files.forEach(function (file) {
|
||||
if (fs.statSync(path.join(dir, file)).isDirectory()) {
|
||||
filelist = walkSync(path.join(dir, file), filelist, fileToFind);
|
||||
}
|
||||
else {
|
||||
core.debug(file);
|
||||
filelist = walkSync(path.join(dir, file), filelist, fileToFind)
|
||||
} else {
|
||||
core.debug(file)
|
||||
if (file == fileToFind) {
|
||||
filelist.push(path.join(dir, file));
|
||||
filelist.push(path.join(dir, file))
|
||||
}
|
||||
}
|
||||
});
|
||||
return filelist;
|
||||
};
|
||||
})
|
||||
return filelist
|
||||
}
|
||||
|
||||
run().catch(core.setFailed);
|
||||
run().catch(core.setFailed)
|
||||
|
@ -2,8 +2,8 @@
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
|
||||
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
@ -11,8 +11,8 @@
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"outDir": "./lib" /* Redirect output structure to the directory. */,
|
||||
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
//"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
|
Reference in New Issue
Block a user