Vidya reddy prettier (#75)

* upgraded to Node16

* Enforce Prettier

* code fix

* Update package-lock.json

resolved the conflicts.

* executed prettier

Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>
This commit is contained in:
Vidya Reddy
2022-06-27 15:27:44 -07:00
committed by GitHub
parent a14110f6e6
commit 7f0153c54c
20 changed files with 11874 additions and 11855 deletions

View File

@ -4,7 +4,4 @@ about: Create a report to help us improve
title: '' title: ''
labels: need-to-triage labels: need-to-triage
assignees: '' assignees: ''
--- ---

View File

@ -3,7 +3,7 @@ name: setting-default-labels
# Controls when the action will run. # Controls when the action will run.
on: on:
schedule: 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 # A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs: jobs:
@ -17,19 +17,19 @@ jobs:
name: Setting issue as idle name: Setting issue as idle
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue is idle because it has been open for 14 days with no activity." stale-issue-message: 'This issue is idle because it has been open for 14 days with no activity.'
stale-issue-label: "idle" stale-issue-label: 'idle'
days-before-stale: 14 days-before-stale: 14
days-before-close: -1 days-before-close: -1
operations-per-run: 100 operations-per-run: 100
exempt-issue-labels: "backlog" exempt-issue-labels: 'backlog'
- uses: actions/stale@v3 - uses: actions/stale@v3
name: Setting PR as idle name: Setting PR as idle
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: "This PR is idle because it has been open for 14 days with no activity." stale-pr-message: 'This PR is idle because it has been open for 14 days with no activity.'
stale-pr-label: "idle" stale-pr-label: 'idle'
days-before-stale: 14 days-before-stale: 14
days-before-close: -1 days-before-close: -1
operations-per-run: 100 operations-per-run: 100

View File

@ -1,17 +1,17 @@
name: "Trigger Integration tests" name: 'Trigger Integration tests'
on: on:
pull_request: pull_request:
branches: branches:
- main - main
- "releases/*" - 'releases/*'
jobs: jobs:
trigger-integration-tests: trigger-integration-tests:
name: Trigger Integration tests name: Trigger Integration tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
HELM_3_8_0: "v3.8.0" HELM_3_8_0: 'v3.8.0'
HELM_3_7_2: "v3.7.2" HELM_3_7_2: 'v3.7.2'
HELM_NO_V: "3.5.0" HELM_NO_V: '3.5.0'
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

18
.github/workflows/prettify-code.yml vendored Normal file
View 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 .

View File

@ -4,7 +4,7 @@ on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
release: release:
description: "Define release version (ex: v1, v2, v3)" description: 'Define release version (ex: v1, v2, v3)'
required: true required: true
jobs: jobs:

View File

@ -1,13 +1,13 @@
name: "Run unit tests." name: 'Run unit tests.'
on: # rebuild any PRs and main branch changes on: # rebuild any PRs and main branch changes
pull_request: pull_request:
branches: branches:
- main - main
- "releases/*" - 'releases/*'
push: push:
branches: branches:
- main - main
- "releases/*" - 'releases/*'
jobs: jobs:
build: # make sure build/ci works properly build: # make sure build/ci works properly

4
.prettierignore Normal file
View File

@ -0,0 +1,4 @@
# dependencies
/node_modules
coverage
/lib

8
.prettierrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"trailingComma": "none",
"bracketSpacing": false,
"semi": false,
"tabWidth": 3,
"singleQuote": true,
"printWidth": 80
}

View File

@ -1,5 +1,7 @@
# Setup Helm # Setup Helm
Install a specific version of helm binary on the runner. 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 and v3 of this action only supports Helm3.

View File

@ -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/). 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 ## 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: 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.

View File

