Grabbed the upstream integration tests and brought them here. Removed bash script. Added validateKubectl.py to /test folder for integration tests.
This commit is contained in:
parent
3c28691302
commit
83ac6564e3
6 changed files with 159 additions and 82 deletions
33
.github/workflows/TriggerIntegrationTests.sh
vendored
33
.github/workflows/TriggerIntegrationTests.sh
vendored
|
@ -1,33 +0,0 @@
|
||||||
token=$1
|
|
||||||
commit=$2
|
|
||||||
repository=$3
|
|
||||||
prNumber=$4
|
|
||||||
frombranch=$5
|
|
||||||
tobranch=$6
|
|
||||||
patUser=$6
|
|
||||||
|
|
||||||
getPayLoad() {
|
|
||||||
cat <<EOF
|
|
||||||
{
|
|
||||||
"event_type": "SetupKubectlActionPR",
|
|
||||||
"client_payload":
|
|
||||||
{
|
|
||||||
"action": "SetupKubectl",
|
|
||||||
"commit": "$commit",
|
|
||||||
"repository": "$repository",
|
|
||||||
"prNumber": "$prNumber",
|
|
||||||
"tobranch": "$tobranch",
|
|
||||||
"frombranch": "$frombranch"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
response=$(curl -u $patUser:$token -X POST https://api.github.com/repos/Azure/azure-actions-integration-tests/dispatches --data "$(getPayLoad)")
|
|
||||||
|
|
||||||
if [ "$response" == "" ]; then
|
|
||||||
echo "Integration tests triggered successfully"
|
|
||||||
else
|
|
||||||
echo "Triggering integration tests failed with: '$response'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
106
.github/workflows/integration-tests.yml
vendored
106
.github/workflows/integration-tests.yml
vendored
|
@ -1,41 +1,79 @@
|
||||||
name: TypeScript Build Check
|
name: Integration test for setup-kubectl-v1
|
||||||
|
on:
|
||||||
on: pull_request
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
reason:
|
||||||
|
description: 'Reason for run'
|
||||||
|
required: true
|
||||||
|
repository_dispatch:
|
||||||
|
types: "SetupKubectlActionPR"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
ts-build-check:
|
run-integration-test:
|
||||||
runs-on: ubuntu-latest
|
name: Validate release and master branch
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Pull Request
|
- name: Set job type
|
||||||
uses: actions/checkout@v2
|
id: job-type
|
||||||
|
run: if [ '${{ github.event.inputs.reason }}' == 'cron' ]; then echo "::set-output name=type::$(echo cron)"; else echo "::set-output name=type::$(echo pr)"; fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions/setup-ruby@v1
|
||||||
|
if: steps.job-type.outputs.type == 'pr'
|
||||||
|
name: Install ruby
|
||||||
with:
|
with:
|
||||||
ref: ${{github.event.pull_request.head.ref}}
|
ruby-version: '2.7'
|
||||||
repository: ${{github.event.pull_request.head.repo.full_name}}
|
|
||||||
path: original-pr
|
- name: Marking status as in-progress on PR
|
||||||
- name: Setup Node
|
if: steps.job-type.outputs.type == 'pr'
|
||||||
uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: 12.x
|
|
||||||
- name: Clone and Build Pull Request
|
|
||||||
run: |
|
run: |
|
||||||
cp $GITHUB_WORKSPACE/original-pr/ $GITHUB_WORKSPACE/built-pr -r
|
ruby postStatus.rb ${{github.event.client_payload.repository}} ${{github.event.client_payload.commit}} ${{secrets.L2_REPO_TOKEN}} ${{job.status}} ${{github.run_id}} ${{matrix.os}} true ${{ secrets.L2_REPO_USER }}
|
||||||
cd $GITHUB_WORKSPACE/built-pr/
|
- uses: actions/checkout@v2
|
||||||
npm i
|
if: steps.job-type.outputs.type == 'pr'
|
||||||
|
name: Checkout from PR branch
|
||||||
|
with:
|
||||||
|
repository: Azure/setup-kubectl
|
||||||
|
ref: ${{ github.event.client_payload.frombranch }}
|
||||||
|
path: 'setup-kubectl'
|
||||||
|
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
if: steps.job-type.outputs.type == 'cron'
|
||||||
|
name: Checkout from main branch
|
||||||
|
with:
|
||||||
|
repository: Azure/setup-kubectl
|
||||||
|
path: 'setup-kubectl'
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
name: Install Python
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
|
- name: Install requests library
|
||||||
|
run: pip install requests
|
||||||
|
|
||||||
|
- name: Building latest changes
|
||||||
|
if: steps.job-type.outputs.type == 'cron' || (steps.job-type.outputs.type == 'pr' && github.event.client_payload.tobranch == 'main')
|
||||||
|
run: |
|
||||||
|
cd setup-kubectl
|
||||||
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
- name: Compare Built Directories
|
- name: Setup kubectl
|
||||||
id: diff
|
uses: ./setup-kubectl
|
||||||
run: |
|
|
||||||
DIFF=$(diff $GITHUB_WORKSPACE/original-pr/lib $GITHUB_WORKSPACE/built-pr/lib -rqiEZbwBd)
|
|
||||||
if [ "$DIFF" != "" ]; then exit 1; else echo -e "PR contains up-to-date compiled JavaScript."; fi
|
|
||||||
- name: Comment Unbuilt TypeScript
|
|
||||||
if: failure() && steps.diff.outcome == 'failure'
|
|
||||||
uses: actions/github-script@v2
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
version: latest
|
||||||
script: |
|
|
||||||
github.issues.createComment({
|
- name: Validate kubectl setup
|
||||||
issue_number: ${{ github.event.number }},
|
run: python test/validate-kubectl.py latest
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
- name: Setup kubectl
|
||||||
body: 'Please compile the TypeScript code with `npm run build`. The compiled JavaScript is not up-to-date.'
|
uses: ./setup-kubectl
|
||||||
})
|
with:
|
||||||
|
version: 'v1.15.1'
|
||||||
|
|
||||||
|
- name: Validate kubectl setup
|
||||||
|
run: python test/validate-kubectl.py 'v1.15.1'
|
||||||
|
|
41
.github/workflows/ts-build-check.yml
vendored
Normal file
41
.github/workflows/ts-build-check.yml
vendored
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
name: TypeScript Build Check
|
||||||
|
|
||||||
|
on: pull_request
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ts-build-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Pull Request
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{github.event.pull_request.head.ref}}
|
||||||
|
repository: ${{github.event.pull_request.head.repo.full_name}}
|
||||||
|
path: original-pr
|
||||||
|
- name: Setup Node
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: 12.x
|
||||||
|
- name: Clone and Build Pull Request
|
||||||
|
run: |
|
||||||
|
cp $GITHUB_WORKSPACE/original-pr/ $GITHUB_WORKSPACE/built-pr -r
|
||||||
|
cd $GITHUB_WORKSPACE/built-pr/
|
||||||
|
npm i
|
||||||
|
npm run build
|
||||||
|
- name: Compare Built Directories
|
||||||
|
id: diff
|
||||||
|
run: |
|
||||||
|
DIFF=$(diff $GITHUB_WORKSPACE/original-pr/lib $GITHUB_WORKSPACE/built-pr/lib -rqiEZbwBd)
|
||||||
|
if [ "$DIFF" != "" ]; then exit 1; else echo -e "PR contains up-to-date compiled JavaScript."; fi
|
||||||
|
- name: Comment Unbuilt TypeScript
|
||||||
|
if: failure() && steps.diff.outcome == 'failure'
|
||||||
|
uses: actions/github-script@v2
|
||||||
|
with:
|
||||||
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
|
script: |
|
||||||
|
github.issues.createComment({
|
||||||
|
issue_number: ${{ github.event.number }},
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
body: 'Please compile the TypeScript code with `npm run build`. The compiled JavaScript is not up-to-date.'
|
||||||
|
})
|
|
@ -1,5 +1,5 @@
|
||||||
import * as run from './run'
|
import * as run from './run'
|
||||||
import * as helpers from './helpers'
|
import { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers';
|
||||||
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';
|
||||||
|
@ -11,14 +11,14 @@ 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(helpers.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(helpers.getExecutableExtension()).toBe('');
|
expect(getExecutableExtension()).toBe('');
|
||||||
expect(os.type).toBeCalled();
|
expect(os.type).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ describe('Testing all functions in run file.', () => {
|
||||||
])("getKubectlArch() - return on %s os arch %s kubectl arch", (osArch, kubectlArch) => {
|
])("getKubectlArch() - return on %s os arch %s kubectl arch", (osArch, kubectlArch) => {
|
||||||
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
jest.spyOn(os, 'arch').mockReturnValue(osArch);
|
||||||
|
|
||||||
expect(helpers.getKubectlArch()).toBe(kubectlArch);
|
expect(getKubectlArch()).toBe(kubectlArch);
|
||||||
expect(os.arch).toBeCalled();
|
expect(os.arch).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ describe('Testing all functions in run file.', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Linux');
|
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);
|
const kubectlLinuxUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/linux/%s/kubectl', arch);
|
||||||
|
|
||||||
expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl);
|
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlLinuxUrl);
|
||||||
expect(os.type).toBeCalled();
|
expect(os.type).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ describe('Testing all functions in run file.', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Darwin');
|
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);
|
const kubectlDarwinUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/darwin/%s/kubectl', arch);
|
||||||
|
|
||||||
expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl);
|
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlDarwinUrl);
|
||||||
expect(os.type).toBeCalled();
|
expect(os.type).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ describe('Testing all functions in run file.', () => {
|
||||||
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');
|
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);
|
const kubectlWindowsUrl = util.format('https://storage.googleapis.com/kubernetes-release/release/v1.15.0/bin/windows/%s/kubectl.exe', arch);
|
||||||
expect(helpers.getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl);
|
expect(getkubectlDownloadURL('v1.15.0', arch)).toBe(kubectlWindowsUrl);
|
||||||
expect(os.type).toBeCalled();
|
expect(os.type).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
12
src/run.ts
12
src/run.ts
|
@ -5,7 +5,7 @@ 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';
|
||||||
|
|
||||||
import * as helpers from './helpers';
|
import { getkubectlDownloadURL, getKubectlArch, getExecutableExtension } from './helpers';
|
||||||
|
|
||||||
const kubectlToolName = 'kubectl';
|
const kubectlToolName = 'kubectl';
|
||||||
const stableKubectlVersion = 'v1.15.0';
|
const stableKubectlVersion = 'v1.15.0';
|
||||||
|
@ -20,7 +20,7 @@ export async function run() {
|
||||||
|
|
||||||
core.addPath(path.dirname(cachedPath));
|
core.addPath(path.dirname(cachedPath));
|
||||||
|
|
||||||
console.log(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`);
|
core.debug(`Kubectl tool version: '${version}' has been cached at ${cachedPath}`);
|
||||||
core.setOutput('kubectl-path', cachedPath);
|
core.setOutput('kubectl-path', cachedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,10 @@ export async function getStableKubectlVersion(): Promise<string> {
|
||||||
export async function downloadKubectl(version: string): Promise<string> {
|
export async function downloadKubectl(version: string): Promise<string> {
|
||||||
let cachedToolpath = toolCache.find(kubectlToolName, version);
|
let cachedToolpath = toolCache.find(kubectlToolName, version);
|
||||||
let kubectlDownloadPath = '';
|
let kubectlDownloadPath = '';
|
||||||
const arch = helpers.getKubectlArch();
|
const arch = getKubectlArch();
|
||||||
if (!cachedToolpath) {
|
if (!cachedToolpath) {
|
||||||
try {
|
try {
|
||||||
kubectlDownloadPath = await toolCache.downloadTool(helpers.getkubectlDownloadURL(version, arch));
|
kubectlDownloadPath = await toolCache.downloadTool(getkubectlDownloadURL(version, arch));
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
if (exception instanceof toolCache.HTTPError && exception.httpStatusCode === 404) {
|
if (exception instanceof toolCache.HTTPError && exception.httpStatusCode === 404) {
|
||||||
throw new Error(util.format("Kubectl '%s' for '%s' arch not found.", version, arch));
|
throw new Error(util.format("Kubectl '%s' for '%s' arch not found.", version, arch));
|
||||||
|
@ -53,10 +53,10 @@ export async function downloadKubectl(version: string): Promise<string> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + helpers.getExecutableExtension(), kubectlToolName, version);
|
cachedToolpath = await toolCache.cacheFile(kubectlDownloadPath, kubectlToolName + getExecutableExtension(), kubectlToolName, version);
|
||||||
}
|
}
|
||||||
|
|
||||||
const kubectlPath = path.join(cachedToolpath, kubectlToolName + helpers.getExecutableExtension());
|
const kubectlPath = path.join(cachedToolpath, kubectlToolName + getExecutableExtension());
|
||||||
fs.chmodSync(kubectlPath, '777');
|
fs.chmodSync(kubectlPath, '777');
|
||||||
return kubectlPath;
|
return kubectlPath;
|
||||||
}
|
}
|
||||||
|
|
31
test/validateKubectl.py
Normal file
31
test/validateKubectl.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import os, sys, json, requests, time
|
||||||
|
|
||||||
|
version_to_check = sys.argv[1]
|
||||||
|
version_info = None
|
||||||
|
PASSED = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
print('kubectl version --client -o json')
|
||||||
|
version_info = json.load(os.popen('kubectl version --client -o json'))
|
||||||
|
except Exception as ex:
|
||||||
|
sys.exit('kubectl not installed')
|
||||||
|
|
||||||
|
try:
|
||||||
|
if version_to_check == 'latest':
|
||||||
|
response = None
|
||||||
|
time_to_sleep = 2
|
||||||
|
for _ in range(10):
|
||||||
|
response = requests.get('https://storage.googleapis.com/kubernetes-release/release/stable.txt')
|
||||||
|
if response.status_code == 200:
|
||||||
|
break
|
||||||
|
print('Failed to obtain latest version info, retrying.')
|
||||||
|
time.sleep(time_to_sleep)
|
||||||
|
time_to_sleep *= 2
|
||||||
|
version_to_check = response.content.decode('utf-8')
|
||||||
|
PASSED = True if version_info['clientVersion']['gitVersion'] == version_to_check else False
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not PASSED:
|
||||||
|
sys.exit('Setting up of '+version_to_check+' kubectl failed')
|
||||||
|
print('Test passed')
|
Loading…
Add table
Reference in a new issue