Skip to content

Commit

Permalink
Refactoring Action for use with AKS Atlanta (#37)
Browse files Browse the repository at this point in the history
* Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src.

* Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src.

* Grabbed the upstream integration tests and brought them here.  Removed bash script. Added validateKubectl.py to /test folder for integration tests.

* Ran npm run build

* Ran npm run build

* Updated on section for integration-tests.yml

* Removing ruby commands from integration tests yaml.

* Fixing discrepancies in integration test yaml.

* Fixing discrepancies in integration test yaml.

* Default to ubuntu-latest

* renamed python script according to workflow.

* renamed python script according to workflow.

* Fixing path parameters.

* Updated tsconfig.json

* Testing for int test failure.

* Validated that int tests work.

* Added new workflows.

* Testing release (#10)

* Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src.

* Did some reorganizing of code in run.ts, moved run.test.ts into /src, and put some helpers into helpers.ts in /src.

* Grabbed the upstream integration tests and brought them here.  Removed bash script. Added validateKubectl.py to /test folder for integration tests.

* Ran npm run build

* Ran npm run build

* Updated on section for integration-tests.yml

* Removing ruby commands from integration tests yaml.

* Fixing discrepancies in integration test yaml.

* Fixing discrepancies in integration test yaml.

* Default to ubuntu-latest

* renamed python script according to workflow.

* renamed python script according to workflow.

* Fixing path parameters.

* Updated tsconfig.json

* Testing for int test failure.

* Validated that int tests work.

* Added new workflows.

Co-authored-by: Tommy Barnes <thbarnes@microsoft.com>

* made changes reflected in comments

Co-authored-by: Tommy Barnes <thbarnes@microsoft.com>
  • Loading branch information
tbarnes94 and tbarnes94 authored Jan 5, 2022
1 parent dae4b3d commit a10d84b
Show file tree
Hide file tree
Showing 16 changed files with 590 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @tauhid621 @kaverma
* @aksatlanta
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report-feature-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Bug Report / Feature Request
about: Create a report to help us improve
title: ''
labels: need-to-triage
assignees: ''
assignees: '@aksatlanta'

---

Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/TriggerIntegrationTests.sh

This file was deleted.

56 changes: 43 additions & 13 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
name: "Trigger Integration tests"
on:
name: Integration test for setup-kubectl
on: # rebuild any PRs and main branch changes
pull_request:
branches:
- main
- 'releases/*'
push:
branches:
- main
- 'releases/*'

jobs:
trigger-integration-tests:
name: Trigger Integration tests
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
path: IntegrationTests
run-integration-test:
name: Validate release and master branch
runs-on: ubuntu-latest
env:
KUBECONFIG: /home/runner/.kube/config
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
steps:
- uses: actions/checkout@v2
name: Checkout from PR branch

- name: Trigger Test run
run: |
bash ./IntegrationTests/.github/workflows/TriggerIntegrationTests.sh ${{ secrets.L2_REPO_TOKEN }} ${{ github.event.pull_request.head.sha }} ${{ github.repository }} ${{ github.event.pull_request.number }} ${{ github.event.pull_request.head.ref }} ${{ github.event.pull_request.base.ref }} ${{ secrets.L2_REPO_USER }}
- id: action-npm-build
name: npm install and build
run: |
echo $PR_BASE_REF
if [[ $PR_BASE_REF != releases/* ]]; then
npm install
npm run build
fi
- uses: actions/setup-python@v2
name: Install Python
with:
python-version: '3.x'

- name: Install requests library
run: pip install requests

- name: Validate kubectl setup
run: python test/validate-kubectl.py latest

- name: Setup kubectl
uses: ./
with:
version: 'v1.15.1'

- name: Validate kubectl setup
run: python test/validate-kubectl.py 'v1.15.1'
56 changes: 56 additions & 0 deletions .github/workflows/release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: "Create release PR"

on:
workflow_dispatch:
inputs:
release:
description: "Define release version (ex: v1, v2, v3)"
required: true

jobs:
createPullRequest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check if remote branch exists
env:
BRANCH: releases/${{ github.event.inputs.release }}
run: |
echo "##[set-output name=exists;]$(echo $(if [[ -z $(git ls-remote --heads origin ${BRANCH}) ]]; then echo false; else echo true; fi;))"
id: extract-branch-status
# these two only need to occur if the branch exists
- name: Checkout proper branch
if: ${{ steps.extract-branch-status.outputs.exists == 'true' }}
env:
BRANCH: releases/${{ github.event.inputs.release }}
run: git checkout ${BRANCH}
- name: Reset promotion branch
if: ${{ steps.extract-branch-status.outputs.exists == 'true' }}
run: |
git fetch origin main:main
git reset --hard main
- name: Install packages
run: |
rm -rf node_modules/
npm install --no-bin-links
npm run build
- name: Remove node_modules from gitignore
run: |
sed -i '/node_modules/d' ./.gitignore
- name: Create branch
uses: peterjgrainger/action-create-branch@v2.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
branch: releases/${{ github.event.inputs.release }}
- name: Create pull request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Add node modules and new code for release
title: ${{ github.event.inputs.release }} new release
base: releases/${{ github.event.inputs.release }}
branch: create-release
delete-branch: true
77 changes: 77 additions & 0 deletions .github/workflows/tag-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: "Tag and create release draft"

on:
push:
branches:
- releases/*

jobs:
gh_tagged_release:
runs-on: "ubuntu-latest"

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Test release
run: |
sudo npm install n
sudo n latest
npm test
- name: Get branch ending
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/} | sed 's:.*/::')"
id: extract-branch
- name: Get tags
run: |
echo "##[set-output name=tags;]$(echo $(git tag))"
id: extract-tags
- name: Get latest tag
uses: actions/github-script@v5
env:
TAGS: ${{ steps.extract-tags.outputs.tags }}
BRANCH: ${{ steps.extract-branch.outputs.branch }}
with:
script: |
const tags = process.env["TAGS"]
.split(" ")
.map((x) => x.trim());
const branch = process.env["BRANCH"];
const splitTag = (x) =>
x
.substring(branch.length + 1)
.split(".")
.map((x) => Number(x));
function compareTags(nums1, nums2, position = 0) {
if (nums1.length < position && nums2.length < position) return nums2;
const num1 = splitTag(nums1)[position] || 0;
const num2 = splitTag(nums2)[position] || 0;
if (num1 === num2) return compareTags(nums1, nums2, position + 1);
else if (num1 > num2) return nums1;
else return nums2;
}
const branchTags = tags.filter((tag) => tag.startsWith(branch));
if (branchTags.length < 1) return branch + ".-1"
return branchTags.reduce((prev, curr) => compareTags(prev, curr));
result-encoding: string
id: get-latest-tag
- name: Get new tag
uses: actions/github-script@v5
env:
PREV: ${{ steps.get-latest-tag.outputs.result }}
with:
script: |
let version = process.env["PREV"]
if (!version.includes(".")) version += ".0"; // case of v1 or v2
const prefix = /^([a-zA-Z]+)/.exec(version)[0];
const numbers = version.substring(prefix.length);
let split = numbers.split(".");
split[split.length - 1] = parseInt(split[split.length - 1]) + 1;
return prefix + split.join(".");
result-encoding: string
id: get-new-tag
- uses: "marvinpinto/action-automatic-releases@v1.2.1"
with:
title: ${{ steps.get-new-tag.outputs.result }} release
automatic_release_tag: ${{ steps.get-new-tag.outputs.result }}
repo_token: "${{ secrets.GITHUB_TOKEN }}"
draft: true
41 changes: 41 additions & 0 deletions .github/workflows/ts-build-check.yml
Original file line number Diff line number Diff line change
@@ -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.'
})
32 changes: 32 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getExecutableExtension = exports.getkubectlDownloadURL = exports.getKubectlArch = void 0;
const os = require("os");
const util = require("util");
function getKubectlArch() {
const arch = os.arch();
if (arch === 'x64') {
return 'amd64';
}
return arch;
}
exports.getKubectlArch = getKubectlArch;
function getkubectlDownloadURL(version, arch) {
switch (os.type()) {
case 'Linux':
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/linux/%s/kubectl', version, arch);
case 'Darwin':
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/darwin/%s/kubectl', version, arch);
case 'Windows_NT':
default:
return util.format('https://storage.googleapis.com/kubernetes-release/release/%s/bin/windows/%s/kubectl.exe', version, arch);
}
}
exports.getkubectlDownloadURL = getkubectlDownloadURL;
function getExecutableExtension() {
if (os.type().match(/^Win/)) {
return '.exe';
}
return '';
}
exports.getExecutableExtension = getExecutableExtension;
Loading

0 comments on commit a10d84b

Please sign in to comment.