Skip to content

Remove stale branches from docs. #1246

Remove stale branches from docs.

Remove stale branches from docs. #1246

name: Remove stale branches from docs.
# Triggers on deletion of a ref type.
on:
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 0 * * *'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "delete"
delete:
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
TARGET_BRANCH: gh-pages
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# https://github.com/actions/checkout#readme
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
ref: ${{ env.TARGET_BRANCH }}
# Look at the 'gh-pages' directory to see if everything looks right.
- run: |
git fetch --quiet
branches=()
eval "$(git for-each-ref --shell --format='branches+=(%(refname:lstrip=3))' refs/remotes/origin)"
branches=("${branches[@]//\//_}")
directories=($GITHUB_WORKSPACE/branches/*/)
directories=("${directories[@]%/}")
directories=("${directories[@]##*/}")
for directory in ${directories[@]} ; do
echo "Checking $directory"
if [[ ! " ${branches[@]} " =~ " ${directory} " ]]; then
echo "Removing $directory"
rm -r $GITHUB_WORKSPACE/branches/$directory
fi
done
# https://github.com/JamesIves/github-pages-deploy-action#readme
- name: Deploy docs 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: ${{ env.TARGET_BRANCH }} # The branch the action should deploy to.
folder: branches
target-folder: branches