Skip to content

Instantly share code, notes, and snippets.

@mg6
Last active May 29, 2018 18:52
Show Gist options
  • Save mg6/4910408299938891bdc4321e049bd072 to your computer and use it in GitHub Desktop.
Save mg6/4910408299938891bdc4321e049bd072 to your computer and use it in GitHub Desktop.
#!/bin/bash
# MIT License
#
# Copyright (c) 2018 Maciej Gamrat <maciej@gamrat.it>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# PURPOSE
# A tool for AppVeyor NuGet feed cleanup.
# RUNNING
# export APPVEYOR_FEED=<feed identifier>
# export APPVEYOR_AUTH=<Base64-encoded Basic Auth username:password>
# export APPVEYOR_API_KEY=<NuGet feed API key>
# ./cleanup-nuget-feed <package filter>
# DEPENDENCIES
# curl jq xml2json
set -euo pipefail
feed="${APPVEYOR_FEED}"
auth="${APPVEYOR_AUTH}"
apikey="${APPVEYOR_API_KEY}"
get_packages() {
curl -sSfL \
-H "Authorization: Basic ${auth}" \
"https://ci.appveyor.com/nuget/${feed}/packages"
}
delete_package() {
local pkg_id="$1"
local version="$2"
echo >&2 "Deleting package ${pkg_id} version ${pkg_version}..."
curl -sSfL -X DELETE \
-H "X-NuGet-ApiKey: ${apikey}" \
"https://ci.appveyor.com/nuget/${feed}/api/v2/package/${pkg_id}/${version}"
}
pkg_title_version_to_tsv() {
jq -cr '
.feed.entry[]
| [.title."$t", ."m:properties"."d:Version"]
| @tsv
'
}
cleanup() {
local filter="$1"
get_packages \
| xml2json \
| pkg_title_version_to_tsv \
| grep "${filter}" \
| while read line; do
local pkg_id pkg_version
pkg_id="$(cut -f1 <<< "$line")"
pkg_version="$(cut -f2 <<< "$line")"
delete_package "${pkg_id}" "${pkg_version}"
done
}
cleanup "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment