feat(gitea,release): auto cleanup prereleases
This commit is contained in:
parent
3f1b8bcda1
commit
199b0bf5d1
|
@ -14,7 +14,10 @@ GITEA_RELEASE_IS_DRAFT=${GITEA_RELEASE_IS_DRAFT:-false}
|
|||
GITEA_RELEASE_IS_PRERELEASE=${GITEA_RELEASE_IS_PRERELEASE:-true}
|
||||
GITEA_RELEASE_BODY=${GITEA_RELEASE_BODY}
|
||||
GITEA_RELEASE_ATTACHMENTS=${GITEA_RELEASE_ATTACHMENTS}
|
||||
GITEA_UPLOAD_MAX_RETRY=${GITEA_UPLOAD_MAX_RETRY:-3}
|
||||
GITEA_RELEASE_CURL_MAX_RETRY=${GITEA_RELEASE_CURL_MAX_RETRY:-3}
|
||||
|
||||
GITEA_RELEASE_CLEANUP_PRERELEASES=${GITEA_RELEASE_CLEANUP_PRERELEASES:-true}
|
||||
GITEA_RELEASE_CLEANUP_KEPT_PRERELEASES=${GITEA_RELEASE_CLEANUP_KEPT_PRERELEASES:-3}
|
||||
|
||||
function check_dependencies {
|
||||
assert_command_available 'curl'
|
||||
|
@ -159,12 +162,30 @@ function gitea_api {
|
|||
--fail \
|
||||
--ipv4 \
|
||||
--progress-bar \
|
||||
--retry "$GITEA_UPLOAD_MAX_RETRY" \
|
||||
--retry "$GITEA_RELEASE_CURL_MAX_RETRY" \
|
||||
-u "$GITEA_RELEASE_USERNAME:$GITEA_RELEASE_PASSWORD" \
|
||||
$GITEA_RELEASE_CURL_ARGS \
|
||||
${args} \
|
||||
"$GITEA_RELEASE_BASE_URL/api/v1$path"
|
||||
}
|
||||
|
||||
function clean_prereleases {
|
||||
if [ "$GITEA_RELEASE_CLEANUP_PRERELEASES" != "true" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local releases=$(gitea_api "/repos/$GITEA_RELEASE_ORG/$GITEA_RELEASE_PROJECT/releases")
|
||||
local to_delete=$(echo "$releases" | jq -r --arg index "$GITEA_RELEASE_CLEANUP_KEPT_PRERELEASES" '[.[] | select(.prerelease == true)] | sort_by(.created_at) | reverse | .[$index | tonumber:] | .[].id')
|
||||
|
||||
echo $to_delete
|
||||
|
||||
for release_id in $to_delete; do
|
||||
gitea_api "/repos/$GITEA_RELEASE_ORG/$GITEA_RELEASE_PROJECT/releases/$release_id" \
|
||||
-X DELETE \
|
||||
-H "Content-Type:application/json"
|
||||
done
|
||||
}
|
||||
|
||||
function main {
|
||||
check_dependencies
|
||||
source_env_file
|
||||
|
@ -173,7 +194,9 @@ function main {
|
|||
retrieve_commitish_target
|
||||
retrieve_version
|
||||
local release=$(create_release)
|
||||
sleep 1 # Wait for release creation
|
||||
upload_release_attachments "$release"
|
||||
clean_prereleases
|
||||
}
|
||||
|
||||
main
|
Loading…
Reference in New Issue