-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: thxCode <[email protected]>
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: clean | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: read | ||
actions: write | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
on: | ||
workflow_dispatch: { } | ||
schedule: | ||
- cron: "0 0 * * *" # every day at 00:00 UTC | ||
|
||
jobs: | ||
clean: | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-22.04 | ||
continue-on-error: true | ||
steps: | ||
- name: Remove Cache | ||
uses: actions/github-script@v7 | ||
with: | ||
# clean up caches, | ||
# ref to https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries, | ||
# and https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache. | ||
script: | | ||
const owner = context.repo.owner | ||
const repo = context.repo.repo | ||
var deleteCaches = new Array() | ||
// get candidate items. | ||
const { data: cs } = await github.rest.actions.getActionsCacheList({ | ||
owner: owner, | ||
repo: repo, | ||
}); | ||
for (const c of cs.actions_caches) { | ||
// clean closed pull request caches. | ||
if (c.ref.match(/^refs\/pull\/.*$/)) { | ||
var prNum = c.ref.replace(/[^\d]/g, "") | ||
const { data: pr } = await github.rest.pulls.get({ | ||
owner: owner, | ||
repo: repo, | ||
pull_number: prNum, | ||
}) | ||
if (pr.state === 'closed') { | ||
deleteCaches.push(c) | ||
} | ||
continue | ||
} | ||
${{ github.event.schedule || '// clean main branch caches' }} | ||
${{ github.event.schedule || 'deleteCaches.push(c)' }} | ||
} | ||
// delete | ||
for (const c of deleteCaches) { | ||
await github.rest.actions.deleteActionsCacheById({ | ||
owner: owner, | ||
repo: repo, | ||
cache_id: c.id, | ||
}) | ||
console.log(`cleaned cache "${c.key}"`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: close | ||
|
||
permissions: | ||
pull-requests: write | ||
issues: write | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
on: | ||
workflow_dispatch: { } | ||
schedule: | ||
- cron: "0 0 * * *" # every day at 00:00 UTC | ||
|
||
jobs: | ||
close: | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-22.04 | ||
continue-on-error: true | ||
steps: | ||
- name: Close Stale Issues and Pull Requests | ||
uses: actions/stale@v9 | ||
with: | ||
days-before-stale: 15 | ||
days-before-close: 14 | ||
exempt-issue-labels: "help wanted,good first issue,bug,bug-qa,enhancement" | ||
stale-issue-label: "stale" | ||
close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." | ||
exempt-pr-labels: "bug,bug-qa,enhancement" | ||
exempt-draft-pr: true | ||
stale-pr-label: "stale" | ||
close-pr-message: "This pull request was closed because it has been inactive for 14 days since being marked as stale." | ||
operations-per-run: 10000 |