feat(gitea): update package management scripts
This commit is contained in:
parent
59e5e62d00
commit
4c4b90dad3
@ -82,10 +82,9 @@ function gitea_api {
|
||||
|
||||
function delete_packages {
|
||||
local page=1
|
||||
local limit=10
|
||||
local next=true
|
||||
while $next; do
|
||||
local result=$(gitea_api "/api/v1/packages/$GITEA_PACKAGE_ORG?page=$page&limit=$limit" -X GET -H 'accept:application/json')
|
||||
local limit=100
|
||||
while true; do
|
||||
local result=$(gitea_api "/api/v1/packages/$GITEA_PACKAGE_ORG?page=$page&limit=$limit&type=all" -X GET -H 'accept:application/json')
|
||||
local total_items=$(echo $result | jq -r '. | length')
|
||||
|
||||
for (( i = 0; i < $total_items; i++ )); do
|
||||
@ -106,8 +105,8 @@ function delete_packages {
|
||||
gitea_api "/api/v1/packages/$GITEA_PACKAGE_ORG/$package_type/$package_name/$package_version" -X DELETE
|
||||
done
|
||||
|
||||
if [[ $total_items == 0 ]]; then
|
||||
next=false
|
||||
if [[ "$total_items" == "0" ]]; then
|
||||
break
|
||||
fi
|
||||
|
||||
page=$(( $page + 1 ))
|
||||
|
29
resources/com/cadoles/gitea/gitea-package.sh
Normal file → Executable file
29
resources/com/cadoles/gitea/gitea-package.sh
Normal file → Executable file
@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eo pipefail
|
||||
set -xeo pipefail
|
||||
|
||||
GITEA_PACKAGE_ORG=${GITEA_PACKAGE_ORG}
|
||||
GITEA_PACKAGE_PROJECT=${GITEA_PACKAGE_PROJECT}
|
||||
GITEA_PACKAGE_BASE_URL=${GITEA_BASE_URL:-https://forge.cadoles.com}
|
||||
GITEA_PACKAGE_USERNAME=${GITEA_PACKAGE_USERNAME}
|
||||
GITEA_PACKAGE_PASSWORD=${GITEA_PACKAGE_PASSWORD}
|
||||
@ -18,6 +19,9 @@ GITEA_PACKAGE_DEBIAN_COMPONENT=${GITEA_PACKAGE_DEBIAN_COMPONENT:-main}
|
||||
GITEA_PACKAGE_ALPINE_BRANCH=${GITEA_PACKAGE_ALPINE_BRANCH:-latest}
|
||||
GITEA_PACKAGE_ALPINE_REPOSITORY=${GITEA_PACKAGE_ALPINE_REPOSITORY:-main}
|
||||
|
||||
GITEA_PACKAGE_GENERIC_PACKAGE_NAME=${GITEA_PACKAGE_GENERIC_PACKAGE_NAME:-$GITEA_PACKAGE_PROJECT}
|
||||
GITEA_PACKAGE_GENERIC_PACKAGE_VERSION=${GITEA_PACKAGE_GENERIC_PACKAGE_VERSION:-latest}
|
||||
|
||||
function check_dependencies {
|
||||
assert_command_available 'curl'
|
||||
}
|
||||
@ -34,6 +38,7 @@ function assert_command_available {
|
||||
|
||||
function check_environment {
|
||||
assert_environment GITEA_PACKAGE_ORG
|
||||
assert_environment GITEA_PACKAGE_PROJECT
|
||||
assert_environment GITEA_PACKAGE_BASE_URL
|
||||
}
|
||||
|
||||
@ -71,16 +76,6 @@ function ask_credentials {
|
||||
fi
|
||||
}
|
||||
|
||||
function ask_package_type {
|
||||
local available_types="debian alpine redhat"
|
||||
local match=$( ( echo "$available_types" | grep -qw "$GITEA_PACKAGE_TYPE" ) && echo yes || echo no )
|
||||
while [ "$match" == "no" ] || [ -z $GITEA_PACKAGE_TYPE ]; do
|
||||
echo -n "Package type ($available_types): "
|
||||
read GITEA_PACKAGE_TYPE
|
||||
match=$( ( echo "$available_types" | grep -qw "$GITEA_PACKAGE_TYPE" ) && echo yes || echo no )
|
||||
done
|
||||
}
|
||||
|
||||
function ask_package_file {
|
||||
while [ ! -f "$GITEA_PACKAGE_FILE" ]; do
|
||||
echo -n "Package file (must be a valid path to a supported package file): "
|
||||
@ -101,6 +96,9 @@ function ask_package_file {
|
||||
rpm)
|
||||
GITEA_PACKAGE_TYPE=redhat
|
||||
;;
|
||||
*)
|
||||
GITEA_PACKAGE_TYPE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
@ -120,6 +118,11 @@ function upload_redhat_package {
|
||||
--upload-file "$GITEA_PACKAGE_FILE"
|
||||
}
|
||||
|
||||
function upload_generic_package {
|
||||
local filename=$(basename $GITEA_PACKAGE_FILE)
|
||||
gitea_api "/api/packages/$GITEA_PACKAGE_ORG/generic/$GITEA_PACKAGE_GENERIC_PACKAGE_NAME/$GITEA_PACKAGE_GENERIC_PACKAGE_VERSION/$filename" \
|
||||
--upload-file "$GITEA_PACKAGE_FILE"
|
||||
}
|
||||
|
||||
function gitea_api {
|
||||
local path=$1
|
||||
@ -142,7 +145,6 @@ function main {
|
||||
check_environment
|
||||
ask_credentials
|
||||
ask_package_file
|
||||
ask_package_type
|
||||
case $GITEA_PACKAGE_TYPE in
|
||||
debian)
|
||||
upload_debian_package
|
||||
@ -153,6 +155,9 @@ function main {
|
||||
redhat)
|
||||
upload_redhat_package
|
||||
;;
|
||||
generic)
|
||||
upload_generic_package
|
||||
;;
|
||||
*)
|
||||
echo "Package type '$GITEA_PACKAGE_TYPE' is not yet supported" 1>&2
|
||||
exit 1
|
||||
|
@ -105,7 +105,6 @@ void release(String credentialsId, String org, String project, Map options = [:]
|
||||
}
|
||||
|
||||
rocketSend(
|
||||
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
|
||||
message: """
|
||||
Nouvelle version publiée pour le projet `${org}/${project}`: [${releaseName}](${baseUrl}/${org}/${project}/releases/tag/${releaseVersion})
|
||||
|
||||
@ -168,7 +167,6 @@ void uploadPackages(String credentialsId, String org, String project, List<Strin
|
||||
}
|
||||
|
||||
rocketSend(
|
||||
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
|
||||
message: """
|
||||
| Nouveau(x) paquet(s) publié(s) pour le projet [${org}/${project}](${baseUrl}/${org}/-/packages):
|
||||
|
|
||||
|
Loading…
x
Reference in New Issue
Block a user