diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml new file mode 100644 index 0000000..3a5a419 --- /dev/null +++ b/.github/workflows/clean.yml @@ -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}"`) + } diff --git a/.github/workflows/close.yml b/.github/workflows/close.yml new file mode 100644 index 0000000..670c7c3 --- /dev/null +++ b/.github/workflows/close.yml @@ -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