diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9dcc4d29..6193e5ab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,8 @@ jobs: run: npm run lint - name: Test run: npm run test + env: + INPUT_GITHUB_TOKEN: ${{ github.token }} # for core.getInput() test-action: name: GraalVM diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 3946ae88..58035be6 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -79190,24 +79190,15 @@ exports.setNativeImageOption = setNativeImageOption; const c = __importStar(__nccwpck_require__(7242)); const core = __importStar(__nccwpck_require__(7484)); const github = __importStar(__nccwpck_require__(3228)); -const httpClient = __importStar(__nccwpck_require__(4844)); const semver = __importStar(__nccwpck_require__(2088)); const tc = __importStar(__nccwpck_require__(3472)); const fs = __importStar(__nccwpck_require__(9896)); const exec_1 = __nccwpck_require__(5236); const fs_1 = __nccwpck_require__(9896); -const core_1 = __nccwpck_require__(1897); const crypto_1 = __nccwpck_require__(6982); const path_1 = __nccwpck_require__(6928); const os_1 = __nccwpck_require__(857); -// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP) -const baseUrl = 'https://api.github.com'; -const GitHubDotCom = core_1.Octokit.defaults({ - baseUrl, - request: { - agent: new httpClient.HttpClient().getAgent(baseUrl) - } -}); +const utils_1 = __nccwpck_require__(8006); async function exec(commandLine, args, options) { const exitCode = await (0, exec_1.exec)(commandLine, args, options); if (exitCode !== 0) { @@ -79215,18 +79206,14 @@ async function exec(commandLine, args, options) { } } async function getLatestRelease(repo) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/latest', { owner: c.GRAALVM_GH_USER, repo })).data; } async function getContents(repo, path) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { owner: c.GRAALVM_GH_USER, repo, @@ -79234,9 +79221,7 @@ async function getContents(repo, path) { })).data; } async function getTaggedRelease(owner, repo, tag) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { owner, repo, @@ -79244,9 +79229,7 @@ async function getTaggedRelease(owner, repo, tag) { })).data; } async function getMatchingTags(owner, repo, tagPrefix) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', { owner, repo, @@ -79314,15 +79297,23 @@ function toSemVer(version) { function isPREvent() { return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST; } -function getGitHubToken() { - return core.getInput(c.INPUT_GITHUB_TOKEN); +function getOctokit() { + /* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */ + const GitHubWithPlugins = utils_1.GitHub.plugin(); + const token = core.getInput(c.INPUT_GITHUB_TOKEN); + if (token) { + return new GitHubWithPlugins({ auth: `token ${token}` }); + } + else { + return new GitHubWithPlugins(); /* unauthenticated */ + } } async function findExistingPRCommentId(bodyStartsWith) { if (!isPREvent()) { throw new Error('Not a PR event.'); } const context = github.context; - const octokit = github.getOctokit(getGitHubToken()); + const octokit = getOctokit(); try { const comments = await octokit.paginate(octokit.rest.issues.listComments, { ...context.repo, @@ -79342,7 +79333,7 @@ async function updatePRComment(content, commentId) { throw new Error('Not a PR event.'); } try { - await github.getOctokit(getGitHubToken()).rest.issues.updateComment({ + await getOctokit().rest.issues.updateComment({ ...github.context.repo, comment_id: commentId, body: content @@ -79358,7 +79349,7 @@ async function createPRComment(content) { } const context = github.context; try { - await github.getOctokit(getGitHubToken()).rest.issues.createComment({ + await getOctokit().rest.issues.createComment({ ...context.repo, issue_number: context.payload.pull_request?.number, body: content diff --git a/dist/main/index.js b/dist/main/index.js index 83082bc2..3f2a75da 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -80484,24 +80484,15 @@ exports.setNativeImageOption = setNativeImageOption; const c = __importStar(__nccwpck_require__(7242)); const core = __importStar(__nccwpck_require__(7484)); const github = __importStar(__nccwpck_require__(3228)); -const httpClient = __importStar(__nccwpck_require__(4844)); const semver = __importStar(__nccwpck_require__(2088)); const tc = __importStar(__nccwpck_require__(3472)); const fs = __importStar(__nccwpck_require__(9896)); const exec_1 = __nccwpck_require__(5236); const fs_1 = __nccwpck_require__(9896); -const core_1 = __nccwpck_require__(1897); const crypto_1 = __nccwpck_require__(6982); const path_1 = __nccwpck_require__(6928); const os_1 = __nccwpck_require__(857); -// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP) -const baseUrl = 'https://api.github.com'; -const GitHubDotCom = core_1.Octokit.defaults({ - baseUrl, - request: { - agent: new httpClient.HttpClient().getAgent(baseUrl) - } -}); +const utils_1 = __nccwpck_require__(8006); async function exec(commandLine, args, options) { const exitCode = await (0, exec_1.exec)(commandLine, args, options); if (exitCode !== 0) { @@ -80509,18 +80500,14 @@ async function exec(commandLine, args, options) { } } async function getLatestRelease(repo) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/latest', { owner: c.GRAALVM_GH_USER, repo })).data; } async function getContents(repo, path) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { owner: c.GRAALVM_GH_USER, repo, @@ -80528,9 +80515,7 @@ async function getContents(repo, path) { })).data; } async function getTaggedRelease(owner, repo, tag) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { owner, repo, @@ -80538,9 +80523,7 @@ async function getTaggedRelease(owner, repo, tag) { })).data; } async function getMatchingTags(owner, repo, tagPrefix) { - const githubToken = getGitHubToken(); - const options = githubToken.length > 0 ? { auth: githubToken } : {}; - const octokit = new GitHubDotCom(options); + const octokit = getOctokit(); return (await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', { owner, repo, @@ -80608,15 +80591,23 @@ function toSemVer(version) { function isPREvent() { return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST; } -function getGitHubToken() { - return core.getInput(c.INPUT_GITHUB_TOKEN); +function getOctokit() { + /* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */ + const GitHubWithPlugins = utils_1.GitHub.plugin(); + const token = core.getInput(c.INPUT_GITHUB_TOKEN); + if (token) { + return new GitHubWithPlugins({ auth: `token ${token}` }); + } + else { + return new GitHubWithPlugins(); /* unauthenticated */ + } } async function findExistingPRCommentId(bodyStartsWith) { if (!isPREvent()) { throw new Error('Not a PR event.'); } const context = github.context; - const octokit = github.getOctokit(getGitHubToken()); + const octokit = getOctokit(); try { const comments = await octokit.paginate(octokit.rest.issues.listComments, { ...context.repo, @@ -80636,7 +80627,7 @@ async function updatePRComment(content, commentId) { throw new Error('Not a PR event.'); } try { - await github.getOctokit(getGitHubToken()).rest.issues.updateComment({ + await getOctokit().rest.issues.updateComment({ ...github.context.repo, comment_id: commentId, body: content @@ -80652,7 +80643,7 @@ async function createPRComment(content) { } const context = github.context; try { - await github.getOctokit(getGitHubToken()).rest.issues.createComment({ + await getOctokit().rest.issues.createComment({ ...context.repo, issue_number: context.payload.pull_request?.number, body: content diff --git a/package-lock.json b/package-lock.json index 24efd02a..bcc2969c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,6 @@ "@actions/io": "^1.1.3", "@actions/tool-cache": "^2.0.2", "@github/dependency-submission-toolkit": "^2.0.5", - "@octokit/core": "^5.2.0", "@octokit/types": "^14.1.0", "semver": "^7.7.2", "uuid": "^11.1.0" @@ -1177,19 +1176,32 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.3.1.tgz", - "integrity": "sha512-0J+zgWxHN+xXONWIyPWKFMgVuJoZuGiIFu8yxk7RJjxkzpGmyja5wRFqZIVtjDVOQpV+Rw0iOAjYPE2eQyjr0w==", + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.3.4.tgz", + "integrity": "sha512-Ul5l+lHEcw3L5+k8POx6r74mxEYKG5kOb6Xpy2gCRW6zweT6TEhAf8vhxGgjhqrd/VO/Dirhsb+1hNpD1ue9hw==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@eslint/core": "^0.14.0", + "@eslint/core": "^0.15.1", "levn": "^0.4.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/plugin-kit/node_modules/@eslint/core": { + "version": "0.15.1", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.15.1.tgz", + "integrity": "sha512-bkOp+iumZCCbt1K1CmWf0R9pM5yKpDv+ZXtvSyQpudrI9kuFLp+bM2WOPXImuD/ceQuaa8f5pj93Y7zyECIGNA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@fastify/busboy": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", @@ -5027,14 +5039,15 @@ } }, "node_modules/form-data": { - "version": "2.5.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.3.tgz", - "integrity": "sha512-XHIrMD0NpDrNM/Ckf7XJiBbLl57KEhT3+i3yY+eWm+cqYZJQTZrKo8Y8AWKnuV5GT4scfuUGt9LzNoIx3dU1nQ==", + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.5.tgz", + "integrity": "sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A==", "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", "mime-types": "^2.1.35", "safe-buffer": "^5.2.1" }, diff --git a/package.json b/package.json index b48f0cf6..32fa6426 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,6 @@ "@actions/http-client": "^2.2.3", "@actions/io": "^1.1.3", "@actions/tool-cache": "^2.0.2", - "@octokit/core": "^5.2.0", "@octokit/types": "^14.1.0", "@github/dependency-submission-toolkit": "^2.0.5", "semver": "^7.7.2", diff --git a/src/utils.ts b/src/utils.ts index c4edcd57..e071a9a3 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,25 +1,15 @@ import * as c from './constants' import * as core from '@actions/core' import * as github from '@actions/github' -import * as httpClient from '@actions/http-client' import * as semver from 'semver' import * as tc from '@actions/tool-cache' import * as fs from 'fs' import { ExecOptions, exec as e } from '@actions/exec' import { readFileSync, readdirSync } from 'fs' -import { Octokit } from '@octokit/core' import { createHash } from 'crypto' import { join } from 'path' import { tmpdir } from 'os' - -// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP) -const baseUrl = 'https://api.github.com' -const GitHubDotCom = Octokit.defaults({ - baseUrl, - request: { - agent: new httpClient.HttpClient().getAgent(baseUrl) - } -}) +import { GitHub } from '@actions/github/lib/utils' export async function exec(commandLine: string, args?: string[], options?: ExecOptions | undefined): Promise { const exitCode = await e(commandLine, args, options) @@ -29,9 +19,7 @@ export async function exec(commandLine: string, args?: string[], options?: ExecO } export async function getLatestRelease(repo: string): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/releases/latest', { owner: c.GRAALVM_GH_USER, @@ -41,9 +29,7 @@ export async function getLatestRelease(repo: string): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/contents/{path}', { owner: c.GRAALVM_GH_USER, @@ -58,9 +44,7 @@ export async function getTaggedRelease( repo: string, tag: string ): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', { owner, @@ -75,9 +59,7 @@ export async function getMatchingTags( repo: string, tagPrefix: string ): Promise { - const githubToken = getGitHubToken() - const options = githubToken.length > 0 ? { auth: githubToken } : {} - const octokit = new GitHubDotCom(options) + const octokit = getOctokit() return ( await octokit.request('GET /repos/{owner}/{repo}/git/matching-refs/tags/{tagPrefix}', { owner, @@ -156,8 +138,15 @@ export function isPREvent(): boolean { return process.env[c.ENV_GITHUB_EVENT_NAME] === c.EVENT_NAME_PULL_REQUEST } -function getGitHubToken(): string { - return core.getInput(c.INPUT_GITHUB_TOKEN) +function getOctokit(): InstanceType { + /* Set up GitHub instance manually because @actions/github does not allow unauthenticated access */ + const GitHubWithPlugins = GitHub.plugin() + const token = core.getInput(c.INPUT_GITHUB_TOKEN) + if (token) { + return new GitHubWithPlugins({ auth: `token ${token}` }) + } else { + return new GitHubWithPlugins() /* unauthenticated */ + } } export async function findExistingPRCommentId(bodyStartsWith: string): Promise { @@ -166,7 +155,7 @@ export async function findExistingPRCommentId(bodyStartsWith: string): Promise { } const context = github.context try { - await github.getOctokit(getGitHubToken()).rest.issues.createComment({ + await getOctokit().rest.issues.createComment({ ...context.repo, issue_number: context.payload.pull_request?.number as number, body: content diff --git a/tsconfig.json b/tsconfig.json index b65a760b..afd50ab6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "$schema": "https://json.schemastore.org/tsconfig", "extends": "./tsconfig.base.json", "compilerOptions": { + "isolatedModules": true, "module": "NodeNext", "moduleResolution": "NodeNext", "outDir": "./dist"