Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup action for release #56

Merged
merged 33 commits into from Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
244104d
Removed empty try catch
aamgayle Dec 6, 2021
102789f
Initial commit
aamgayle Jan 13, 2022
91434c9
Compiled to js
aamgayle Jan 13, 2022
db9832f
Merge pull request #1 from taakleton/asgayle/setup-helm-refactor
aamgayle Jan 13, 2022
db3e6df
Escape slash for nodejs
aamgayle Jan 13, 2022
7b95bcc
Updating getStableHelmVersion test
aamgayle Jan 13, 2022
e468b13
Removing old versions of run
aamgayle Jan 14, 2022
b34dae9
Added comment on getLatestHelmVersion and variable for helm release u…
aamgayle Jan 14, 2022
363e425
Pushing recent changes before computer reset
aamgayle Jan 21, 2022
f1588f7
Latest getLatestHelmVersion iteration
aamgayle Jan 25, 2022
6fb2206
Removed test
aamgayle Jan 25, 2022
822c0c2
Testing async test
aamgayle Jan 25, 2022
45f20ed
getLatestHelmVersion refactor
aamgayle Jan 25, 2022
f89e61b
fixed method to access helm releses JSON
aamgayle Jan 25, 2022
700a7c0
Edited comment on isValidVersion
aamgayle Jan 25, 2022
7184130
Removed old integration tests
aamgayle Jan 26, 2022
73481c6
Small temp test
aamgayle Jan 26, 2022
4c466f0
Removed IntegrationTests path
aamgayle Jan 26, 2022
03759bd
Updated package-lock.json and removed unused dep
aamgayle Jan 26, 2022
49a9aad
Integration testing
aamgayle Jan 26, 2022
49e3211
Fixed if statement in run command
aamgayle Jan 26, 2022
21069d8
Added exit
aamgayle Jan 26, 2022
1d63310
Double brackets for new test
aamgayle Jan 26, 2022
36eb99c
Added version confirmation output and different check for version
aamgayle Jan 26, 2022
64dc736
Helm 3.7.2 test
aamgayle Jan 26, 2022
eb06923
added env to workflow paths
aamgayle Jan 26, 2022
0b18ab3
adjusted env in workflow paths
aamgayle Jan 26, 2022
d2f4a46
3.5.0 tests
aamgayle Jan 26, 2022
a277a45
Requested changes
aamgayle Jan 26, 2022
499b0f3
Fixed downloadHelm test
aamgayle Jan 26, 2022
a191932
Clean up for release
aamgayle Jan 26, 2022
5806275
Updated CODEOWNERS
aamgayle Jan 26, 2022
5f83ebd
Updated CODEOWNERS
aamgayle Jan 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -1 +1 @@
* @ds-ms
* @Azure/aksatlanta
33 changes: 0 additions & 33 deletions .github/workflows/TriggerIntegrationTests.sh

This file was deleted.

56 changes: 51 additions & 5 deletions .github/workflows/integration-tests.yml
Expand Up @@ -8,12 +8,58 @@ jobs:
trigger-integration-tests:
name: Trigger Integration tests
runs-on: ubuntu-latest
env:
HELM_3_8_0: "v3.8.0"
HELM_3_7_2: "v3.7.2"
HELM_3_5_0: "v3.5.0"
PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
path: IntegrationTests