@ -1,15 +1,15 @@
name: "Helm tool installer" name: 'Helm tool installer'
description: "Install a specific version of helm binary. Acceptable values are latest or any semantic version string like 1.15.0" description: 'Install a specific version of helm binary. Acceptable values are latest or any semantic version string like 1.15.0'
inputs: inputs:
version: version:
description: "Version of helm" description: 'Version of helm'
required: true required: true
default: "latest" default: 'latest'
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: 'node16'
main: "lib/index.js" main: 'lib/index.js'

View File

@ -8,11 +8,11 @@ module.exports = {
}, },
verbose: true, verbose: true,
coverageThreshold: { coverageThreshold: {
"global": { global: {
"branches": 0, branches: 0,
"functions": 14, functions: 14,
"lines": 27, lines: 27,
"statements": 27 statements: 27
} }
} }
} }

33
package-lock.json generated
View File

@ -10812,38 +10812,21 @@
} }
}, },
"ts-jest": { "ts-jest": {
"version": "26.5.6", "version": "25.5.1",
"resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-26.5.6.tgz", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.5.1.tgz",
"integrity": "sha512-rua+rCP8DxpA8b4DQD/6X2HQS8Zy/xzViVYfEs2OQu68tkCuKLV0Md8pmX55+W24uRIyAsf/BajRfxOs+R2MKA==", "integrity": "sha512-kHEUlZMK8fn8vkxDjwbHlxXRB9dHYpyzqKIGDNxbzs+Rz+ssNDSDNusEK8Fk/sDd4xE6iKoQLfFkFVaskmTJyw==",
"dev": true, "dev": true,
"requires": { "requires": {
"bs-logger": "0.x", "bs-logger": "0.x",
"buffer-from": "1.x", "buffer-from": "1.x",
"fast-json-stable-stringify": "2.x", "fast-json-stable-stringify": "2.x",
"jest-util": "^26.1.0",
"json5": "2.x", "json5": "2.x",
"lodash": "4.x", "lodash.memoize": "4.x",
"make-error": "1.x", "make-error": "1.x",
"mkdirp": "1.x", "micromatch": "4.x",
"semver": "7.x", "mkdirp": "0.x",
"yargs-parser": "20.x" "semver": "6.x",
}, "yargs-parser": "18.x"
"dependencies": {
"semver": {
"version": "7.3.7",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz",
"integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
},
"yargs-parser": {
"version": "20.2.9",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==",
"dev": true
}
} }
}, },
"tunnel": { "tunnel": {

View File

@ -17,7 +17,9 @@
"scripts": { "scripts": {
"build": "ncc build src/run.ts -o lib", "build": "ncc build src/run.ts -o lib",
"test": "jest", "test": "jest",
"test-coverage": "jest --coverage" "test-coverage": "jest --coverage",
"format": "prettier --write .",
"format-check": "prettier --check ."
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.0", "@types/jest": "^26.0.0",

View File

@ -1,268 +1,273 @@
import * as run from "./run"; import * as run from './run'
import * as os from "os"; import * as os from 'os'
import * as toolCache from "@actions/tool-cache"; import * as toolCache from '@actions/tool-cache'
import * as fs from "fs"; import * as fs from 'fs'
import * as path from "path"; import * as path from 'path'
import * as core from "@actions/core"; import * as core from '@actions/core'
describe("run.ts", () => { describe('run.ts', () => {
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, 'type').mockReturnValue('Windows_NT')
expect(run.getExecutableExtension()).toBe(".exe"); expect(run.getExecutableExtension()).toBe('.exe')
expect(os.type).toBeCalled(); expect(os.type).toBeCalled()
}); })
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, 'type').mockReturnValue('Darwin')
expect(run.getExecutableExtension()).toBe(""); expect(run.getExecutableExtension()).toBe('')
expect(os.type).toBeCalled(); expect(os.type).toBeCalled()
}); })
test("getHelmDownloadURL() - return the URL to download helm for Linux", () => { test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
jest.spyOn(os, "type").mockReturnValue("Linux"); jest.spyOn(os, 'type').mockReturnValue('Linux')
jest.spyOn(os, "arch").mockReturnValueOnce("unknown"); jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
const kubectlLinuxUrl = "https://get.helm.sh/helm-v3.8.0-linux-amd64.zip"; const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.8.0-linux-amd64.zip'
expect(run.getHelmDownloadURL("v3.8.0")).toBe(kubectlLinuxUrl); expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl)
expect(os.type).toBeCalled(); expect(os.type).toBeCalled()
expect(os.arch).toBeCalled(); expect(os.arch).toBeCalled()
// arm64 // arm64
jest.spyOn(os, "type").mockReturnValue("Linux"); jest.spyOn(os, 'type').mockReturnValue('Linux')
jest.spyOn(os, "arch").mockReturnValueOnce("arm64"); jest.spyOn(os, 'arch').mockReturnValueOnce('arm64')
const kubectlLinuxArm64Url = const kubectlLinuxArm64Url =
"https://get.helm.sh/helm-v3.8.0-linux-arm64.zip"; 'https://get.helm.sh/helm-v3.8.0-linux-arm64.zip'
expect(run.getHelmDownloadURL("v3.8.0")).toBe(kubectlLinuxArm64Url); expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxArm64Url)
expect(os.type).toBeCalled(); expect(os.type).toBeCalled()
expect(os.arch).toBeCalled(); expect(os.arch).toBeCalled()
}); })
test("getHelmDownloadURL() - return the URL to download helm for Darwin", () => { test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
jest.spyOn(os, "type").mockReturnValue("Darwin"); jest.spyOn(os, 'type').mockReturnValue('Darwin')
jest.spyOn(os, "arch").mockReturnValueOnce("unknown"); jest.spyOn(os, 'arch').mockReturnValueOnce('unknown')
const kubectlDarwinUrl = "https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip"; const kubectlDarwinUrl =
'https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip'
expect(run.getHelmDownloadURL("v3.8.0")).toBe(kubectlDarwinUrl); expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl)
expect(os.type).toBeCalled(); expect(os.type).toBeCalled()
expect(os.arch).toBeCalled(); expect(os.arch).toBeCalled()
// arm64 // arm64
jest.spyOn(os, "type").mockReturnValue("Darwin"); jest.spyOn(os, 'type').mockReturnValue('Darwin')
jest.spyOn(os, "arch").mockReturnValueOnce("arm64"); jest.spyOn(os, 'arch').mockReturnValueOnce('arm64')
const kubectlDarwinArm64Url = const kubectlDarwinArm64Url =
"https://get.helm.sh/helm-v3.8.0-darwin-arm64.zip"; 'https://get.helm.sh/helm-v3.8.0-darwin-arm64.zip'
expect(run.getHelmDownloadURL("v3.8.0")).toBe(kubectlDarwinArm64Url); expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinArm64Url)
expect(os.type).toBeCalled(); expect(os.type).toBeCalled()
expect(os.arch).toBeCalled(); expect(os.arch).toBeCalled()
}); })
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", () => { test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
jest.spyOn(os, "type").mockReturnValue("Windows_NT"); jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
const kubectlWindowsUrl = const kubectlWindowsUrl =
"https://get.helm.sh/helm-v3.8.0-windows-amd64.zip"; 'https://get.helm.sh/helm-v3.8.0-windows-amd64.zip'
expect(run.getHelmDownloadURL("v3.8.0")).toBe(kubectlWindowsUrl); expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlWindowsUrl)
expect(os.type).toBeCalled(); expect(os.type).toBeCalled()
}); })
test("getLatestHelmVersion() - return the latest version of HELM", async () => { test('getLatestHelmVersion() - return the latest version of HELM', async () => {
try { try {
expect(await run.getLatestHelmVersion()).toBe("v3.8.0"); expect(await run.getLatestHelmVersion()).toBe('v3.8.0')
} catch (e) { } catch (e) {
return 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,
"file2" as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent,
"folder1" as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent,
"folder2" as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent
]; ]
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,
"file12" as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent
]; ]
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,
"file22" as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent
]; ]
}); })
jest.spyOn(core, "debug").mockImplementation(); jest.spyOn(core, 'debug').mockImplementation()
jest.spyOn(fs, "statSync").mockImplementation((file) => { jest.spyOn(fs, 'statSync').mockImplementation((file) => {
const isDirectory = const isDirectory =
(file as string).toLowerCase().indexOf("file") == -1 ? true : false; (file as string).toLowerCase().indexOf('file') == -1 ? true : false
return { isDirectory: () => isDirectory } as fs.Stats; return {isDirectory: () => isDirectory} as fs.Stats
}); })
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).toBeCalledTimes(3)
expect(fs.statSync).toBeCalledTimes(8); expect(fs.statSync).toBeCalledTimes(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,
"file2" as unknown as fs.Dirent, 'file2' as unknown as fs.Dirent,
"folder1" as unknown as fs.Dirent, 'folder1' as unknown as fs.Dirent,
"folder2" as unknown as fs.Dirent, 'folder2' as unknown as fs.Dirent
]; ]
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,
"file12" as unknown as fs.Dirent, 'file12' as unknown as fs.Dirent
]; ]
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,
"file22" as unknown as fs.Dirent, 'file22' as unknown as fs.Dirent
]; ]
}); })
jest.spyOn(core, "debug").mockImplementation(); jest.spyOn(core, 'debug').mockImplementation()
jest.spyOn(fs, "statSync").mockImplementation((file) => { jest.spyOn(fs, 'statSync').mockImplementation((file) => {
const isDirectory = const isDirectory =
(file as string).toLowerCase().indexOf("file") == -1 ? true : false; (file as string).toLowerCase().indexOf('file') == -1 ? true : false
return { isDirectory: () => isDirectory } as fs.Stats; return {isDirectory: () => isDirectory} as fs.Stats
}); })
expect(run.walkSync("mainFolder", null, "helm.exe")).toEqual([]); expect(run.walkSync('mainFolder', null, 'helm.exe')).toEqual([])
expect(fs.readdirSync).toBeCalledTimes(3); expect(fs.readdirSync).toBeCalledTimes(3)
expect(fs.statSync).toBeCalledTimes(8); expect(fs.statSync).toBeCalledTimes(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]
}); })
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, 'type').mockReturnValue('Windows_NT')
expect(run.findHelm("mainFolder")).toBe( expect(run.findHelm('mainFolder')).toBe(
path.join("mainFolder", "helm.exe") path.join('mainFolder', 'helm.exe')
); )
}); })
test("findHelm() - throw error if executable not found", () => { test('findHelm() - throw error if executable not found', () => {
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 []
}); })
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, 'type').mockReturnValue('Windows_NT')
expect(() => run.findHelm("mainFolder")).toThrow( expect(() => run.findHelm('mainFolder')).toThrow(
"Helm executable not found in path mainFolder" 'Helm executable not found in path mainFolder'
); )
}); })
test("downloadHelm() - download helm and return path to it", async () => { test('downloadHelm() - download helm and return path to it', async () => {
jest.spyOn(toolCache, "find").mockReturnValue(""); jest.spyOn(toolCache, 'find').mockReturnValue('')
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, 'type').mockReturnValue('Windows_NT')
jest.spyOn(fs, "chmodSync").mockImplementation(() => {}); jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
jest.spyOn(toolCache, "extractZip").mockResolvedValue("pathToUnzippedHelm");
jest.spyOn(toolCache, "cacheDir").mockResolvedValue("pathToCachedDir");
jest jest
.spyOn(fs, "readdirSync") .spyOn(toolCache, 'extractZip')
.mockImplementation((file, _) => ["helm.exe" as unknown as fs.Dirent]); .mockResolvedValue('pathToUnzippedHelm')
jest.spyOn(fs, "statSync").mockImplementation((file) => { 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 = 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('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).toBeCalledWith('helm', 'v4.0.0')
expect(toolCache.downloadTool).toBeCalledWith( expect(toolCache.downloadTool).toBeCalledWith(
"https://get.helm.sh/helm-v4.0.0-windows-amd64.zip" 'https://get.helm.sh/helm-v4.0.0-windows-amd64.zip'
); )
expect(fs.chmodSync).toBeCalledWith("pathToTool", "777"); expect(fs.chmodSync).toBeCalledWith('pathToTool', '777')
expect(toolCache.extractZip).toBeCalledWith("pathToTool"); expect(toolCache.extractZip).toBeCalledWith('pathToTool')
expect(fs.chmodSync).toBeCalledWith( expect(fs.chmodSync).toBeCalledWith(
path.join("pathToCachedDir", "helm.exe"), path.join('pathToCachedDir', 'helm.exe'),
"777" '777'
); )
}); })
test("downloadHelm() - throw error if unable to download", async () => { test('downloadHelm() - throw error if unable to download', async () => {
jest.spyOn(toolCache, "find").mockReturnValue(""); jest.spyOn(toolCache, 'find').mockReturnValue('')
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, 'type').mockReturnValue('Windows_NT')
await expect(run.downloadHelm("v3.2.1")).rejects.toThrow( 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" '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.find).toBeCalledWith('helm', 'v3.2.1')
expect(toolCache.downloadTool).toBeCalledWith( expect(toolCache.downloadTool).toBeCalledWith(
"https://get.helm.sh/helm-v3.2.1-windows-amd64.zip" 'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
); )
}); })
test("downloadHelm() - return path to helm tool with same version from toolCache", async () => { test('downloadHelm() - return path to helm tool with same version from toolCache', async () => {
jest.spyOn(toolCache, "find").mockReturnValue("pathToCachedDir"); jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedDir')
jest.spyOn(fs, "chmodSync").mockImplementation(() => {}); jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
expect(await run.downloadHelm("v3.2.1")).toBe( expect(await run.downloadHelm('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).toBeCalledWith('helm', 'v3.2.1')
expect(fs.chmodSync).toBeCalledWith( expect(fs.chmodSync).toBeCalledWith(
path.join("pathToCachedDir", "helm.exe"), path.join('pathToCachedDir', 'helm.exe'),
"777" '777'
); )
}); })
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(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(fs, "chmodSync").mockImplementation(); jest.spyOn(fs, 'chmodSync').mockImplementation()
jest.spyOn(toolCache, "extractZip").mockResolvedValue("pathToUnzippedHelm"); jest
jest.spyOn(toolCache, "cacheDir").mockResolvedValue("pathToCachedDir"); .spyOn(toolCache, 'extractZip')
jest.spyOn(fs, "readdirSync").mockImplementation((file, _) => []); .mockResolvedValue('pathToUnzippedHelm')
jest.spyOn(fs, "statSync").mockImplementation((file) => { jest.spyOn(toolCache, 'cacheDir').mockResolvedValue('pathToCachedDir')
jest.spyOn(fs, 'readdirSync').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
}); })
await expect(run.downloadHelm("v3.2.1")).rejects.toThrow( await expect(run.downloadHelm('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).toBeCalledWith('helm', 'v3.2.1')
expect(toolCache.downloadTool).toBeCalledWith( expect(toolCache.downloadTool).toBeCalledWith(
"https://get.helm.sh/helm-v3.2.1-windows-amd64.zip" 'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
); )
expect(fs.chmodSync).toBeCalledWith("pathToTool", "777"); expect(fs.chmodSync).toBeCalledWith('pathToTool', '777')
expect(toolCache.extractZip).toBeCalledWith("pathToTool"); expect(toolCache.extractZip).toBeCalledWith('pathToTool')
}); })
}); })

