Skip to content

Commit 39a51bb

Browse files
committed
Add cleanup workflow when closing PR
1 parent 3626bb5 commit 39a51bb

File tree

2 files changed

+68
-28
lines changed

2 files changed

+68
-28
lines changed

.github/workflows/pr-cleanup.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: cleanup PR
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
permissions: {}
8+
9+
defaults:
10+
run:
11+
shell: "bash"
12+
13+
jobs:
14+
clean-artifacts:
15+
if: always()
16+
runs-on: ubuntu-latest
17+
continue-on-error: true
18+
steps:
19+
- name: Clean artifacts
20+
run: |
21+
set -eu
22+
23+
ARTIFACTS=$(
24+
gh api \
25+
--paginate \
26+
-H "Accept: application/vnd.github+json" \
27+
-H "X-GitHub-Api-Version: 2022-11-28" \
28+
/repos/probabl-ai/skore/actions/artifacts \
29+
|
30+
jq -c ".artifacts[] | select(.workflow_run.head_branch == \"${BRANCH}\") | {id: .id, name: .name}"
31+
)
32+
33+
for ARTIFACT in $ARTIFACTS; do
34+
ID=$(echo "${ARTIFACT}" | jq -r '.id')
35+
NAME=$(echo "${ARTIFACT}" | jq -r '.name')
36+
37+
echo "Deleting artifact (BRANCH: \"${BRANCH}\", NAME: \"${NAME}\", ID: \"${ID}\")"
38+
39+
gh api \
40+
--method DELETE \
41+
--silent \
42+
-H "Accept: application/vnd.github+json" \
43+
-H "X-GitHub-Api-Version: 2022-11-28" \
44+
/repos/${OWNER}/${REPOSITORY}/actions/artifacts/${ID}
45+
done
46+
env:
47+
GH_TOKEN: ${{ github.token }}
48+
OWNER: ${{ github.repository_owner }}
49+
REPOSITORY: ${{ github.repository.name }}
50+
BRANCH: ${{ github.head_ref }}
51+
52+
clean-documentation-preview:
53+
if: always()
54+
runs-on: ubuntu-latest
55+
continue-on-error: true
56+
steps:
57+
- name: Clean documentation preview
58+
run: |
59+
set -eu
60+
sudo apt-get update
61+
sudo apt-get install -y rclone
62+
echo "${{ inputs.CONFIGURATION }}" > rclone.configuration
63+
rclone --config rclone.configuration prune ${PROVIDER}:${BUCKET}/${PULL_REQUEST_NUMBER}/
64+
env:
65+
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }}
66+
PROVIDER: scaleway
67+
BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }}
68+
PULL_REQUEST_NUMBER: ${{ github.event.number }}

cleanup.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)