Skip to content

add-to-project workflow: Fix assignment of reviewers also when PR is still in draft mode #26

add-to-project workflow: Fix assignment of reviewers also when PR is still in draft mode

add-to-project workflow: Fix assignment of reviewers also when PR is still in draft mode #26

name: clean up storage by a branch
on:
pull_request:
types:
- closed
workflow_call:
jobs:
cleanup-action-cache:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Cleanup
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 }}
cleanup-action-artefact:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Cleanup
run: |
REPO=${{ github.repository }}
echo "cleaning up repo: $REPO branch: $GITHUB_HEAD_REF"
sudo apt install -y jq
while true; do
# Retrieve a page of artifacts
ART_EXIST=$(gh api repos/$REPO/actions/artifacts?per_page=100\&page=$PAGE | jq -r '.artifacts[]')
ARTIFACTS=$(gh api repos/$REPO/actions/artifacts?per_page=100\&page=$PAGE | jq -r '.artifacts[] | select(.workflow_run.head_branch =="'"$GITHUB_HEAD_REF"'" ) | .id')
echo "page: $PAGE"
# If there are no more artifacts, exit the loop
if [[ -z "$ART_EXIST" ]]; then
break
fi
# Loop through the artifacts on this page and delete the old ones
for ARTIFACT_ID in $ARTIFACTS; do
ARTIFACT_NAME=$(gh api repos/$REPO/actions/artifacts/$ARTIFACT_ID | jq -r '.name')
echo "Deleting artifact $ARTIFACT_NAME (ID: $ARTIFACT_ID)..."
gh api repos/$REPO/actions/artifacts/$ARTIFACT_ID -X DELETE
done
# Increment the page counter
PAGE=$((PAGE+1))
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}