Skip to content

Commit 943a0fd

Browse files
committed
Cleanup old snapshots on Bintray
1 parent 4e38d01 commit 943a0fd

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

.travis/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ echo "TRAVIS_ALLOW_FAILURE: $TRAVIS_ALLOW_FAILURE"
1818
if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ]; then
1919
# Uploading the update site to Bintray
2020
./mvnw verify -DskipTests -Psnapshot-properties -Prelease-composite
21+
# Cleanup old snapshots
22+
(
23+
cd net.sourceforge.pmd.eclipse.p2updatesite
24+
./cleanup-bintray-snapshots.sh
25+
)
2126
fi
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
set -e
3+
4+
#Sample Usage: cleanup-bintray-snapshots.sh user apikey
5+
API=https://api.bintray.com
6+
7+
if [ -z $BINTRAY_API_KEY -o -z $BINTRAY_USER ]; then
8+
# only take arguments, if there are now env variable set already
9+
BINTRAY_API_KEY=$1
10+
BINTRAY_USER=$2
11+
fi
12+
13+
if [ -z $BINTRAY_API_KEY -o -z $BINTRAY_USER ]; then
14+
echo "Usage: $0 <BINTRAY_API_KEY> <BINTRAY_USER>"
15+
exit 1
16+
fi
17+
18+
BINTRAY_REPO=pmd-eclipse-plugin
19+
BINTRAY_OWNER=pmd
20+
21+
BASE_PATH=pmd/pmd-eclipse-plugin/snapshots/updates/4.0
22+
BASE_URL=https://dl.bintray.com/${BASE_PATH}
23+
BASE_PATH_SNAPSHOT_BUILDS=pmd/pmd-eclipse-plugin/snapshots/builds
24+
ARTIFACTS_FILE=compositeArtifacts.xml
25+
CONTENT_FILE=compositeContent.xml
26+
WORKING_DIR=target/cleanup-bintray-snapshots
27+
KEEP=5
28+
#DRY_RUN=echo
29+
30+
mkdir -p ${WORKING_DIR}
31+
pushd ${WORKING_DIR}
32+
33+
34+
# download the metadata
35+
curl ${BASE_URL}/${ARTIFACTS_FILE} > ${ARTIFACTS_FILE}
36+
curl ${BASE_URL}/${CONTENT_FILE} > ${CONTENT_FILE}
37+
38+
# we keep some versions
39+
artifacts=$(grep "<child location" ${ARTIFACTS_FILE} | tail -${KEEP})
40+
count=$(grep "<child location" ${ARTIFACTS_FILE} | tail -${KEEP}|wc -l)
41+
artifacts_remove=$(grep "<child location" ${ARTIFACTS_FILE} | grep -v "${artifacts}")
42+
artifacts_remove_count=$(echo "${artifacts_remove}" | grep -c "<child location")
43+
44+
#echo "Artifacts to keep:"
45+
#echo "$artifacts"
46+
#echo "Artifacts to remove:"
47+
#echo "$artifacts_remove"
48+
#echo "Artifacts to remove count: ${artifacts_remove_count}"
49+
50+
if [[ $artifacts_remove_count -eq 0 ]]; then
51+
echo "No artifacts should be removed, exiting"
52+
popd
53+
exit 0
54+
fi
55+
56+
57+
artifacts_versions=$(echo "${artifacts_remove}" | sed -n "s/ *<child location='..\/..\/builds\/\([^']*\).*/\1/p")
58+
#echo "versions:"
59+
#echo "$artifacts_versions"
60+
61+
for v in $artifacts_versions; do
62+
echo "Deleting $v ..."
63+
64+
for file in artifacts.jar artifacts.xml.xz content.jar content.xml.xz p2.index features/net.sourceforge.pmd.eclipse_${v}.jar plugins/net.sourceforge.pmd.eclipse.plugin_${v}.jar; do
65+
${DRY_RUN} curl -X DELETE -u${BINTRAY_USER}:${BINTRAY_API_KEY} "https://api.bintray.com/content/${BASE_PATH_SNAPSHOT_BUILDS}/${v}/${file}"
66+
done
67+
echo
68+
echo ----------------------------------------
69+
done
70+
71+
72+
echo
73+
echo "Updating metadata"
74+
75+
76+
artifactsTemplate="<?xml version='1.0' encoding='UTF-8'?>
77+
<?compositeArtifactRepository version='1.0.0'?>
78+
<repository name='PMD for Eclipse Update Site 4.0' type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository' version='1.0.0'>
79+
<properties size='2'>
80+
<property name='p2.timestamp' value='$(date +%s)000'/>
81+
<property name='p2.atomic.composite.loading' value='true'/>
82+
</properties>
83+
<children size='${count}'>
84+
$artifacts
85+
</children>
86+
</repository>
87+
"
88+
echo "${artifactsTemplate}" > ${ARTIFACTS_FILE}.new
89+
${DRY_RUN} curl -X PUT -u${BINTRAY_USER}:${BINTRAY_API_KEY} -T ${ARTIFACTS_FILE}.new https://api.bintray.com/content/${BASE_PATH}/${ARTIFACTS_FILE};publish=1
90+
91+
92+
content=$(grep "<child location" ${CONTENT_FILE} | tail -${KEEP})
93+
count=$(grep "<child location" ${CONTENT_FILE} | tail -${KEEP}|wc -l)
94+
content_remove=$(grep "<child location" ${CONTENT_FILE} | grep -v "${content}")
95+
96+
#echo "Content to keep:"
97+
#echo "$content"
98+
#echo "Content to remove:"
99+
#echo "$content_remove"
100+
101+
contentTemplate="<?xml version='1.0' encoding='UTF-8'?>
102+
<?compositeMetadataRepository version='1.0.0'?>
103+
<repository name='PMD for Eclipse Update Site 4.0' type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'>
104+
<properties size='2'>
105+
<property name='p2.timestamp' value='$(date +%s)000'/>
106+
<property name='p2.atomic.composite.loading' value='true'/>
107+
</properties>
108+
<children size='${count}'>
109+
$content
110+
</children>
111+
</repository>
112+
"
113+
echo "${contentTemplate}" > ${CONTENT_FILE}.new
114+
${DRY_RUN} curl -X PUT -u${BINTRAY_USER}:${BINTRAY_API_KEY} -T ${CONTENT_FILE}.new https://api.bintray.com/content/${BASE_PATH}/${CONTENT_FILE};publish=1
115+
116+
117+
popd

0 commit comments

Comments
 (0)