Version fix (#66)

* Added version validation check

* Added check for latest

* Changed Helm 3.5.0 test to also test lack of v in version

* Pushing integration tests

* Removed push integration test

* Added more context to integration test

* Addressing comment
This commit is contained in:
Asa Gayle
2022-02-08 17:07:21 -05:00
committed by GitHub
parent 2998c83e16
commit e00756a00e
3 changed files with 17 additions and 5 deletions

View File

@ -11,7 +11,7 @@ jobs:
env: env:
HELM_3_8_0: "v3.8.0" HELM_3_8_0: "v3.8.0"
HELM_3_7_2: "v3.7.2" HELM_3_7_2: "v3.7.2"
HELM_3_5_0: "v3.5.0" HELM_NO_V: "3.5.0"
PR_BASE_REF: ${{ github.event.pull_request.base.ref }} PR_BASE_REF: ${{ github.event.pull_request.base.ref }}
steps: steps:
- name: Check out repository - name: Check out repository
@ -50,13 +50,13 @@ jobs:
else else
echo "HELM VERSION $HELM_3_7_2 INSTALLED SUCCESSFULLY" echo "HELM VERSION $HELM_3_7_2 INSTALLED SUCCESSFULLY"
fi fi
- name: Setup helm 3.5.0 - name: Setup helm 3.5.0 with no v in version
uses: ./ uses: ./
with: with:
version: ${{ env.HELM_3_5_0 }} version: ${{ env.HELM_NO_V }}
- name: Validate 3.5.0 - name: Validate 3.5.0 without v in version
run: | run: |
if [[ $(helm version) != *$HELM_3_5_0* ]]; then if [[ $(helm version) != *$HELM_NO_V* ]]; then
echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.5.0" echo "HELM VERSION INCORRECT: HELM VERSION DOES NOT CONTAIN v3.5.0"
echo "HELM VERSION OUTPUT: $(helm version)" echo "HELM VERSION OUTPUT: $(helm version)"
exit 1 exit 1

View File

@ -60,6 +60,10 @@ describe("run.ts", () => {
expect(os.arch).toBeCalled(); expect(os.arch).toBeCalled();
}); });
test("getValidVersion() - return version with v prepended", () => {
expect(run.getValidVersion("3.8.0")).toBe("v3.8.0");
});
test("getHelmDownloadURL() - return the URL to download helm for Windows", () => { test("getHelmDownloadURL() - return the URL to download helm for Windows", () => {
jest.spyOn(os, "type").mockReturnValue("Windows_NT"); jest.spyOn(os, "type").mockReturnValue("Windows_NT");

View File

@ -17,6 +17,9 @@ const helmAllReleasesUrl = "https://api.github.com/repos/helm/helm/releases";
export async function run() { export async function run() {
let version = core.getInput("version", { required: true }); let version = core.getInput("version", { required: true });
if(version !== "latest" && version[0] !== "v"){
version = getValidVersion(version);
}
if (version.toLocaleLowerCase() === "latest") { if (version.toLocaleLowerCase() === "latest") {
version = await getLatestHelmVersion(); version = await getLatestHelmVersion();
} }
@ -38,6 +41,11 @@ export async function run() {
core.setOutput("helm-path", cachedPath); core.setOutput("helm-path", cachedPath);
} }
//Returns version with proper v before it
export function getValidVersion(version: string): string {
return "v" + version;
}
// Downloads the helm releases JSON and parses all the recent versions of helm from it. // Downloads the helm releases JSON and parses all the recent versions of helm from it.
// Defaults to sending stable helm version if none are valid or if it fails // Defaults to sending stable helm version if none are valid or if it fails