Skip to content

Weekly Cleanup

Weekly Cleanup #21

Workflow file for this run

name: Weekly Cleanup
on:
schedule:
- cron: "0 0 * * 0,3"
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout for PR list
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: List open PRs
id: open_prs
run: |
OPEN_PRS=$(gh pr list --state open --json number --jq '.[].number')
echo "open_prs=$OPEN_PRS" >> $GITHUB_ENV
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout schematic-previews
uses: actions/checkout@v4
with:
ref: schematic-previews
path: sch-previews
- name: Clean schematic-previews branch
run: |
echo "$open_prs" | tr ' ' '\n' > /tmp/open_prs.txt
for f in $(find . -type f -not -path "./.git/*"); do
if [[ $f =~ schematic-.*-([0-9]+):[a-f0-9]+\.png ]]; then
prnum="${BASH_REMATCH[1]}"
if ! grep -q "^$prnum$" /tmp/open_prs.txt; then
if [[ -e "$f" || -L "$f" ]]; then
echo "Deleting $f (PR #$prnum closed)"
rm -rf "$f"
fi
fi
else
if [[ -e "$f" || -L "$f" ]]; then
echo "Deleting $f (does not match schematic preview pattern)"
rm -rf "$f"
fi
fi
done
find . -name "*.png" -exec mv -v '{}' . \; || true
rm -rf sch-previews
git config user.name "actions-cleanup[bot]"
git config user.email "actions-cleanup[bot]@users.noreply.github.com"
git checkout --orphan temp-clean
git rm -rf . > /dev/null 2>&1 || true
git add ./*.png 2>/dev/null || true
git commit --allow-empty -m "Cleanup schematic previews" || echo "No changes"
git branch -M schematic-previews
git push -f origin schematic-previews
env:
open_prs: ${{ env.open_prs }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout layout-previews
uses: actions/checkout@v4
with:
ref: layout-previews
path: pcb-previews
- name: Clean layout-previews branch
run: |
echo "$open_prs" | tr ' ' '\n' > /tmp/open_prs.txt
for f in $(find . -type f -not -path "./.git/*"); do
if [[ $f =~ layout-.*-([0-9]+):[a-f0-9]+\.png ]]; then
prnum="${BASH_REMATCH[1]}"
if ! grep -q "^$prnum$" /tmp/open_prs.txt; then
if [[ -e "$f" || -L "$f" ]]; then
echo "Deleting $f (PR #$prnum closed)"
rm -rf "$f"
fi
fi
else
if [[ -e "$f" || -L "$f" ]]; then
echo "Deleting $f (does not match layout preview pattern)"
rm -rf "$f"
fi
fi
done
find . -name "*.png" -exec mv -v '{}' . \; || true
rm -rf pcb-previews
git config user.name "actions-cleanup[bot]"
git config user.email "actions-cleanup[bot]@users.noreply.github.com"
git checkout --orphan temp-clean
git rm -rf . > /dev/null 2>&1 || true
git add ./*.png 2>/dev/null || true
git commit --allow-empty -m "Cleanup layout previews" || echo "No changes"
git branch -M layout-previews
git push -f origin layout-previews
env:
open_prs: ${{ env.open_prs }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}