2022-12-30 06:56:27 +01:00
|
|
|
# Simple job to clear the cache used by a workflow. This automatically runs when a PR is closed/merged
|
|
|
|
# to clean up the corresponding PR's cache.
|
2022-11-06 09:44:02 +01:00
|
|
|
|
2022-12-30 06:56:27 +01:00
|
|
|
name: "clear workflow cache"
|
2022-11-06 09:44:02 +01:00
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
id:
|
2023-05-04 07:22:28 +02:00
|
|
|
description: "Which id to clear. Type main/master/all to clean all, and keep-main/keep-master to clean all but the main branch."
|
2022-11-06 09:44:02 +01:00
|
|
|
required: false
|
|
|
|
pull_request:
|
|
|
|
types:
|
|
|
|
- closed
|
2023-01-13 07:45:11 +01:00
|
|
|
schedule:
|
2023-04-02 23:36:51 +02:00
|
|
|
- cron: "0 11 * * 0"
|
2022-11-06 09:44:02 +01:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
clear-cache:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
env:
|
|
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
steps:
|
2022-11-06 09:46:51 +01:00
|
|
|
- name: Checkout repository
|
2023-11-19 01:15:28 +01:00
|
|
|
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
|
2022-11-06 09:46:51 +01:00
|
|
|
with:
|
|
|
|
fetch-depth: 1
|
|
|
|
|
2023-04-11 10:39:28 +02:00
|
|
|
# We run each script twice with a small delay in between to try and catch everything.
|
|
|
|
- name: Clear cache
|
|
|
|
run: |
|
2023-01-13 07:45:11 +01:00
|
|
|
if [[ -n "${{ github.event.schedule }}" ]]; then
|
2023-12-06 06:16:26 +01:00
|
|
|
python ./scripts/clear_cache.py keep-main
|
2023-04-11 10:39:28 +02:00
|
|
|
sleep 5
|
2023-12-06 06:16:26 +01:00
|
|
|
python ./scripts/clear_cache.py keep-main
|
2023-01-13 07:45:11 +01:00
|
|
|
elif [[ -z "${{ github.event.inputs.id }}" ]]; then
|
2022-11-06 09:44:02 +01:00
|
|
|
python ./scripts/clear_cache.py ${{ github.event.pull_request.number }}
|
2023-04-11 10:39:28 +02:00
|
|
|
sleep 5
|
|
|
|
python ./scripts/clear_cache.py ${{ github.event.pull_request.number }}
|
2022-11-06 09:44:02 +01:00
|
|
|
else
|
|
|
|
python ./scripts/clear_cache.py ${{ github.event.inputs.id }}
|
2023-04-11 10:39:28 +02:00
|
|
|
sleep 5
|
|
|
|
python ./scripts/clear_cache.py ${{ github.event.inputs.id }}
|
2022-11-06 09:44:02 +01:00
|
|
|
fi
|