Skip to content

Commit

Permalink
fix: refの指定方法を修正
Browse files Browse the repository at this point in the history
pull_requestやissueの番号をいい感じに取る方法が見つからなかったのでpayloadから取得するようにした
  • Loading branch information
hulk510 committed Jan 17, 2024
1 parent 088ef69 commit 148befd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
39 changes: 26 additions & 13 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const deleteRefActionsCache = async (
}
)

// https://github.com/octokit/octokit.js/tree/b831b6bce43d56b97e25a996e1b43525486d8bd3?tab=readme-ov-file#pagination
for await (const { data: cacheList } of iterator) {
for (const { id: cacheId } of cacheList) {
if (!cacheId) continue
Expand All @@ -35,17 +36,34 @@ export async function run(): Promise<void> {
try {
const token = core.getInput('repo-token')
const octokit = github.getOctokit(token)
// get context
// MEMO: git contextからheadRefは取得できなそう
const { repo, ref } = github.context

const headRef = process.env.GITHUB_HEAD_REF
core.debug(`headRef: ${headRef}`)
// get repostiory information
const { repo } = github.context

// MEMO: payloadから取得できるのは確認したけど、型何もついてない
const payload = github.context.payload
const prNumber = payload.pull_request?.number as number | undefined

Check failure on line 45 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

This assertion is unnecessary since it does not change the type of the expression

Check failure on line 45 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

This assertion is unnecessary since it does not change the type of the expression
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`)
await deleteRefActionsCache(octokit, repo, `refs/pull/${prNumber}/merge`)
core.info('done ✅')
}
if (headRef) {
deleteRefActionsCache(octokit, repo, 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}`)
await deleteRefActionsCache(octokit, repo, `refs/heads/${headRef}`)
core.info('done ✅')
}
if (ref) {
// fire when event is workflow_dispatch or push
core.info(`delete cache for ${ref}`)
await deleteRefActionsCache(octokit, repo, ref)
core.info('done ✅')
}
deleteRefActionsCache(octokit, repo, ref)
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit 148befd

Please sign in to comment.