- name: Trigger Test run
- name: npm install and build
id: action-npm-build
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 }}
echo $PR_BASE_REF
if [[ $PR_BASE_REF != releases/* ]]; then
npm install
npm run build
fi
- name: Setup helm
uses: ./
with:
version: ${{ env.HELM_3_8_0 }}
- name: Validate helm 3.8.0
run: |
if [[ $(helm version) != *$HELM_3_8_0* ]]; then
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.8.0"
echo "HELM VERSION OUTPUT: $(helm version)"
exit 1
else
echo "HELM VERSION $HELM_3_8_0 INSTALLED SUCCESSFULLY"
fi
- name: Setup helm 3.7.2
uses: ./
with:
version: ${{ env.HELM_3_7_2 }}
- name: Validate 3.7.2
run: |
if [[ $(helm version) != *$HELM_3_7_2* ]]; then
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.7.2"
echo "HELM VERSION OUTPUT: $(helm version)"
exit 1
else
echo "HELM VERSION $HELM_3_7_2 INSTALLED SUCCESSFULLY"
fi
- name: Setup helm 3.5.0
uses: ./
with:
version: ${{ env.HELM_3_5_0 }}
- name: Validate 3.5.0
run: |
if [[ $(helm version) != *$HELM_3_5_0* ]]; then
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.5.0"
echo "HELM VERSION OUTPUT: $(helm version)"
exit 1
else
echo "HELM VERSION $HELM_3_5_0 INSTALLED SUCCESSFULLY"
fi
55 changes: 55 additions & 0 deletions .github/workflows/release-pr.yml
@@ -0,0 +1,55 @@
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 master:master
git reset --hard master
- 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
77 changes: 77 additions & 0 deletions .github/workflows/tag-and-release.yml
@@ -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
47 changes: 13 additions & 34 deletions __tests__/run.test.ts
Expand Up @@ -22,55 +22,34 @@ describe('run.ts', () => {

test('getHelmDownloadURL() - return the URL to download helm for Linux', () => {
jest.spyOn(os, 'type').mockReturnValue('Linux');
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.2.1-linux-amd64.zip'
const kubectlLinuxUrl = 'https://get.helm.sh/helm-v3.8.0-linux-amd64.zip'

expect(run.getHelmDownloadURL('v3.2.1')).toBe(kubectlLinuxUrl);
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlLinuxUrl);
expect(os.type).toBeCalled();
});

test('getHelmDownloadURL() - return the URL to download helm for Darwin', () => {
jest.spyOn(os, 'type').mockReturnValue('Darwin');
const kubectlDarwinUrl = 'https://get.helm.sh/helm-v3.2.1-darwin-amd64.zip'
const kubectlDarwinUrl = 'https://get.helm.sh/helm-v3.8.0-darwin-amd64.zip'

expect(run.getHelmDownloadURL('v3.2.1')).toBe(kubectlDarwinUrl);
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlDarwinUrl);
expect(os.type).toBeCalled();
});

test('getHelmDownloadURL() - return the URL to download helm for Windows', () => {
jest.spyOn(os, 'type').mockReturnValue('Windows_NT');

const kubectlWindowsUrl = 'https://get.helm.sh/helm-v3.2.1-windows-amd64.zip'
expect(run.getHelmDownloadURL('v3.2.1')).toBe(kubectlWindowsUrl);
const kubectlWindowsUrl = 'https://get.helm.sh/helm-v3.8.0-windows-amd64.zip'
expect(run.getHelmDownloadURL('v3.8.0')).toBe(kubectlWindowsUrl);
expect(os.type).toBeCalled();
});

test('getStableHelmVersion() - download stable version file, read version and return it', async () => {
jest.spyOn(toolCache, 'downloadTool').mockResolvedValue('pathToTool');
const response = JSON.stringify(
[
{
'tag_name': 'v4.0.0'
}, {
'tag_name': 'v3.0.0'
}, {
'tag_name': 'v2.0.0'
}
]
);
jest.spyOn(fs, 'readFileSync').mockReturnValue(response);

expect(await run.getStableHelmVersion()).toBe('v4.0.0');
expect(toolCache.downloadTool).toBeCalled();
expect(fs.readFileSync).toBeCalledWith('pathToTool', 'utf8');
});

test('getStableHelmVersion() - return default version if error occurs while getting latest version', async () => {
jest.spyOn(toolCache, 'downloadTool').mockRejectedValue('Unable to download');
jest.spyOn(core, 'warning').mockImplementation();

expect(await run.getStableHelmVersion()).toBe('v3.2.1');
expect(toolCache.downloadTool).toBeCalled();
expect(core.warning).toBeCalledWith("Cannot get the latest Helm info from https://api.github.com/repos/helm/helm/releases. Error Unable to download. Using default Helm version v3.2.1.");
test('getLatestHelmVersion() - return the latest version of HELM', async () => {
try{
expect(await run.getLatestHelmVersion()).toBe("v3.8.0");
} catch (e){
return e;
}
});

test('walkSync() - return path to the all files matching fileToFind in dir', () => {
Expand Down Expand Up @@ -146,7 +125,7 @@ describe('run.ts', () => {
return { isDirectory: () => isDirectory } as fs.Stats;
});

expect(await run.downloadHelm(null)).toBe(path.join('pathToCachedDir', 'helm.exe'));
expect(await run.downloadHelm("v4.0.0")).toBe(path.join('pathToCachedDir', 'helm.exe'));
expect(toolCache.find).toBeCalledWith('helm', 'v4.0.0');
expect(toolCache.downloadTool).toBeCalledWith('https://get.helm.sh/helm-v4.0.0-windows-amd64.zip');
expect(fs.chmodSync).toBeCalledWith('pathToTool', '777');
Expand Down
4 changes: 0 additions & 4 deletions action.yml
Expand Up @@ -5,10 +5,6 @@ inputs:
description: 'Version of helm'
required: true
default: 'latest'
token:
description: 'Github token'
default: ${{ github.token }}
required: true
outputs:
helm-path:
description: 'Path to the cached helm binary'
Expand Down