Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes docs workflow failing when no branch previews exist #4632

Merged
merged 4 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
contents: write # for git push
name: Cleanup branch previews
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -35,18 +35,26 @@ jobs:
run: |
pushd $GITHUB_WORKSPACE/gh-pages

for name in `ls branch/`
do
if [[ -z "$(git show-ref --quiet ${name})" ]]
then
git rm -rf branch/${name}
fi
done
if [[ -e "$GITHUB_WORKSPACE/gh-pages/branch" ]]; then
ls -la "$GITHUB_WORKSPACE/gh-pages/branch"

git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git commit -m "Clean up branch previews"
git push
for name in `ls branch/`
do
if [[ -z "$(git show-ref --quiet ${name})" ]]
then
git rm -rf branch/${name}

echo "Removed $GITHUB_WORKSPACE/gh-pages/branch/${name}"
fi
done

git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git commit -m "Clean up branch previews"
git push
fi

echo "Done cleaning branches"
build-and-deploy:
permissions:
contents: write # for peaceiris/actions-gh-pages to push
Expand Down
Loading