From 549876d809cb2f70bedbfa5c913e6d2422c326e1 Mon Sep 17 00:00:00 2001 From: Dmytro Bondar Date: Sun, 28 Jan 2024 10:24:14 +0100 Subject: [PATCH] Revert and rewrite with @octokit/action --- README.md | 4 +- action.yml | 3 +- package-lock.json | 98 +++++++++++++++++++++++++++++++++++++---------- package.json | 2 +- src/run.test.ts | 4 +- src/run.ts | 28 +++++++++++--- 6 files changed, 106 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 66fc164..35717a2 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,12 @@ Acceptable values are latest or any semantic version string like v3.5.0 Use this - uses: azure/setup-helm@v3 with: version: '' # default is latest (stable) + token: ${{ secrets.GITHUB_TOKEN }} # only needed if version is 'latest' id: install ``` > [!NOTE] -> When using latest version the action will try to resolve version tag from latest Helm release. If it fails, will return the hardcoded default stable version (currently v3.13.3). -> If you rely on a certain version higher than the default, you should use that version instead of latest. +> When using latest version you might hit the GitHub GraphQL API hourly rate limit of 5,000. The action will then return the hardcoded default stable version (currently v3.13.3). If you rely on a certain version higher than the default, you should use that version instead of latest. The cached helm binary path is prepended to the PATH environment variable as well as stored in the helm-path output variable. Refer to the action metadata file for details about all the inputs https://github.com/Azure/setup-helm/blob/master/action.yml diff --git a/action.yml b/action.yml index 12e6904..80e20f2 100644 --- a/action.yml +++ b/action.yml @@ -6,9 +6,8 @@ inputs: required: true default: 'latest' token: - description: GitHub token. + description: GitHub token. Required only if 'version' == 'latest' required: false - deprecationMessage: 'This input is deprecated. Action does not require a token anymore.' downloadBaseURL: description: 'Set the download base URL' required: false diff --git a/package-lock.json b/package-lock.json index 8920dc5..5e0d493 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,11 +11,9 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", - "@actions/http-client": "^2.2.0", "@actions/io": "^1.1.2", "@actions/tool-cache": "2.0.1", - "@octokit/auth-action": "^4.0.1", - "@octokit/graphql": "^7.0.2", + "@octokit/action": "^6.0.7", "semver": "^7.5.4" }, "devDependencies": { @@ -25,9 +23,6 @@ "jest": "^29.7.0", "ts-jest": "^29.1.2", "typescript": "^5.3.3" - }, - "engines": { - "node": "20.x" } }, "node_modules/@actions/core": { @@ -1103,6 +1098,33 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@octokit/action": { + "version": "6.0.7", + "resolved": "https://registry.npmjs.org/@octokit/action/-/action-6.0.7.tgz", + "integrity": "sha512-0Q1L96F8JsNb+M2NzN7r4artGyX02Pa9tzg+JaxXncvdHEXVIJFnkA8CstC52EB4DAZ0b8wpqDOG05v/DcyS3g==", + "dependencies": { + "@octokit/auth-action": "^4.0.0", + "@octokit/core": "^5.0.0", + "@octokit/plugin-paginate-rest": "^9.0.0", + "@octokit/plugin-rest-endpoint-methods": "^10.0.0", + "@octokit/types": "^12.0.0", + "undici": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/@octokit/action/node_modules/undici": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-6.5.0.tgz", + "integrity": "sha512-/MUmPb2ptTvp1j7lPvdMSofMdqPxcOhAaKZi4k55sqm6XMeKI3n1dZJ5cnD4gLjpt2l7CIlthR1IXM59xKhpxw==", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=18.0" + } + }, "node_modules/@octokit/auth-action": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/@octokit/auth-action/-/auth-action-4.0.1.tgz", @@ -1123,6 +1145,23 @@ "node": ">= 18" } }, + "node_modules/@octokit/core": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@octokit/core/-/core-5.1.0.tgz", + "integrity": "sha512-BDa2VAMLSh3otEiaMJ/3Y36GU4qf6GI+VivQ/P41NC6GHcdxpKlqV0ikSZ5gdQsmS3ojXeRx5vasgNTinF0Q4g==", + "dependencies": { + "@octokit/auth-token": "^4.0.0", + "@octokit/graphql": "^7.0.0", + "@octokit/request": "^8.0.2", + "@octokit/request-error": "^5.0.0", + "@octokit/types": "^12.0.0", + "before-after-hook": "^2.2.0", + "universal-user-agent": "^6.0.0" + }, + "engines": { + "node": ">= 18" + } + }, "node_modules/@octokit/endpoint": { "version": "9.0.4", "resolved": "https://registry.npmjs.org/@octokit/endpoint/-/endpoint-9.0.4.tgz", @@ -1153,6 +1192,34 @@ "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-19.1.0.tgz", "integrity": "sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw==" }, + "node_modules/@octokit/plugin-paginate-rest": { + "version": "9.1.5", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-9.1.5.tgz", + "integrity": "sha512-WKTQXxK+bu49qzwv4qKbMMRXej1DU2gq017euWyKVudA6MldaSSQuxtz+vGbhxV4CjxpUxjZu6rM2wfc1FiWVg==", + "dependencies": { + "@octokit/types": "^12.4.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, + "node_modules/@octokit/plugin-rest-endpoint-methods": { + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-10.2.0.tgz", + "integrity": "sha512-ePbgBMYtGoRNXDyKGvr9cyHjQ163PbwD0y1MkDJCpkO2YH4OeXX40c4wYHKikHGZcpGPbcRLuy0unPUuafco8Q==", + "dependencies": { + "@octokit/types": "^12.3.0" + }, + "engines": { + "node": ">= 18" + }, + "peerDependencies": { + "@octokit/core": ">=5" + } + }, "node_modules/@octokit/request": { "version": "8.1.6", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.1.6.tgz", @@ -1518,6 +1585,11 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/before-after-hook": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", + "integrity": "sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==" + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1999,20 +2071,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", diff --git a/package.json b/package.json index bbf14c7..3c96f6a 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,9 @@ "dependencies": { "@actions/core": "^1.10.0", "@actions/exec": "^1.1.1", - "@actions/http-client": "^2.2.0", "@actions/io": "^1.1.2", "@actions/tool-cache": "2.0.1", + "@octokit/action": "^6.0.7", "semver": "^7.5.4" }, "main": "lib/index.js", diff --git a/src/run.test.ts b/src/run.test.ts index 8eb90e7..558d4a5 100644 --- a/src/run.test.ts +++ b/src/run.test.ts @@ -86,8 +86,8 @@ describe('run.ts', () => { expect(os.type).toBeCalled() }) - test('getLatestHelmVersion() - check that returned value matches helm version regex', async () => { - expect(await run.getLatestHelmVersion()).toMatch(/^v\d+\.\d+\.\d+$/) + test('getLatestHelmVersion() - return the stable version of HELM since its not authenticated', async () => { + expect(await run.getLatestHelmVersion()).toBe('v3.13.3') }) test('walkSync() - return path to the all files matching fileToFind in dir', () => { diff --git a/src/run.ts b/src/run.ts index f3906e9..839eeac 100644 --- a/src/run.ts +++ b/src/run.ts @@ -9,7 +9,7 @@ import * as fs from 'fs' import * as toolCache from '@actions/tool-cache' import * as core from '@actions/core' -import * as http from '@actions/http-client' +import {Octokit} from '@octokit/action' const helmToolName = 'helm' const stableHelmVersion = 'v3.13.3' @@ -51,17 +51,33 @@ export function getValidVersion(version: string): string { // Gets the latest helm version or returns a default stable if getting latest fails export async function getLatestHelmVersion(): Promise { try { - const httpClient = new http.HttpClient() - const response = await httpClient.getJson( - 'https://github.com/helm/helm/releases/latest' - ) - return response.result.tag_name + const octokit = new Octokit() + const response = await octokit.rest.repos.listReleases({ + owner: 'helm', + repo: 'helm', + per_page: 100, + order: 'desc', + sort: 'created' + }) + + const releases = response.data + const latestValidRelease: string = releases.find( + ({tag_name, draft, prerelease}) => + isValidVersion(tag_name) && !draft && !prerelease + )?.tag_name + + if (latestValidRelease) return latestValidRelease } catch (err) { core.warning( `Error while fetching latest Helm release: ${err.toString()}. Using default version ${stableHelmVersion}` ) return stableHelmVersion } + + core.warning( + `Could not find valid release. Using default version ${stableHelmVersion}` + ) + return stableHelmVersion } // isValidVersion checks if verison is a stable release