Skip to content

9. Delete old workflow runs #33

9. Delete old workflow runs

9. Delete old workflow runs #33

name: "9. Delete old workflow runs"
on:
schedule:
# Run monthly, at 00:00 on the 1st day of month.
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html#tag_20_25_07
- cron: '0 0 1 * *'
# Allow manual triggering
workflow_dispatch:
inputs:
retain_days:
description: 'Delete runs older than this many days'
required: true
type: string
default: 30
min_runs:
description: 'Minimum runs to keep'
required: true
type: string
default: 20
jobs:
gate-check:
# Adding an `if:` that evaluates to false for this gate-check job prevents other dependent jobs from running.
runs-on: ubuntu-latest
steps:
- id: checkUserMember
# Only check for manual runs, not scheduled runs
if: github.event_name == 'workflow_dispatch'
uses: tspascoal/[email protected]
with:
username: ${{ github.actor }}
team: 'vro-restricted'
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN_READ_TEAM }}
- name: "Check permission"
id: check-permission
# Only check for manual runs, not scheduled runs
if: github.event_name == 'workflow_dispatch'
run: |
echo "${{ github.actor }} isTeamMember: ${{ steps.checkUserMember.outputs.isTeamMember }}"
echo "Member of teams: ${{ steps.checkUserMember.outputs.teams }}"
if [ ${{ steps.checkUserMember.outputs.isTeamMember }} = 'false' ]; then
echo "Only VRO-RESTRICTED team members can run this action!" | tee -a "$GITHUB_STEP_SUMMARY"
exit 3
fi
delete_runs:
needs: gate-check
runs-on: ubuntu-latest
steps:
- name: "Delete old workflow runs"
uses: Mattraks/delete-workflow-runs@v2
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ inputs.retain_days || 30 }}
keep_minimum_runs: ${{ inputs.min_runs || 20 }}