From e7e91fdc79120b19d7ed8e5ad7f37197ec86c35e Mon Sep 17 00:00:00 2001 From: hulk510 Date: Thu, 18 Jan 2024 01:26:30 +0900 Subject: [PATCH] test5 --- dist/index.js | 29 ++++++++++++++++------------- src/main.ts | 35 ++++++++++++++++------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0032211f..52f6fa7b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29679,25 +29679,28 @@ async function run() { try { const token = core.getInput('repo-token'); const octokit = github.getOctokit(token); - // get context - // MEMO: git contextからheadRefは取得できなそう - const { repo, ref } = github.context; - core.info(`ref: ${ref}`); - core.info(`payload: ${JSON.stringify(github.context.payload)}`); - core.info(`number: ${JSON.stringify(github.context.payload.pull_request?.number)}`); - core.info(`head ref: ${JSON.stringify(github.context.payload.pull_request?.head.ref)}`); - // const eventPath = process.env.GITHUB_EVENT_PATH - const headRef = process.env.GITHUB_HEAD_REF; - core.info(`headRef: ${headRef}`); - const prNumber = github.context.payload.pull_request?.number; + // get repostiory information + const { repo } = github.context; + // MEMO: payloadから取得できるのは確認したけど、型何もついてない + const payload = github.context.payload; + const prNumber = payload.pull_request?.number; + const headRef = payload.pull_request?.head?.ref; + const ref = payload.ref; if (prNumber) { + // fire when event is pull_request or pull_request_target or pull_request_review or pull_request_review_comment + core.info(`delete cache for refs/pull/${prNumber}/merge`); deleteRefActionsCache(octokit, repo, `refs/pull/${prNumber}/merge`); } if (headRef) { + // fire when event is pull_request or pull_request_target or pull_request_review or pull_request_review_comment + core.info(`delete cache for refs/heads/${headRef}`); deleteRefActionsCache(octokit, repo, `refs/heads/${headRef}`); } - // workflow_dispatch or push - deleteRefActionsCache(octokit, repo, ref); + if (ref) { + // fire when event is workflow_dispatch or push + core.info(`delete cache for ${ref}`); + deleteRefActionsCache(octokit, repo, ref); + } } catch (error) { // Fail the workflow run if an error occurs diff --git a/src/main.ts b/src/main.ts index b5c0e3a2..048b7a6e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,34 +36,31 @@ export async function run(): Promise { try { const token = core.getInput('repo-token') const octokit = github.getOctokit(token) - // get context - // MEMO: git contextからheadRefは取得できなそう - const { repo, ref } = github.context - core.info(`ref: ${ref}`) - core.info(`payload: ${JSON.stringify(github.context.payload)}`) - core.info( - `number: ${JSON.stringify(github.context.payload.pull_request?.number)}` - ) - core.info( - `head ref: ${JSON.stringify( - github.context.payload.pull_request?.head.ref - )}` - ) - // const eventPath = process.env.GITHUB_EVENT_PATH + // get repostiory information + const { repo } = github.context - const headRef = process.env.GITHUB_HEAD_REF - core.info(`headRef: ${headRef}`) - const prNumber = github.context.payload.pull_request?.number + // MEMO: payloadから取得できるのは確認したけど、型何もついてない + const payload = github.context.payload + const prNumber = payload.pull_request?.number as number | undefined + const headRef = payload.pull_request?.head?.ref as string | undefined + const ref = payload.ref as string | undefined if (prNumber) { + // fire when event is pull_request or pull_request_target or pull_request_review or pull_request_review_comment + core.info(`delete cache for refs/pull/${prNumber}/merge`) deleteRefActionsCache(octokit, repo, `refs/pull/${prNumber}/merge`) } if (headRef) { + // fire when event is pull_request or pull_request_target or pull_request_review or pull_request_review_comment + core.info(`delete cache for refs/heads/${headRef}`) deleteRefActionsCache(octokit, repo, `refs/heads/${headRef}`) } - // workflow_dispatch or push - deleteRefActionsCache(octokit, repo, ref) + if (ref) { + // fire when event is workflow_dispatch or push + core.info(`delete cache for ${ref}`) + deleteRefActionsCache(octokit, repo, ref) + } } catch (error) { // Fail the workflow run if an error occurs if (error instanceof Error) core.setFailed(error.message)