Skip to content

EVM PA Documentation Update #183

EVM PA Documentation Update

EVM PA Documentation Update #183

Workflow file for this run

name: clean up and delete PR previews
on:
pull_request:
types:
- closed
concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.run_id }}"
cancel-in-progress: true
permissions:
contents: write
pull-requests: write
repository-projects: write
env:
GH_TOKEN: ${{ github.token }}
BRANCH_NUMBER: ${{ github.event.pull_request.number }}
GIT_COMMITTER_EMAIL: [email protected]
GIT_COMMITTER_NAME: Anoma Research
REPO: anoma/nspec
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PAGES_TOKEN }}
repository: anoma/specs.anoma.net
ref: main
clean: true
fetch-depth: 0
- name: List directories
run: ls -la
- name: Delete PR branch
run: |
if [ -d "pr-${{ env.BRANCH_NUMBER }}" ]; then
echo "Directory pr-${{ env.BRANCH_NUMBER }} exists. Deleting..."
git config --global user.name "${{ env.GIT_COMMITTER_NAME }}"
git config --global user.email "${{ env.GIT_COMMITTER_EMAIL }}"
git checkout --orphan new
git rm -rf "pr-${{ env.BRANCH_NUMBER }}"
git commit -m "Delete PR preview for PR #${{ env.BRANCH_NUMBER }}"
git branch -M main
git push -f
else
echo "Directory pr-${{ env.BRANCH_NUMBER }} does not exist. Skipping deletion."
fi
- name: Delete the PR preview if the PR is closed or merged (Pull Request)
run: |-
gh pr -R ${{ env.REPO }} comment ${{ env.BRANCH_NUMBER }} --edit-last --body "The preview of this PR has been deleted."
continue-on-error: true
- name: Cleanup cache
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}