Detect deletion of slides #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Verify Deleted Slide Entries | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
jobs: | |
verify-deleted-slides: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install dependencies | |
run: | | |
# Install your dependencies here. | |
- name: Check if it's a pull request event | |
id: check-pr-event | |
run: | | |
if [ -n "$GITHUB_EVENT_NAME" ] && [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then | |
echo "is_pull_request=true" >> $GITHUB_ENV | |
else | |
echo "is_pull_request=false" >> $GITHUB_ENV | |
fi | |
- name: Get base branch | |
id: base-branch | |
run: | | |
is_pull_request="${{ env.is_pull_request }}" | |
if [ "$is_pull_request" == "true" ]; then | |
base_branch=$(jq -r .pull_request.base.ref "$GITHUB_EVENT_PATH") | |
echo "base_branch=$base_branch" >> $GITHUB_ENV | |
else | |
echo "base_branch=" >> $GITHUB_ENV | |
fi | |
- name: Set deleted slides in an environment file | |
run: | | |
base_branch="${{ env.base_branch }}" | |
if [ -n "$base_branch" ]; then | |
echo "DELETED_SLIDES=$(git diff --name-only \"$base_branch\"...HEAD --diff-filter=D)" >> $GITHUB_ENV | |
fi | |
- name: Check for entries in book.toml | |
run: | | |
deleted_slides="$DELETED_SLIDES" | |
for slide in $deleted_slides; do | |
slide_filename=$(basename -- "$slide") | |
slide_name="${slide_filename%.*}" | |
entry_exists=$(grep -c "\[slide.$slide_name\]" book.toml) | |
if [ $entry_exists -eq 0 ]; then | |
echo "Error: Entry for slide $slide_name not found in book.toml" | |
exit 1 | |
fi | |
done |