Compare commits
31 commits
releases/v
...
main
Author | SHA1 | Date | |
---|---|---|---|
|
2d66d6bef6 | ||
|
3b0a9a4ae3 | ||
|
66e812b74c | ||
|
fc19d5430f | ||
|
5f6d890454 | ||
|
27d304ebf8 | ||
|
b5a36385a8 | ||
|
0b4bd0b42d | ||
|
2a0a121944 | ||
|
619a3634cc | ||
|
688936d8db | ||
|
d1dc92d6ff | ||
|
f471212b11 | ||
|
6a79469612 | ||
|
4552b26c1d | ||
|
0a920068d6 | ||
|
340b2c4cf2 | ||
|
bc474d7b1f | ||
|
796733b6bf | ||
|
dd44a92c26 | ||
|
bd5ca45a62 | ||
|
ad011b0706 | ||
|
4beba283ef | ||
|
07847ca908 | ||
|
d41afda166 | ||
|
80632d0f30 | ||
|
84f5aafb14 | ||
|
6d0ea16244 | ||
|
3545f3a551 | ||
|
2eb2a370ff | ||
|
b474dc39ef |
25 changed files with 7213 additions and 11338 deletions
|
@ -4,7 +4,4 @@ about: Create a report to help us improve
|
|||
title: ''
|
||||
labels: need-to-triage
|
||||
assignees: '@aksatlanta'
|
||||
|
||||
---
|
||||
|
||||
|
||||
|
|
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-kubectl" Support
|
||||
url: https://github.com/Azure/setup-kubectl
|
||||
security: https://github.com/Azure/setup-kubectl/blob/main/SECURITY.md
|
||||
about: Please ask and answer questions here.
|
13
.github/ISSUE_TEMPLATE/featureRequestForm.yml
vendored
Normal file
13
.github/ISSUE_TEMPLATE/featureRequestForm.yml
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
name: Feature Request
|
||||
description: File a Feature Request form, we will respond to this thread with any questions.
|
||||
title: 'Feature Request: '
|
||||
labels: ['Feature']
|
||||
assignees: '@Azure/aks-atlanta'
|
||||
body:
|
||||
- type: textarea
|
||||
id: Feature_request
|
||||
attributes:
|
||||
label: Feature request
|
||||
description: Provide example functionality and links to relevant docs
|
||||
validations:
|
||||
required: true
|
18
.github/dependabot.yml
vendored
Normal file
18
.github/dependabot.yml
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: npm
|
||||
directory: /
|
||||
schedule:
|
||||
interval: weekly
|
||||
groups:
|
||||
actions:
|
||||
patterns:
|
||||
- '*'
|
||||
- package-ecosystem: github-actions
|
||||
directory: .github/workflows
|
||||
schedule:
|
||||
interval: weekly
|
||||
groups:
|
||||
actions:
|
||||
patterns:
|
||||
- '*'
|
6
.github/workflows/defaultLabels.yml
vendored
6
.github/workflows/defaultLabels.yml
vendored
|
@ -2,13 +2,13 @@ name: setting-default-labels
|
|||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 0/3 * * *"
|
||||
- cron: '0 0/3 * * *'
|
||||
|
||||
jobs:
|
||||
label-issues:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v9
|
||||
name: Setting issue as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
@ -19,7 +19,7 @@ jobs:
|
|||
operations-per-run: 100
|
||||
exempt-issue-labels: 'backlog'
|
||||
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v9
|
||||
name: Setting PR as idle
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
25
.github/workflows/integration-tests.yml
vendored
25
.github/workflows/integration-tests.yml
vendored
|
@ -3,11 +3,11 @@ on: # rebuild any PRs and main branch changes
|
|||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- "releases/*"
|
||||
- 'releases/*'
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- "releases/*"
|
||||
- 'releases/*'
|
||||
|
||||
jobs:
|
||||
run-integration-test:
|
||||
|
@ -17,7 +17,7 @@ jobs:
|
|||
KUBECONFIG: /home/runner/.kube/config
|
||||
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
name: Checkout from PR branch
|
||||
|
||||
- id: action-npm-build
|
||||
|
@ -29,21 +29,26 @@ jobs:
|
|||
npm run build
|
||||
fi
|
||||
|
||||
- uses: actions/setup-python@v2
|
||||
- uses: actions/setup-python@v5
|
||||
name: Install Python
|
||||
with:
|
||||
python-version: "3.x"
|
||||
python-version: '3.x'
|
||||
|
||||
- name: Install requests library
|
||||
run: pip install requests
|
||||
|
||||
- name: Validate kubectl setup
|
||||
run: python test/validate-kubectl.py !v1.15.1
|
||||
|
||||
- name: Setup kubectl
|
||||
- name: Setup kubectl latest
|
||||
uses: ./
|
||||
with:
|
||||
version: "v1.15.1"
|
||||
version: 'latest'
|
||||
|
||||
- name: Validate kubectl setup
|
||||
run: python test/validate-kubectl.py latest
|
||||
|
||||
- name: Setup kubectl old version
|
||||
uses: ./
|
||||
with:
|
||||
version: 'v1.15.1'
|
||||
|
||||
- name: Validate kubectl setup old version
|
||||
run: python test/validate-kubectl.py 'v1.15.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@v4
|
||||
|
||||
- name: Enforce Prettier
|
||||
uses: actionsx/prettier@v3
|
||||
with:
|
||||
args: --check .
|
20
.github/workflows/release-pr.yml
vendored
20
.github/workflows/release-pr.yml
vendored
|
@ -1,14 +1,18 @@
|
|||
name: Create release PR
|
||||
name: Release Project
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- CHANGELOG.md
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release:
|
||||
description: "Define release version (ex: v1, v2, v3)"
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
release-pr:
|
||||
uses: OliverMKing/javascript-release-workflow/.github/workflows/release-pr.yml@main
|
||||
release:
|
||||
permissions:
|
||||
actions: read
|
||||
contents: write
|
||||
uses: Azure/action-release-workflows/.github/workflows/release_js_project.yaml@v1
|
||||
with:
|
||||
release: ${{ github.event.inputs.release }}
|
||||
changelogPath: ./CHANGELOG.md
|
||||
|
|
10
.github/workflows/tag-and-draft.yml
vendored
10
.github/workflows/tag-and-draft.yml
vendored
|
@ -1,10 +0,0 @@
|
|||
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
|
4
.github/workflows/unit-tests.yml
vendored
4
.github/workflows/unit-tests.yml
vendored
|
@ -1,4 +1,4 @@
|
|||
name: "Run unit tests."
|
||||
name: 'Run unit tests.'
|
||||
on: # rebuild any PRs and main branch changes
|
||||
pull_request:
|
||||
branches:
|
||||
|
@ -13,7 +13,7 @@ jobs:
|
|||
build: # make sure build/ci works properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Build and run L0 tests.
|
||||
run: |
|
||||
|
|
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
|
||||
}
|
7
CHANGELOG.md
Normal file
7
CHANGELOG.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
# Changelog
|
||||
|
||||
## [v4.0.0] - 2024-01-30
|
||||
|
||||
### Changed
|
||||
|
||||
- #90 Migrate to node 20 as node 16 is deprecated
|
|
@ -1,14 +1,16 @@
|
|||
# Setup Kubectl
|
||||
|
||||
#### Sample workflow to install a specific version of kubectl binary on the runner.
|
||||
|
||||
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
|
||||
- uses: azure/setup-kubectl@v2.0
|
||||
- uses: azure/setup-kubectl@v4
|
||||
with:
|
||||
version: '<version>' # default is latest stable
|
||||
id: install
|
||||
```
|
||||
|
||||
Refer to the action metadata file for details about all the inputs https://github.com/Azure/setup-kubectl/blob/main/action.yml
|
||||
|
||||
# Contributing
|
||||
|
@ -24,3 +26,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-kubectl 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-kubectl/issues), and if your issue isn't already represented please [open a new one](https://github.com/Azure/setup-kubectl/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
|
||||
|
||||
|
@ -14,13 +14,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.
|
||||
|
||||
|
|
16
action.yml
16
action.yml
|
@ -1,15 +1,15 @@
|
|||
name: "Kubectl tool installer"
|
||||
description: "Install a specific version of kubectl binary. Acceptable values are latest or any semantic version string like 1.15.0"
|
||||
name: 'Kubectl tool installer'
|
||||
description: 'Install a specific version of kubectl binary. Acceptable values are latest or any semantic version string like 1.15.0'
|
||||
inputs:
|
||||
version:
|
||||
description: "Version of kubectl"
|
||||
description: 'Version of kubectl'
|
||||
required: true
|
||||
default: "latest"
|
||||
default: 'latest'
|
||||
outputs:
|
||||
kubectl-path:
|
||||
description: "Path to the cached kubectl binary"
|
||||
description: 'Path to the cached kubectl binary'
|
||||
branding:
|
||||
color: "blue"
|
||||
color: 'blue'
|
||||
runs:
|
||||
using: "node16"
|
||||
main: "lib/index.js"
|
||||
using: 'node20'
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10326
package-lock.json
generated
10326
package-lock.json
generated
File diff suppressed because it is too large
Load diff
23
package.json
23
package.json
|
@ -4,9 +4,11 @@
|
|||
"private": true,
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"build": "ncc build src/run.ts -o lib",
|
||||
"build": "npm i ncc && npx ncc build src/run.ts -o lib",
|
||||
"test": "jest",
|
||||
"test-coverage": "jest --coverage"
|
||||
"test-coverage": "jest --coverage",
|
||||
"format": "prettier --write .",
|
||||
"format-check": "prettier --check ."
|
||||
},
|
||||
"keywords": [
|
||||
"actions",
|
||||
|
@ -16,16 +18,17 @@
|
|||
"author": "GitHub",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/core": "^1.11.1",
|
||||
"@actions/exec": "^1.0.0",
|
||||
"@actions/tool-cache": "^1.0.0"
|
||||
"@actions/tool-cache": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.0.4",
|
||||
"@vercel/ncc": "^0.33.1",
|
||||
"jest": "^26.0.1",
|
||||
"@types/jest": "^26.0.1",
|
||||
"ts-jest": "^26.0.1",
|
||||
"typescript": "3.9.2"
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/node": "^22.10.2",
|
||||
"@vercel/ncc": "^0.38.3",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "3.4.2",
|
||||
"ts-jest": "^29.2.5",
|
||||
"typescript": "5.7.2"
|
||||
}
|
||||
}
|
|
@ -1,31 +1,31 @@
|
|||
import * as os from 'os';
|
||||
import * as util from 'util';
|
||||
import * as os from 'os'
|
||||
import * as util from 'util'
|
||||
|
||||
export function getKubectlArch(): string {
|
||||
const arch = os.arch();
|
||||
const arch = os.arch()
|
||||
if (arch === 'x64') {
|
||||
return 'amd64';
|
||||
return 'amd64'
|
||||
}
|
||||
return arch;
|
||||
return arch
|
||||
}
|
||||
|
||||
export function getkubectlDownloadURL(version: string, arch: string): string {
|
||||
switch (os.type()) {
|
||||
case 'Linux':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/%s/kubectl', version, arch);
|
||||
return `https://dl.k8s.io/release/${version}/bin/linux/${arch}/kubectl`
|
||||
|
||||
case 'Darwin':
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/darwin/%s/kubectl', version, arch);
|
||||
return `https://dl.k8s.io/release/${version}/bin/darwin/${arch}/kubectl`
|
||||
|
||||
case 'Windows_NT':
|
||||
default:
|
||||
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/%s/kubectl.exe', version, arch);
|
||||
return `https://dl.k8s.io/release/${version}/bin/windows/${arch}/kubectl.exe`
|
||||
}
|
||||
}
|
||||
|
||||
export function getExecutableExtension(): string {
|
||||
if (os.type().match(/^Win/)) {
|
||||
return '.exe';
|
||||
return '.exe'
|
||||
}
|
||||
return '';
|
||||
return ''
|
||||
}
|
320
src/run.test.ts
320
src/run.test.ts
|
@ -1,183 +1,235 @@
|
|||
import * as run from './run'
|
||||
import { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers';
|
||||
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';
|
||||
import * as util from 'util';
|
||||
import {
|
||||
getkubectlDownloadURL,
|
||||
getKubectlArch,
|
||||
getExecutableExtension
|
||||
} from './helpers'
|
||||
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'
|
||||
import * as util from 'util'
|
||||
|
||||
describe('Testing all functions in run file.', () => {
|
||||
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(os.type).toBeCalled();
|
||||
});
|
||||
expect(getExecutableExtension()).toBe('.exe')
|
||||
expect(os.type).toBeCalled()
|
||||
})
|
||||
|
||||
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(os.type).toBeCalled();
|
||||
});
|
||||
expect(getExecutableExtension()).toBe('')
|
||||
expect(os.type).toBeCalled()
|
||||
})
|
||||
|
||||
test.each([
|
||||
['arm', 'arm'],
|
||||
['arm64', 'arm64'],
|
||||
['x64', 'amd64']
|
||||
])("getKubectlArch() - return on %s os arch %s kubectl arch", (osArch, kubectlArch) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||
])(
|
||||
'getKubectlArch() - return on %s os arch %s kubectl arch',
|
||||
(osArch, kubectlArch) => {
|
||||
jest.spyOn(os, 'arch').mockReturnValue(osArch)
|
||||
|
||||
expect(getKubectlArch()).toBe(kubectlArch);
|
||||
expect(os.arch).toBeCalled();
|
||||
});
|
||||
expect(getKubectlArch()).toBe(kubectlArch)
|
||||
expect(os.arch).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test.each([
|
||||
['arm'],
|
||||
['arm64'],
|
||||
['amd64']
|
||||
])('getkubectlDownloadURL() - return the URL to download %s kubectl for Linux', (arch) => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
||||
const kubectlLinuxUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/linux/%s/kubectl', arch);
|
||||
test.each([['arm'], ['arm64'], ['amd64']])(
|
||||
'getkubectlDownloadURL() - return the URL to download %s kubectl for Linux',
|
||||
(arch) => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Linux')
|
||||
const kubectlLinuxUrl = util.format(
|
||||
'https://dl.k8s.io/release/v1.15.0/bin/linux/%s/kubectl',
|
||||
arch
|
||||
)
|
||||
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test.each([
|
||||
['arm'],
|
||||
['arm64'],
|
||||
['amd64']
|
||||
])('getkubectlDownloadURL() - return the URL to download %s kubectl for Darwin', (arch) => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
||||
const kubectlDarwinUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/darwin/%s/kubectl', arch);
|
||||
test.each([['arm'], ['arm64'], ['amd64']])(
|
||||
'getkubectlDownloadURL() - return the URL to download %s kubectl for Darwin',
|
||||
(arch) => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Darwin')
|
||||
const kubectlDarwinUrl = util.format(
|
||||
'https://dl.k8s.io/release/v1.15.0/bin/darwin/%s/kubectl',
|
||||
arch
|
||||
)
|
||||
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test.each([
|
||||
['arm'],
|
||||
['arm64'],
|
||||
['amd64']
|
||||
])('getkubectlDownloadURL() - return the URL to download %s kubectl for Windows', (arch) => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
test.each([['arm'], ['arm64'], ['amd64']])(
|
||||
'getkubectlDownloadURL() - return the URL to download %s kubectl for Windows',
|
||||
(arch) => {
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
|
||||
const kubectlWindowsUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/windows/%s/kubectl.exe', arch);
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl);
|
||||
expect(os.type).toBeCalled();
|
||||
});
|
||||
const kubectlWindowsUrl = util.format(
|
||||
'https://dl.k8s.io/release/v1.15.0/bin/windows/%s/kubectl.exe',
|
||||
arch
|
||||
)
|
||||
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl)
|
||||
expect(os.type).toBeCalled()
|
||||
}
|
||||
)
|
||||
|
||||
test('getStableKubectlVersion() - download stable version file, read version and return it', async () => {
|
||||
jest.spyOn(toolCache, 'downloadTool').mockReturnValue(Promise.resolve('pathToTool'));
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4');
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockReturnValue(Promise.resolve('pathToTool'))
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4')
|
||||
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.20.4');
|
||||
expect(toolCache.downloadTool).toBeCalled();
|
||||
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8');
|
||||
});
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.20.4')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8')
|
||||
})
|
||||
|
||||
test('getStableKubectlVersion() - return default v1.15.0 if version read is empty', async () => {
|
||||
jest.spyOn(toolCache, 'downloadTool').mockReturnValue(Promise.resolve('pathToTool'));
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('');
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockReturnValue(Promise.resolve('pathToTool'))
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('')
|
||||
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.15.0');
|
||||
expect(toolCache.downloadTool).toBeCalled();
|
||||
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8');
|
||||
});
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8')
|
||||
})
|
||||
|
||||
test('getStableKubectlVersion() - return default v1.15.0 if unable to download file', async () => {
|
||||
jest.spyOn(toolCache, 'downloadTool').mockRejectedValue('Unable to download.');
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockRejectedValue('Unable to download.')
|
||||
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.15.0');
|
||||
expect(toolCache.downloadTool).toBeCalled();
|
||||
});
|
||||
expect(await run.getStableKubectlVersion()).toBe('v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
})
|
||||
|
||||
test('downloadKubectl() - download kubectl, add it to toolCache and return path to it', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockReturnValue(Promise.resolve('pathToTool'));
|
||||
jest.spyOn(toolCache, 'cacheFile').mockReturnValue(Promise.resolve('pathToCachedTool'));
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => { });
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockReturnValue(Promise.resolve('pathToTool'))
|
||||
jest
|
||||
.spyOn(toolCache, 'cacheFile')
|
||||
.mockReturnValue(Promise.resolve('pathToCachedTool'))
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
|
||||
expect(await run.downloadKubectl('v1.15.0')).toBe(path.join('pathToCachedTool', 'kubectl.exe'));
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0');
|
||||
expect(toolCache.downloadTool).toBeCalled();
|
||||
expect(toolCache.cacheFile).toBeCalled();
|
||||
expect(os.type).toBeCalled();
|
||||
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedTool', 'kubectl.exe'), '775');
|
||||
});
|
||||
expect(await run.downloadKubectl('v1.15.0')).toBe(
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
expect(toolCache.cacheFile).toBeCalled()
|
||||
expect(os.type).toBeCalled()
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
path.join('pathToCachedTool', 'kubectl.exe'),
|
||||
'775'
|
||||
)
|
||||
})
|
||||
|
||||
test('downloadKubectl() - throw DownloadKubectlFailed error when unable to download kubectl', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockRejectedValue('Unable to download kubectl.');
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockRejectedValue('Unable to download kubectl.')
|
||||
|
||||
await expect(run.downloadKubectl('v1.15.0')).rejects.toThrow('DownloadKubectlFailed');
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0');
|
||||
expect(toolCache.downloadTool).toBeCalled();
|
||||
});
|
||||
await expect(run.downloadKubectl('v1.15.0')).rejects.toThrow(
|
||||
'DownloadKubectlFailed'
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
})
|
||||
|
||||
test('downloadKubectl() - throw kubectl not found error when receive 404 response', async () => {
|
||||
const kubectlVersion = 'v1.15.0'
|
||||
const arch = 'arm128';
|
||||
const arch = 'arm128'
|
||||
|
||||
jest.spyOn(os, 'arch').mockReturnValue(arch);
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockImplementation(_ => {
|
||||
throw new toolCache.HTTPError(404);
|
||||
});
|
||||
jest.spyOn(os, 'arch').mockReturnValue(arch)
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('')
|
||||
jest.spyOn(toolCache, 'downloadTool').mockImplementation((_) => {
|
||||
throw new toolCache.HTTPError(404)
|
||||
})
|
||||
|
||||
await expect(run.downloadKubectl(kubectlVersion)).rejects
|
||||
.toThrow(util.format("Kubectl '%s' for '%s' arch not found.", kubectlVersion, arch));
|
||||
expect(os.arch).toBeCalled();
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', kubectlVersion);
|
||||
expect(toolCache.downloadTool).toBeCalled();
|
||||
});
|
||||
await expect(run.downloadKubectl(kubectlVersion)).rejects.toThrow(
|
||||
util.format(
|
||||
"Kubectl '%s' for '%s' arch not found.",
|
||||
kubectlVersion,
|
||||
arch
|
||||
)
|
||||
)
|
||||
expect(os.arch).toBeCalled()
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', kubectlVersion)
|
||||
expect(toolCache.downloadTool).toBeCalled()
|
||||
})
|
||||
|
||||
test('downloadKubectl() - return path to existing cache of kubectl', async () => {
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool');
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => { });
|
||||
jest.spyOn(toolCache, 'downloadTool');
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation(() => {})
|
||||
jest.spyOn(toolCache, 'downloadTool')
|
||||
|
||||
expect(await run.downloadKubectl('v1.15.0')).toBe(path.join('pathToCachedTool', 'kubectl.exe'));
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0');
|
||||
expect(os.type).toBeCalled();
|
||||
expect(fs.chmodSync).toBeCalledWith(path.join('pathToCachedTool', 'kubectl.exe'), '775');
|
||||
expect(toolCache.downloadTool).not.toBeCalled();
|
||||
});
|
||||
expect(await run.downloadKubectl('v1.15.0')).toBe(
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
expect(toolCache.find).toBeCalledWith('kubectl', 'v1.15.0')
|
||||
expect(os.type).toBeCalled()
|
||||
expect(fs.chmodSync).toBeCalledWith(
|
||||
path.join('pathToCachedTool', 'kubectl.exe'),
|
||||
'775'
|
||||
)
|
||||
expect(toolCache.downloadTool).not.toBeCalled()
|
||||
})
|
||||
|
||||
test('run() - download specified version and set output', async () => {
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5');
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool');
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation();
|
||||
jest.spyOn(core, 'addPath').mockImplementation();
|
||||
jest.spyOn(console, 'log').mockImplementation();
|
||||
jest.spyOn(core, 'setOutput').mockImplementation();
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('v1.15.5')
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation()
|
||||
jest.spyOn(core, 'addPath').mockImplementation()
|
||||
jest.spyOn(console, 'log').mockImplementation()
|
||||
jest.spyOn(core, 'setOutput').mockImplementation()
|
||||
|
||||
expect(await run.run()).toBeUndefined();
|
||||
expect(core.getInput).toBeCalledWith('version', { 'required': true });
|
||||
expect(core.addPath).toBeCalledWith('pathToCachedTool');
|
||||
expect(core.setOutput).toBeCalledWith('kubectl-path', path.join('pathToCachedTool', 'kubectl.exe'));
|
||||
});
|
||||
expect(await run.run()).toBeUndefined()
|
||||
expect(core.getInput).toBeCalledWith('version', {required: true})
|
||||
expect(core.addPath).toBeCalledWith('pathToCachedTool')
|
||||
expect(core.setOutput).toBeCalledWith(
|
||||
'kubectl-path',
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
})
|
||||
|
||||
test('run() - get latest version, download it and set output', async () => {
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('latest');
|
||||
jest.spyOn(toolCache, 'downloadTool').mockReturnValue(Promise.resolve('pathToTool'));
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4');
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool');
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation();
|
||||
jest.spyOn(core, 'addPath').mockImplementation();
|
||||
jest.spyOn(console, 'log').mockImplementation();
|
||||
jest.spyOn(core, 'setOutput').mockImplementation();
|
||||
jest.spyOn(core, 'getInput').mockReturnValue('latest')
|
||||
jest
|
||||
.spyOn(toolCache, 'downloadTool')
|
||||
.mockReturnValue(Promise.resolve('pathToTool'))
|
||||
jest.spyOn(fs, 'readFileSync').mockReturnValue('v1.20.4')
|
||||
jest.spyOn(toolCache, 'find').mockReturnValue('pathToCachedTool')
|
||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT')
|
||||
jest.spyOn(fs, 'chmodSync').mockImplementation()
|
||||
jest.spyOn(core, 'addPath').mockImplementation()
|
||||
jest.spyOn(console, 'log').mockImplementation()
|
||||
jest.spyOn(core, 'setOutput').mockImplementation()
|
||||
|
||||
expect(await run.run()).toBeUndefined();
|
||||
expect(toolCache.downloadTool).toBeCalledWith('https://storage.googleapis.com/kubernetes-release/release/stable.txt');
|
||||
expect(core.getInput).toBeCalledWith('version', { 'required': true });
|
||||
expect(core.addPath).toBeCalledWith('pathToCachedTool');
|
||||
expect(core.setOutput).toBeCalledWith('kubectl-path', path.join('pathToCachedTool', 'kubectl.exe'));
|
||||
});
|
||||
});
|
||||
expect(await run.run()).toBeUndefined()
|
||||
expect(toolCache.downloadTool).toBeCalledWith(
|
||||
'https://storage.googleapis.com/kubernetes-release/release/stable.txt'
|
||||
)
|
||||
expect(core.getInput).toBeCalledWith('version', {required: true})
|
||||
expect(core.addPath).toBeCalledWith('pathToCachedTool')
|
||||
expect(core.setOutput).toBeCalledWith(
|
||||
'kubectl-path',
|
||||
path.join('pathToCachedTool', 'kubectl.exe')
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
101
src/run.ts
101
src/run.ts
|
@ -1,64 +1,93 @@
|
|||
import * as path from 'path';
|
||||
import * as util from 'util';
|
||||
import * as fs from 'fs';
|
||||
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 { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers';
|
||||
import {
|
||||
getkubectlDownloadURL,
|
||||
getKubectlArch,
|
||||
getExecutableExtension
|
||||
} from './helpers'
|
||||
|
||||
const kubectlToolName = 'kubectl';
|
||||
const stableKubectlVersion = 'v1.15.0';
|
||||
const stableVersionUrl = 'https://storage.googleapis.com/kubernetes-release/release/stable.txt';
|
||||
const kubectlToolName = 'kubectl'
|
||||
const stableKubectlVersion = 'v1.15.0'
|
||||
const stableVersionUrl =
|
||||
'https://storage.googleapis.com/kubernetes-release/release/stable.txt'
|
||||
|
||||
export async function run() {
|
||||
let version = core.getInput('version', { 'required': true });
|
||||
let version = core.getInput('version', {required: true})
|
||||
if (version.toLocaleLowerCase() === 'latest') {
|
||||
version = await getStableKubectlVersion();
|
||||
version = await getStableKubectlVersion()
|
||||
}
|
||||
const cachedPath = await downloadKubectl(version);
|
||||
const cachedPath = await downloadKubectl(version)
|
||||
|
||||
core.addPath(path.dirname(cachedPath));
|
||||
core.addPath(path.dirname(cachedPath))
|
||||
|
||||
core.debug(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`);
|
||||
core.setOutput('kubectl-path', cachedPath);
|
||||
core.debug(
|
||||
`Kubectl tool version: '${version}' has been cached at ${cachedPath}`
|
||||
)
|
||||
core.setOutput('kubectl-path', cachedPath)
|
||||
}
|
||||
|
||||
export async function getStableKubectlVersion(): Promise<string> {
|
||||
return toolCache.downloadTool(stableVersionUrl).then((downloadPath) => {
|
||||
let version = fs.readFileSync(downloadPath, 'utf8').toString().trim();
|
||||
return toolCache.downloadTool(stableVersionUrl).then(
|
||||
(downloadPath) => {
|
||||
let version = fs.readFileSync(downloadPath, 'utf8').toString().trim()
|
||||
if (!version) {
|
||||
version = stableKubectlVersion;
|
||||
version = stableKubectlVersion
|
||||
}
|
||||
return version;
|
||||
}, (error) => {
|
||||
core.debug(error);
|
||||
core.warning('GetStableVersionFailed');
|
||||
return stableKubectlVersion;
|
||||
});
|
||||
return version
|
||||
},
|
||||
(error) => {
|
||||
core.debug(error)
|
||||
core.warning('GetStableVersionFailed')
|
||||
return stableKubectlVersion
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export async function downloadKubectl(version: string): Promise<string> {
|
||||
let cachedToolpath = toolCache.find(kubectlToolName, version);
|
||||
let kubectlDownloadPath = '';
|
||||
const arch = getKubectlArch();
|
||||
let cachedToolpath = toolCache.find(kubectlToolName, version)
|
||||
let kubectlDownloadPath = ''
|
||||
const arch = getKubectlArch()
|
||||
if (!cachedToolpath) {
|
||||
try {
|
||||
kubectlDownloadPath = await toolCache.downloadTool(getkubectlDownloadURL(version, arch));
|
||||
kubectlDownloadPath = await toolCache.downloadTool(
|
||||
getkubectlDownloadURL(version, arch)
|
||||
)
|
||||
} catch (exception) {
|
||||
if (exception instanceof toolCache.HTTPError && exception.httpStatusCode === 404) {
|
||||
throw new Error(util.format("Kubectl '%s' for '%s' arch not found.", version, arch));
|
||||
if (
|
||||
exception instanceof toolCache.HTTPError &&
|
||||
exception.httpStatusCode === 404
|
||||
) {
|
||||
throw new Error(
|
||||
util.format(
|
||||
"Kubectl '%s' for '%s' arch not found.",
|
||||
version,
|
||||
arch
|
||||
)
|
||||
)
|
||||
} else {
|
||||
throw new Error('DownloadKubectlFailed');
|
||||
throw new Error('DownloadKubectlFailed')
|
||||
}
|
||||
}
|
||||
|
||||
cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version);
|
||||
cachedToolpath = await toolCache.cacheFile(
|
||||
kubectlDownloadPath,
|
||||
kubectlToolName + getExecutableExtension(),
|
||||
kubectlToolName,
|
||||
version
|
||||
)
|
||||
}
|
||||
|
||||
const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension());
|
||||
fs.chmodSync(kubectlPath, '775');
|
||||
return kubectlPath;
|
||||
const kubectlPath = path.join(
|
||||
cachedToolpath,
|
||||
kubectlToolName + getExecutableExtension()
|
||||
)
|
||||
fs.chmodSync(kubectlPath, '775')
|
||||
return kubectlPath
|
||||
}
|
||||
|
||||
run().catch(core.setFailed);
|
||||
run().catch(core.setFailed)
|
||||
|
|
|
@ -3,8 +3,5 @@
|
|||
"target": "ES6",
|
||||
"module": "commonjs"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"test"
|
||||
]
|
||||
"exclude": ["node_modules", "test"]
|
||||
}
|
Loading…
Reference in a new issue