Skip to content

.github/workflows/clean_docs.yml #132

.github/workflows/clean_docs.yml

.github/workflows/clean_docs.yml #132

Workflow file for this run

on:
delete:
branches:
- '*'
jobs:
delete_docs_folder:
if: github.event.ref_type == 'branch'
name: Remove corresponding documentation folder in DOAJ/doaj-docs when a branch is deleted
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout the doaj-docs repository
uses: actions/checkout@v4
with:
path: doaj-docs
repository: DOAJ/doaj-docs
token: ${{ secrets.STEVE_PAT_DOAJ_ACTIONS_DOCS }}
fetch-depth: 0
- name: Delete corresponding folder
env:
BRANCH_NAME: ${{ github.event.ref }}
run: |
FOLDER_PATH="${{ env.BRANCH_NAME }}"
BASE_FOLDER=$(dirname "$FOLDER_PATH")
TARGET_FOLDER=$(basename "$FOLDER_PATH")
echo "Cleaning up docs for branch $FOLDER_PATH"
# Check if base folder and target folder exist
if [ -d "$GITHUB_WORKSPACE/doaj-docs/$BASE_FOLDER" ]; then
cd $GITHUB_WORKSPACE/doaj-docs/$BASE_FOLDER
if [ -d "$TARGET_FOLDER" ]; then
rm -rf "$TARGET_FOLDER"
echo "Deleted folder $TARGET_FOLDER"
cd $GITHUB_WORKSPACE/doaj-docs
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "deleted: $TARGET_FOLDER"
git push origin master
else
echo "$FOLDER_PATH doesn't have a corresponding folder in doaj-docs"
fi
else
echo "$FOLDER_PATH doesn't have a corresponding folder in doaj-docs"
fi