Delete Visual Tests Reports #3096
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
# This workflow is triggered when a branch is deleted, except for master, main, and gh-pages. | |
# The visual tests reports for the deleted branch are removed from the gh-pages branch. This is to ensure that the reports are not visible on the website after the branch is deleted and to reduce the size of the repository. | |
# The workflow also removes branches that may have been automatically added to Netlify's branch deploy list. | |
# It's common for release related branches to be added to the Netlify branch deploy list. Otherwise, if not part of the deploy list, the branch will not receive a Netlify deploy preview URL. | |
name: Delete Visual Tests Reports | |
on: | |
delete: | |
branches-ignore: [master, main, gh-pages] | |
env: | |
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} | |
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} | |
GITHUB_BRANCH: ${{ github.event.ref }} | |
concurrency: | |
group: ${{ github.event.ref }} | |
cancel-in-progress: true | |
jobs: | |
update_netlify: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout GitHub Pages Branch | |
uses: actions/checkout@v4 | |
- name: Remove Branch From Netlify | |
run: cd scripts && ./netlify_remove_branch.sh | |
delete_reports: | |
name: Delete Reports | |
runs-on: ubuntu-latest | |
env: | |
# Contains all reports for deleted branch | |
BRANCH_REPORTS_DIR: reports/${{ github.event.ref }} | |
steps: | |
- name: Checkout GitHub Pages Branch | |
uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
- name: Set Git User | |
# see: https://github.com/actions/checkout/issues/13#issuecomment-724415212 | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
- name: Check for workflow reports | |
run: | | |
if [ -z "$(ls -A $BRANCH_REPORTS_DIR)" ]; then | |
echo "BRANCH_REPORTS_EXIST="false"" >> $GITHUB_ENV | |
else | |
echo "BRANCH_REPORTS_EXIST="true"" >> $GITHUB_ENV | |
fi | |
- name: Delete reports from repo for branch | |
if: ${{ env.BRANCH_REPORTS_EXIST == 'true' }} | |
timeout-minutes: 3 | |
run: | | |
cd $BRANCH_REPORTS_DIR/.. | |
rm -rf ${{ github.event.ref }} | |
git add . | |
git commit -m "workflow: remove all reports for branch ${{ github.event.ref }}" | |
while true; do | |
git pull --rebase | |
if [ $? -ne 0 ]; then | |
echo "Failed to rebase. Please review manually." | |
exit 1 | |
fi | |
git push | |
if [ $? -eq 0 ]; then | |
echo "Successfully pushed HTML reports to repo." | |
exit 0 | |
fi | |
done |