4 Commits
vv4 ... v3

Author SHA1 Message Date
github-actions[bot]
901a10e89e v3 new release (#78)
* Bump ansi-regex from 5.0.0 to 5.0.1 (#56)

Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 5.0.0 to 5.0.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](https://github.com/chalk/ansi-regex/compare/v5.0.0...v5.0.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Vidya reddy prettier (#58)

* upgraded to Node16

* Enforce Prettier

* code fix

* jest version change and prettify code

Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>

* Upgraded the ncc version (#61)

Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>

* Update README example to v3 (#60)

* Bump @actions/core from 1.9.0 to 1.9.1 (#63)

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add the issue report and feature request form (#64)

* syntax error fixes (#66)

* added support message (#67)

* Bump @actions/core (#68)

to address https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

* Bump decode-uri-component from 0.2.0 to 0.2.2 (#73)

Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* change uri (#77)

* Add node modules and compiled JavaScript from main

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Vidya Reddy <59590642+Vidya2606@users.noreply.github.com>
Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>
Co-authored-by: Oliver King <olivermerkleyking@gmail.com>
Co-authored-by: Asa Gayle <azmatch.gayle@gmail.com>
Co-authored-by: Sumner Warren <sumner.warren@gmail.com>
Co-authored-by: Oliver King <oking3@uncc.edu>
2023-01-09 13:58:02 -05:00
github-actions[bot]
e1be5e75ed v3 new release (#72)
* Bump ansi-regex from 5.0.0 to 5.0.1 (#56)

Bumps [ansi-regex](https://github.com/chalk/ansi-regex) from 5.0.0 to 5.0.1.
- [Release notes](https://github.com/chalk/ansi-regex/releases)
- [Commits](https://github.com/chalk/ansi-regex/compare/v5.0.0...v5.0.1)

---
updated-dependencies:
- dependency-name: ansi-regex
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Vidya reddy prettier (#58)

* upgraded to Node16

* Enforce Prettier

* code fix

* jest version change and prettify code

Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>

* Upgraded the ncc version (#61)

Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>

* Update README example to v3 (#60)

* Bump @actions/core from 1.9.0 to 1.9.1 (#63)

Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Add the issue report and feature request form (#64)

* syntax error fixes (#66)

* added support message (#67)

* Bump @actions/core (#68)

to address https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

* Add node modules and compiled JavaScript from main

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Vidya Reddy <59590642+Vidya2606@users.noreply.github.com>
Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com>
Co-authored-by: Oliver King <olivermerkleyking@gmail.com>
Co-authored-by: Asa Gayle <azmatch.gayle@gmail.com>
Co-authored-by: Sumner Warren <sumner.warren@gmail.com>
Co-authored-by: Oliver King <oking3@uncc.edu>
2022-12-05 13:21:32 -05:00
Oliver King
b196533533 Delete node_modules directory (#71) 2022-12-05 12:02:40 -05:00
github-actions[bot]
7f7e5ba5ea Add node modules and compiled JavaScript from main (#57)
Co-authored-by: Oliver King <oking3@uncc.edu>
2022-06-21 12:18:30 -04:00
19 changed files with 8488 additions and 3131 deletions

View File

@@ -1,18 +0,0 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
groups:
actions:
patterns:
- '*'
- package-ecosystem: github-actions
directory: .github/workflows
schedule:
interval: weekly
groups:
actions:
patterns:
- '*'

View File

@@ -1,91 +0,0 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: 'CodeQL Advanced'
on:
push:
branches: ['main']
pull_request:
branches: ['main']
schedule:
- cron: '15 9 * * 0'
jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write
# required to fetch internal or private CodeQL packs
packages: read
# only required for workflows in private repositories
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: javascript-typescript
build-mode: none
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@17a820bf2e43b47be2c72b39cc905417bc1ab6d0 # v3.28.6
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@17a820bf2e43b47be2c72b39cc905417bc1ab6d0 # v3.28.6
with:
category: '/language:${{matrix.language}}'

View File

@@ -8,7 +8,7 @@ jobs:
label-issues: label-issues:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0 - uses: actions/stale@v3
name: Setting issue as idle name: Setting issue as idle
with: with:
repo-token: ${{ secrets.GITHUB_TOKEN }} repo-token: ${{ secrets.GITHUB_TOKEN }}
@@ -19,7 +19,7 @@ jobs:
operations-per-run: 100 operations-per-run: 100
exempt-issue-labels: 'backlog' exempt-issue-labels: 'backlog'
- uses: actions/stale@5bef64f19d7facfb25b37b414482c7164d639639 # v9.1.0 - 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 }}

View File

@@ -17,7 +17,7 @@ jobs:
KUBECONFIG: /home/runner/.kube/config KUBECONFIG: /home/runner/.kube/config
PR_BASE_REF: ${{ github.event.pull_request.base.ref }} PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@v2
name: Checkout from PR branch name: Checkout from PR branch
- id: action-npm-build - id: action-npm-build
@@ -29,7 +29,7 @@ jobs:
npm run build npm run build
fi fi
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0 - uses: actions/setup-python@v2
name: Install Python name: Install Python
with: with:
python-version: '3.x' python-version: '3.x'
@@ -37,18 +37,13 @@ jobs:
- name: Install requests library - name: Install requests library
run: pip install requests run: pip install requests
- name: Setup kubectl latest
uses: ./
with:
version: 'latest'
- name: Validate kubectl setup - name: Validate kubectl setup
run: python test/validate-kubectl.py latest run: python test/validate-kubectl.py latest
- name: Setup kubectl old version - name: Setup kubectl
uses: ./ uses: ./
with: with:
version: 'v1.15.1' version: 'v1.15.1'
- name: Validate kubectl setup old version - name: Validate kubectl setup
run: python test/validate-kubectl.py 'v1.15.1' run: python test/validate-kubectl.py 'v1.15.1'

View File

@@ -10,16 +10,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 uses: actions/checkout@v2
- name: Setup Node.js - name: Enforce Prettier
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0 uses: actionsx/prettier@v2
with: with:
node-version: 'lts/*' args: --check .
cache: 'npm'
- name: Install Dependencies
run: npm ci
- name: Run Prettier Check
run: npx prettier --check .

View File

@@ -1,18 +1,14 @@
name: Release Project name: Create release PR
on: on:
push:
branches:
- main
paths:
- CHANGELOG.md
workflow_dispatch: workflow_dispatch:
inputs:
release:
description: 'Define release version (ex: v1, v2, v3)'
required: true
jobs: jobs:
release: release-pr:
permissions: uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main
actions: read
contents: write
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@v1
with: with:
changelogPath: ./CHANGELOG.md release: ${{ github.event.inputs.release }}

10
.github/workflows/tag-and-draft.yml vendored Normal file
View 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

View File

@@ -13,7 +13,7 @@ jobs:
build: # make sure build/ci works properly build: # make sure build/ci works properly
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - uses: actions/checkout@v1
- name: Build and run L0 tests. - name: Build and run L0 tests.
run: | run: |

View File

@@ -1,7 +0,0 @@
# Changelog
## [v4.0.0] - 2024-01-30
### Changed
- #90 Migrate to node 20 as node 16 is deprecated

View File

@@ -5,7 +5,7 @@
Acceptable values are latest or any semantic version string like `v1.15.0`. Use this action in workflow to define which version of kubectl will be used. Acceptable values are latest or any semantic version string like `v1.15.0`. Use this action in workflow to define which version of kubectl will be used.
```yaml ```yaml
- uses: azure/setup-kubectl@v4 - uses: azure/setup-kubectl@v3
with: with:
version: '<version>' # default is latest stable version: '<version>' # default is latest stable
id: install id: install

View File

@@ -11,5 +11,5 @@ outputs:
branding: branding:
color: 'blue' color: 'blue'
runs: runs:
using: 'node20' using: 'node16'
main: 'lib/index.js' main: 'lib/index.js'

File diff suppressed because it is too large Load Diff

9293
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@
"private": true, "private": true,
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
"build": "npm i ncc && npx ncc build src/index.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": "prettier --write .",
@@ -18,18 +18,17 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.11.1", "@actions/core": "^1.10.0",
"@actions/exec": "^1.0.0", "@actions/exec": "^1.0.0",
"@actions/tool-cache": "^2.0.2", "@actions/tool-cache": "^1.0.0"
"ncc": "^0.3.6"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.14", "@types/jest": "^26.0.0",
"@types/node": "^22.10.10", "@types/node": "^12.0.4",
"@vercel/ncc": "^0.38.3", "@vercel/ncc": "^0.34.0",
"jest": "^29.7.0", "jest": "^26.0.1",
"prettier": "3.4.2", "prettier": "2.7.1",
"ts-jest": "^29.2.5", "ts-jest": "^26.0.0",
"typescript": "5.7.3" "typescript": "3.9.2"
} }
} }

View File

@@ -1,4 +0,0 @@
import {run} from './run'
import * as core from '@actions/core'
run().catch(core.setFailed)

View File

@@ -14,14 +14,18 @@ import * as util from 'util'
describe('Testing all functions in run file.', () => { describe('Testing all functions in run file.', () => {
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(getExecutableExtension()).toBe('.exe') expect(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(getExecutableExtension()).toBe('') expect(getExecutableExtension()).toBe('')
expect(os.type).toBeCalled() expect(os.type).toBeCalled()
}) })
test.each([ test.each([
['arm', 'arm'], ['arm', 'arm'],
['arm64', 'arm64'], ['arm64', 'arm64'],
@@ -30,10 +34,12 @@ describe('Testing all functions in run file.', () => {
'getKubectlArch() - return on %s os arch %s kubectl arch', 'getKubectlArch() - return on %s os arch %s kubectl arch',
(osArch, kubectlArch) => { (osArch, kubectlArch) => {
jest.spyOn(os, 'arch').mockReturnValue(osArch) jest.spyOn(os, 'arch').mockReturnValue(osArch)
expect(getKubectlArch()).toBe(kubectlArch) expect(getKubectlArch()).toBe(kubectlArch)
expect(os.arch).toBeCalled() expect(os.arch).toBeCalled()
} }
) )
test.each([['arm'], ['arm64'], ['amd64']])( test.each([['arm'], ['arm64'], ['amd64']])(
'getkubectlDownloadURL() - return the URL to download %s kubectl for Linux', 'getkubectlDownloadURL() - return the URL to download %s kubectl for Linux',
(arch) => { (arch) => {
@@ -42,10 +48,12 @@ describe('Testing all functions in run file.', () => {
'https://dl.k8s.io/release/v1.15.0/bin/linux/%s/kubectl', 'https://dl.k8s.io/release/v1.15.0/bin/linux/%s/kubectl',
arch arch
) )
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl) expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl)
expect(os.type).toBeCalled() expect(os.type).toBeCalled()
} }
) )
test.each([['arm'], ['arm64'], ['amd64']])( test.each([['arm'], ['arm64'], ['amd64']])(
'getkubectlDownloadURL() - return the URL to download %s kubectl for Darwin', 'getkubectlDownloadURL() - return the URL to download %s kubectl for Darwin',
(arch) => { (arch) => {
@@ -54,14 +62,17 @@ describe('Testing all functions in run file.', () => {
'https://dl.k8s.io/release/v1.15.0/bin/darwin/%s/kubectl', 'https://dl.k8s.io/release/v1.15.0/bin/darwin/%s/kubectl',
arch arch
) )
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl) expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl)
expect(os.type).toBeCalled() expect(os.type).toBeCalled()
} }
) )
test.each([['arm'], ['arm64'], ['amd64']])( test.each([['arm'], ['arm64'], ['amd64']])(
'getkubectlDownloadURL() - return the URL to download %s kubectl for Windows', 'getkubectlDownloadURL() - return the URL to download %s kubectl for Windows',
(arch) => { (arch) => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
const kubectlWindowsUrl = util.format( const kubectlWindowsUrl = util.format(
'https://dl.k8s.io/release/v1.15.0/bin/windows/%s/kubectl.exe', 'https://dl.k8s.io/release/v1.15.0/bin/windows/%s/kubectl.exe',
arch arch
@@ -70,31 +81,38 @@ describe('Testing all functions in run file.', () => {
expect(os.type).toBeCalled() expect(os.type).toBeCalled()
} }
) )
test('getStableKubectlVersion() - download stable version file, read version and return it', async () => { test('getStableKubectlVersion() - download stable version file, read version and return it', async () => {
jest jest
.spyOn(toolCache, 'downloadTool') .spyOn(toolCache, 'downloadTool')
.mockReturnValue(Promise.resolve('pathToTool')) .mockReturnValue(Promise.resolve('pathToTool'))
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4') jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4')
expect(await run.getStableKubectlVersion()).toBe('v1.20.4') expect(await run.getStableKubectlVersion()).toBe('v1.20.4')
expect(toolCache.downloadTool).toBeCalled() expect(toolCache.downloadTool).toBeCalled()
expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8') expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8')
}) })
test('getStableKubectlVersion() - return default v1.15.0 if version read is empty', async () => { test('getStableKubectlVersion() - return default v1.15.0 if version read is empty', async () => {
jest jest
.spyOn(toolCache, 'downloadTool') .spyOn(toolCache, 'downloadTool')
.mockReturnValue(Promise.resolve('pathToTool')) .mockReturnValue(Promise.resolve('pathToTool'))
jest.spyOn(fs, 'readFileSync').mockReturnValue('') jest.spyOn(fs, 'readFileSync').mockReturnValue('')
expect(await run.getStableKubectlVersion()).toBe('v1.15.0') expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
expect(toolCache.downloadTool).toBeCalled() expect(toolCache.downloadTool).toBeCalled()
expect(fs.readFileSync).toHaveBeenCalledWith('pathToTool', 'utf8') expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8')
}) })
test('getStableKubectlVersion() - return default v1.15.0 if unable to download file', async () => { test('getStableKubectlVersion() - return default v1.15.0 if unable to download file', async () => {
jest jest
.spyOn(toolCache, 'downloadTool') .spyOn(toolCache, 'downloadTool')
.mockRejectedValue('Unable to download.') .mockRejectedValue('Unable to download.')
expect(await run.getStableKubectlVersion()).toBe('v1.15.0') expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
expect(toolCache.downloadTool).toBeCalled() expect(toolCache.downloadTool).toBeCalled()
}) })
test('downloadKubectl() - download kubectl, add it to toolCache and return path to it', async () => { test('downloadKubectl() - download kubectl, add it to toolCache and return path to it', async () => {
jest.spyOn(toolCache, 'find').mockReturnValue('') jest.spyOn(toolCache, 'find').mockReturnValue('')
jest jest
@@ -105,37 +123,43 @@ describe('Testing all functions in run file.', () => {
.mockReturnValue(Promise.resolve('pathToCachedTool')) .mockReturnValue(Promise.resolve('pathToCachedTool'))
jest.spyOn(os, 'type').mockReturnValue('Windows_NT') jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {}) jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
expect(await run.downloadKubectl('v1.15.0')).toBe( expect(await run.downloadKubectl('v1.15.0')).toBe(
path.join('pathToCachedTool', 'kubectl.exe') path.join('pathToCachedTool', 'kubectl.exe')
) )
expect(toolCache.find).toHaveBeenCalledWith('kubectl', 'v1.15.0') expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
expect(toolCache.downloadTool).toBeCalled() expect(toolCache.downloadTool).toBeCalled()
expect(toolCache.cacheFile).toBeCalled() expect(toolCache.cacheFile).toBeCalled()
expect(os.type).toBeCalled() expect(os.type).toBeCalled()
expect(fs.chmodSync).toHaveBeenCalledWith( expect(fs.chmodSync).toBeCalledWith(
path.join('pathToCachedTool', 'kubectl.exe'), path.join('pathToCachedTool', 'kubectl.exe'),
'775' '775'
) )
}) })
test('downloadKubectl() - throw DownloadKubectlFailed error when unable to download kubectl', async () => { test('downloadKubectl() - throw DownloadKubectlFailed error when unable to download kubectl', async () => {
jest.spyOn(toolCache, 'find').mockReturnValue('') jest.spyOn(toolCache, 'find').mockReturnValue('')
jest jest
.spyOn(toolCache, 'downloadTool') .spyOn(toolCache, 'downloadTool')
.mockRejectedValue('Unable to download kubectl.') .mockRejectedValue('Unable to download kubectl.')
await expect(run.downloadKubectl('v1.15.0')).rejects.toThrow( await expect(run.downloadKubectl('v1.15.0')).rejects.toThrow(
'DownloadKubectlFailed' 'DownloadKubectlFailed'
) )
expect(toolCache.find).toHaveBeenCalledWith('kubectl', 'v1.15.0') expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
expect(toolCache.downloadTool).toBeCalled() expect(toolCache.downloadTool).toBeCalled()
}) })
test('downloadKubectl() - throw kubectl not found error when receive 404 response', async () => { test('downloadKubectl() - throw kubectl not found error when receive 404 response', async () => {
const kubectlVersion = 'v1.15.0' const kubectlVersion = 'v1.15.0'
const arch = 'arm128' const arch = 'arm128'
jest.spyOn(os, 'arch').mockReturnValue(arch) jest.spyOn(os, 'arch').mockReturnValue(arch)
jest.spyOn(toolCache, 'find').mockReturnValue('') jest.spyOn(toolCache, 'find').mockReturnValue('')
jest.spyOn(toolCache, 'downloadTool').mockImplementation((_) => { jest.spyOn(toolCache, 'downloadTool').mockImplementation((_) => {
throw new toolCache.HTTPError(404) throw new toolCache.HTTPError(404)
}) })
await expect(run.downloadKubectl(kubectlVersion)).rejects.toThrow( await expect(run.downloadKubectl(kubectlVersion)).rejects.toThrow(
util.format( util.format(
"Kubectl '%s' for '%s' arch not found.", "Kubectl '%s' for '%s' arch not found.",
@@ -144,26 +168,28 @@ describe('Testing all functions in run file.', () => {
) )
) )
expect(os.arch).toBeCalled() expect(os.arch).toBeCalled()
expect(toolCache.find).toHaveBeenCalledWith('kubectl', kubectlVersion) expect(toolCache.find).toBeCalledWith('kubectl', kubectlVersion)
expect(toolCache.downloadTool).toBeCalled() expect(toolCache.downloadTool).toBeCalled()
}) })
test('downloadKubectl() - return path to existing cache of kubectl', async () => { test('downloadKubectl() - return path to existing cache of kubectl', async () => {
jest.spyOn(core, 'getInput').mockImplementation(() => 'v1.15.5')
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool') jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
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, 'downloadTool') jest.spyOn(toolCache, 'downloadTool')
expect(await run.downloadKubectl('v1.15.0')).toBe( expect(await run.downloadKubectl('v1.15.0')).toBe(
path.join('pathToCachedTool', 'kubectl.exe') path.join('pathToCachedTool', 'kubectl.exe')
) )
expect(toolCache.find).toHaveBeenCalledWith('kubectl', 'v1.15.0') expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
expect(os.type).toBeCalled() expect(os.type).toBeCalled()
expect(fs.chmodSync).toHaveBeenCalledWith( expect(fs.chmodSync).toBeCalledWith(
path.join('pathToCachedTool', 'kubectl.exe'), path.join('pathToCachedTool', 'kubectl.exe'),
'775' '775'
) )
expect(toolCache.downloadTool).not.toBeCalled() expect(toolCache.downloadTool).not.toBeCalled()
}) })
test('run() - download specified version and set output', async () => { test('run() - download specified version and set output', async () => {
jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5') jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5')
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool') jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
@@ -172,14 +198,16 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(core, 'addPath').mockImplementation() jest.spyOn(core, 'addPath').mockImplementation()
jest.spyOn(console, 'log').mockImplementation() jest.spyOn(console, 'log').mockImplementation()
jest.spyOn(core, 'setOutput').mockImplementation() jest.spyOn(core, 'setOutput').mockImplementation()
expect(await run.run()).toBeUndefined() expect(await run.run()).toBeUndefined()
expect(core.getInput).toHaveBeenCalledWith('version', {required: true}) expect(core.getInput).toBeCalledWith('version', {required: true})
expect(core.addPath).toHaveBeenCalledWith('pathToCachedTool') expect(core.addPath).toBeCalledWith('pathToCachedTool')
expect(core.setOutput).toHaveBeenCalledWith( expect(core.setOutput).toBeCalledWith(
'kubectl-path', 'kubectl-path',
path.join('pathToCachedTool', 'kubectl.exe') path.join('pathToCachedTool', 'kubectl.exe')
) )
}) })
test('run() - get latest version, download it and set output', async () => { test('run() - get latest version, download it and set output', async () => {
jest.spyOn(core, 'getInput').mockReturnValue('latest') jest.spyOn(core, 'getInput').mockReturnValue('latest')
jest jest
@@ -192,13 +220,14 @@ describe('Testing all functions in run file.', () => {
jest.spyOn(core, 'addPath').mockImplementation() jest.spyOn(core, 'addPath').mockImplementation()
jest.spyOn(console, 'log').mockImplementation() jest.spyOn(console, 'log').mockImplementation()
jest.spyOn(core, 'setOutput').mockImplementation() jest.spyOn(core, 'setOutput').mockImplementation()
expect(await run.run()).toBeUndefined() expect(await run.run()).toBeUndefined()
expect(toolCache.downloadTool).toHaveBeenCalledWith( expect(toolCache.downloadTool).toBeCalledWith(
'https://storage.googleapis.com/kubernetes-release/release/stable.txt' 'https://storage.googleapis.com/kubernetes-release/release/stable.txt'
) )
expect(core.getInput).toHaveBeenCalledWith('version', {required: true}) expect(core.getInput).toBeCalledWith('version', {required: true})
expect(core.addPath).toHaveBeenCalledWith('pathToCachedTool') expect(core.addPath).toBeCalledWith('pathToCachedTool')
expect(core.setOutput).toHaveBeenCalledWith( expect(core.setOutput).toBeCalledWith(
'kubectl-path', 'kubectl-path',
path.join('pathToCachedTool', 'kubectl.exe') path.join('pathToCachedTool', 'kubectl.exe')
) )

View File

@@ -89,3 +89,5 @@ export async function downloadKubectl(version: string): Promise<string> {
fs.chmodSync(kubectlPath, '775') fs.chmodSync(kubectlPath, '775')
return kubectlPath return kubectlPath
} }
run().catch(core.setFailed)