View File

@ -2,34 +2,34 @@
// 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'
import * as path from "path"; import * as path from 'path'
import * as util from "util"; import * as util from 'util'
import * as fs from "fs"; import * as fs from 'fs'
import * as toolCache from "@actions/tool-cache"; 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.8.0'
const helmAllReleasesUrl = "https://api.github.com/repos/helm/helm/releases"; 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') {
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)); core.debug(util.format('Downloading %s', version))
let cachedPath = await downloadHelm(version); let cachedPath = await downloadHelm(version)
try { try {
if (!process.env["PATH"].startsWith(path.dirname(cachedPath))) { 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 //do nothing, set as output variable
@ -37,158 +37,158 @@ export async function run() {
console.log( console.log(
`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 //Returns version with proper v before it
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. // 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 // 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); const helmJSONPath: string = await toolCache.downloadTool(helmAllReleasesUrl)
try { try {
const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, "utf-8")); const helmJSON = JSON.parse(fs.readFileSync(helmJSONPath, 'utf-8'))
for (let i in helmJSON) { for (let i in helmJSON) {
if (isValidVersion(helmJSON[i].tag_name)) { if (isValidVersion(helmJSON[i].tag_name)) {
return helmJSON[i].tag_name; return helmJSON[i].tag_name
} }
} }
} catch (err) { } catch (err) {
core.warning( core.warning(
util.format( util.format(
"Error while fetching the latest Helm release. Error: %s. Using default Helm version %s", 'Error while fetching the latest Helm release. Error: %s. Using default Helm version %s',
err.toString(), err.toString(),
stableHelmVersion stableHelmVersion
) )
); )
return stableHelmVersion; return stableHelmVersion
} }
return stableHelmVersion; return stableHelmVersion
} }
// isValidVersion checks if verison is a stable release // isValidVersion checks if verison is a stable release
function isValidVersion(version: string): boolean { function isValidVersion(version: string): boolean {
return version.indexOf("rc") == -1; return version.indexOf('rc') == -1
} }
export function getExecutableExtension(): string { export function getExecutableExtension(): string {
if (os.type().match(/^Win/)) { if (os.type().match(/^Win/)) {
return ".exe"; return '.exe'
} }
return ""; return ''
} }
const LINUX = "Linux"; const LINUX = 'Linux'
const MAC_OS = "Darwin"; const MAC_OS = 'Darwin'
const WINDOWS = "Windows_NT"; const WINDOWS = 'Windows_NT'
const ARM64 = "arm64"; const ARM64 = 'arm64'
export function getHelmDownloadURL(version: string): string { export function getHelmDownloadURL(version: string): string {
const arch = os.arch(); const arch = os.arch()
const operatingSystem = os.type(); const operatingSystem = os.type()
switch (true) { switch (true) {
case operatingSystem == LINUX && arch == ARM64: case operatingSystem == LINUX && arch == ARM64:
return util.format( return util.format(
"https://get.helm.sh/helm-%s-linux-arm64.zip", 'https://get.helm.sh/helm-%s-linux-arm64.zip',
version version
); )
case operatingSystem == LINUX: case operatingSystem == LINUX:
return util.format( return util.format(
"https://get.helm.sh/helm-%s-linux-amd64.zip", 'https://get.helm.sh/helm-%s-linux-amd64.zip',
version version
); )
case operatingSystem == MAC_OS && arch == ARM64: case operatingSystem == MAC_OS && arch == ARM64:
return util.format( return util.format(
"https://get.helm.sh/helm-%s-darwin-arm64.zip", 'https://get.helm.sh/helm-%s-darwin-arm64.zip',
version version
); )
case operatingSystem == MAC_OS: case operatingSystem == MAC_OS:
return util.format( return util.format(
"https://get.helm.sh/helm-%s-darwin-amd64.zip", 'https://get.helm.sh/helm-%s-darwin-amd64.zip',
version version
); )
case operatingSystem == WINDOWS: case operatingSystem == WINDOWS:
default: default:
return util.format( return util.format(
"https://get.helm.sh/helm-%s-windows-amd64.zip", 'https://get.helm.sh/helm-%s-windows-amd64.zip',
version version
); )
} }
} }
export async function downloadHelm(version: string): Promise<string> { export async function downloadHelm(version: string): Promise<string> {
let cachedToolpath = toolCache.find(helmToolName, version); let cachedToolpath = toolCache.find(helmToolName, version)
if (!cachedToolpath) { if (!cachedToolpath) {
let helmDownloadPath; let helmDownloadPath
try { try {
helmDownloadPath = await toolCache.downloadTool( helmDownloadPath = await toolCache.downloadTool(
getHelmDownloadURL(version) getHelmDownloadURL(version)
); )
} catch (exception) { } catch (exception) {
throw new Error( throw new Error(
util.format( util.format(
"Failed to download Helm from location", 'Failed to download Helm from location',
getHelmDownloadURL(version) getHelmDownloadURL(version)
) )
); )
} }
fs.chmodSync(helmDownloadPath, "777"); fs.chmodSync(helmDownloadPath, '777')
const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath); const unzipedHelmPath = await toolCache.extractZip(helmDownloadPath)
cachedToolpath = await toolCache.cacheDir( cachedToolpath = await toolCache.cacheDir(
unzipedHelmPath, unzipedHelmPath,
helmToolName, helmToolName,
version version
); )
} }
const helmpath = findHelm(cachedToolpath); const helmpath = findHelm(cachedToolpath)
if (!helmpath) { if (!helmpath) {
throw new Error( throw new Error(
util.format("Helm executable not found in path", cachedToolpath) util.format('Helm executable not found in path', cachedToolpath)
); )
} }
fs.chmodSync(helmpath, "777"); fs.chmodSync(helmpath, '777')
return helmpath; return helmpath
} }
export function findHelm(rootFolder: string): string { export function findHelm(rootFolder: string): string {
fs.chmodSync(rootFolder, "777"); fs.chmodSync(rootFolder, '777')
var filelist: string[] = []; var filelist: string[] = []
walkSync(rootFolder, filelist, helmToolName + getExecutableExtension()); walkSync(rootFolder, filelist, helmToolName + getExecutableExtension())
if (!filelist || filelist.length == 0) { if (!filelist || filelist.length == 0) {
throw new Error( throw new Error(
util.format("Helm executable not found in path", rootFolder) util.format('Helm executable not found in path', rootFolder)
); )
} else { } else {
return filelist[0]; return filelist[0]
} }
} }
export var walkSync = function (dir, filelist, fileToFind) { export var walkSync = function (dir, filelist, fileToFind) {
var files = fs.readdirSync(dir); var files = fs.readdirSync(dir)
filelist = filelist || []; filelist = filelist || []
files.forEach(function (file) { files.forEach(function (file) {
if (fs.statSync(path.join(dir, file)).isDirectory()) { if (fs.statSync(path.join(dir, file)).isDirectory()) {
filelist = walkSync(path.join(dir, file), filelist, fileToFind); filelist = walkSync(path.join(dir, file), filelist, fileToFind)
} else { } else {
core.debug(file); core.debug(file)
if (file == fileToFind) { 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)

View File

@ -2,8 +2,8 @@
"compilerOptions": { "compilerOptions": {
/* Basic Options */ /* Basic Options */
// "incremental": true, /* Enable incremental compilation */ // "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' 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'. */ "module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
// "allowJs": true, /* Allow javascript files to be compiled. */ // "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */ // "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ // "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. */ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */ // "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */ // "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */ "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. */ "rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "composite": true, /* Enable project compilation */ // "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */ // "removeComments": true, /* Do not emit comments to output. */
@ -23,7 +23,7 @@
/* Strict Type-Checking Options */ /* Strict Type-Checking Options */
//"strict": true, /* Enable all 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. */ // "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */