annotate contrib/cleanup-pipeline.sh @ 52313:56e8841a454c default tip

rust: remove `atty` dependency It is fully replaced with the now stable `std::io::IsTerminal` trait. This was the last dependency flagged as a warning by `cargo audit`, aside from `cpython` which we know about all too well: the plan is to transition to PyO3 soon-ish.
author Raphaël Gomès <rgomes@octobus.net>
date Mon, 04 Nov 2024 15:28:32 +0100
parents 77b38c86915d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52293
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 #!/bin/bash
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2 # A small script to cleanup old CI-pipeline that accumulate over time
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 d="`date -d '-1 month' --iso-8601`T00:00:00Z"
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7 PROJECT_ID=22
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9 token=$1
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
10
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
11 if [ -z $token ]; then
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
12 echo "USAGE: $0 GITLAB_TOKEN" >&2
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
13 exit 64
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
14 fi
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
15
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
16 get_ids() {
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
17 curl --silent "https://foss.heptapod.net/api/v4/projects/$PROJECT_ID/pipelines?updated_before=$d&per_page=100" | python3 -m json.tool | grep -E '"\bid": ([0-9]+),' | grep -oE '[0-9]+'
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
18 }
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
19
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
20 ids=`get_ids`
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
21 while [ -n "$ids" ]; do
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
22 echo '#########'
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
23 for pipeline_id in $ids; do
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
24 echo "deleting pipeline #$pipeline_id"
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
25 url="https://foss.heptapod.net/api/v4/projects/$PROJECT_ID/pipelines/$pipeline_id"
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
26 echo $url
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
27 curl \
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
28 --header "PRIVATE-TOKEN: $token"\
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
29 --request "DELETE"\
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
30 $url
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
31 done
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
32 ids=`get_ids`
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
33 if [ -n "$ids" ]; then
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
34 sleep 1
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
35 fi
77b38c86915d ci: add a small script one can run to purge older pipeline
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
36 done