-
Notifications
You must be signed in to change notification settings - Fork 10
112 lines (91 loc) · 4.36 KB
/
remove-wheels.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Remove old wheels
on:
# Run daily at 1:23 UTC
schedule:
- cron: '23 1 * * *'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Needed for micromamba pickup
defaults:
run:
shell: bash -l {0}
env:
N_LATEST_UPLOADS: 5
ANACONDA_USER: "scientific-python-nightly-wheels"
jobs:
remove:
runs-on: ubuntu-latest
if: github.repository_owner == 'scientific-python'
# Set required workflow secrets in the environment for additional security
# https://github.com/scientific-python/upload-nightly-action/settings/environments
environment:
name: remove-old-wheels
steps:
- name: Install micromamba and anaconda-client
uses: mamba-org/setup-micromamba@06375d89d211a1232ef63355742e9e2e564bc7f7 # v2.0.2
with:
environment-name: remove-wheels
create-args: >-
python=3.12
anaconda-client=1.12.3
curl
jq
- name: Show environment
run: env
- name: Show CLI API info
run: |
anaconda show --help
echo ""
anaconda remove --help
- name: Query package index for packages
run: |
curl https://raw.githubusercontent.com/scientific-python/upload-nightly-action/main/packages-ignore-from-cleanup.txt --output packages-ignore-from-cleanup.txt
anaconda show "${ANACONDA_USER}" &> >(grep "${ANACONDA_USER}/") | \
awk '{print $1}' | \
sed 's|.*/||g' | \
grep -vf packages-ignore-from-cleanup.txt > package-names.txt
- name: Remove old uploads to save space
run: |
# Remove all _but_ the last ${N_LATEST_UPLOADS} package versions and
# remove all package versions older than 30 days.
if [ -s package-names.txt ]; then
threshold_date="$(date +%F -d '30 days ago')"
# Remember can't quote subshell as need to split on (space seperated) token
for package_name in $(cat package-names.txt); do
echo -e "\n# package: ${package_name}"
curl --silent https://api.anaconda.org/package/"${ANACONDA_USER}/${package_name}" | \
jq -r '.releases[].version' > package-versions.txt
head --lines "-${N_LATEST_UPLOADS}" package-versions.txt > remove-package-versions.txt
for package_version in $(cat package-versions.txt); do
# c.f. https://github.com/Anaconda-Platform/anaconda-client/issues/682#issuecomment-1677283067
upload_date=$(curl --silent https://api.anaconda.org/release/"${ANACONDA_USER}/${package_name}/${package_version}" | \
jq -r '.distributions[].upload_time' | \
sort | \
tail --lines 1 | \
awk '{print $1}')
# check upload_date is YYYY-MM-DD formatted
# c.f. https://github.com/scientific-python/upload-nightly-action/issues/73
if [[ "${upload_date}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then
if [[ "${upload_date}" < "${threshold_date}" ]]; then
echo "# ${ANACONDA_USER}/${package_name}/${package_version} last uploaded on ${upload_date}"
echo "${package_version}" >> remove-package-versions.txt
fi
else
echo "# ERROR: ${ANACONDA_USER}/${package_name}/${package_version} upload date ${upload_date} is not YYYY-MM-DD."
fi
done
if [ -s remove-package-versions.txt ]; then
# Guard against duplicate entries from packages over
# count and time thresholds
sort --output remove-package-versions.txt --unique remove-package-versions.txt
for package_version in $(cat remove-package-versions.txt); do
echo "# Removing ${ANACONDA_USER}/${package_name}/${package_version}"
anaconda --token ${{ secrets.ANACONDA_TOKEN }} remove \
--force \
"${ANACONDA_USER}/${package_name}/${package_version}"
done
fi
done
fi