-
Notifications
You must be signed in to change notification settings - Fork 13
73 lines (61 loc) · 2.1 KB
/
pr-cleanup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: cleanup PR
# on:
# pull_request_target:
# types: [closed]
on: [pull_request_target]
permissions: {}
defaults:
run:
shell: "bash"
jobs:
clean-artifacts:
if: always()
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Clean artifacts
run: |
set -u
ARTIFACTS=$(
gh api \
--paginate \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/probabl-ai/skore/actions/artifacts \
|
jq -c ".artifacts[] | select(.workflow_run.head_branch == \"${BRANCH}\") | {id: .id, name: .name}"
)
for ARTIFACT in $ARTIFACTS; do
ID=$(echo "${ARTIFACT}" | jq -r '.id')
NAME=$(echo "${ARTIFACT}" | jq -r '.name')
echo "Deleting artifact (BRANCH: \"${BRANCH}\", NAME: \"${NAME}\", ID: \"${ID}\")"
gh api \
--method DELETE \
--silent \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${REPOSITORY_OWNER}/${REPOSITORY_NAME}/actions/artifacts/${ID}
done
env:
GH_TOKEN: ${{ github.token }}
REPOSITORY_OWNER: ${{ github.repository_owner }}
REPOSITORY_NAME: ${{ github.event.repository.name }}
BRANCH: ${{ github.head_ref }}
clean-documentation-preview:
if: always()
runs-on: ubuntu-latest
steps:
- shell: bash
run: |
sudo apt-get update
sudo apt-get install -y rclone
- shell: bash
run: echo "${CONFIGURATION}" > rclone.configuration
env:
CONFIGURATION: ${{ secrets.RCLONE_CONFIG_DOC_PREVIEW }}
- name: Clean documentation preview
run: rclone --config rclone.configuration purge ${PROVIDER}:${BUCKET}/${PULL_REQUEST_NUMBER}/ -v
env:
PROVIDER: scaleway
BUCKET: ${{ vars.DOCUMENTATION_PREVIEW_BUCKET }}
PULL_REQUEST_NUMBER: ${{ github.event.number }}