Skip to content

Commit

Permalink
ci: close and clean
Browse files Browse the repository at this point in the history
Signed-off-by: thxCode <[email protected]>
  • Loading branch information
thxCode committed Sep 18, 2024
1 parent ee6d366 commit 83a7875
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/clean.yml
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}"`)
}
34 changes: 34 additions & 0 deletions .github/workflows/close.yml
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

0 comments on commit 83a7875

Please sign in to comment.