gitea-package/gitea-package.sh

84 lines
2.0 KiB
Bash
Raw Normal View History

#!/usr/bin/env sh
set -e
say() {
if [ -n "$2" ]; then
printf "🤖 \e[32mgitea-package\e[0m \e[36m[⚒️ %s]\e[0m: %s \n" "$2" "$1"
else
printf "🤖 \e[32mgitea-package\e[0m: %s \n" "$1"
fi
}
sayE() {
if [ -n "$2" ]; then
printf "🤖 \e[31mgitea-package\e[0m \e[36m[⚒️ %s]\e[0m: %s \n" "$2" "$1" 1>&2
else
printf "🤖 \e[31mgitea-package\e[0m: %s \n" "$1" 1>&2
fi
}
sayW() {
if [ -n "$2" ]; then
printf "🤖 \e[33mgitea-package\e[0m \e[36m[⚒️ %s]\e[0m: %s \n" "$2" "$1" 1>&2
else
printf "🤖 \e[33mgitea-package\e[0m: %s \n" "$1" 1>&2
fi
}
showHelp() {
cat << HELP
🤖 gitea-package Woodpecker-CI Plugin
Syntax:
HELP
}
showENV() {
env | sort
}
showSettings() {
say "PLUGIN_OWNER: $PLUGIN_OWNER" "showSettings"
say "PLUGIN_PACKAGE_NAME: $PLUGIN_PACKAGE_NAME" "showSettings"
say "PLUGIN_PACKAGE_VERSION: $PLUGIN_PACKAGE_VERSION" "showSettings"
say "PLUGIN_FILE_NAME: $PLUGIN_FILE_NAME" "showSettings"
2024-05-14 08:21:25 +02:00
say "PLUGIN_FILE_SOURCE: $PLUGIN_FILE_SOURCE" "showSettings"
say "PLUGIN_UPDATE: $PLUGIN_UPDATE" "showSettings"
}
uploadArtifact() {
2024-05-14 09:15:29 +02:00
say "Starting file upload..."
2024-05-14 08:55:29 +02:00
cout=$(curl --output /dev/null --write-out "%{http_code}" \
2024-05-14 08:39:32 +02:00
--user "$PLUGIN_USER:$PLUGIN_PASSWORD" \
2024-05-14 08:21:25 +02:00
--upload-file "$PLUGIN_FILE_SOURCE" \
2024-05-14 08:43:26 +02:00
"$CI_FORGE_URL/api/packages/$PLUGIN_OWNER/generic/$PLUGIN_PACKAGE_NAME/$PLUGIN_PACKAGE_VERSION/$PLUGIN_FILE_NAME")
say "Curl output is: $cout" "uploadArtifact"
2024-05-14 09:15:29 +02:00
if [ "$cout" = "201" ]; then
say "Upload sucessfully finished." "uploadArtifact"
exit 0
elif [ "$cout" = "400" ]; then
sayE "Upload failed! (Bad Request)" "uploadArtifact"
exit 1
elif [ "$cout" = "409" ]; then
sayW "A file with the same name exist already in the package." "uploadArtifact"
exit 1
else
sayE "Unknown upload response! ($cout)" "uploadArtifact"
exit 1
fi
}
main() {
if [ -n "$PLUGIN_DEBUG" ]; then
sayW "Debug mode enabled."
showSettings
2024-05-14 08:55:29 +02:00
#sayW "Available ENV vars:"
#showENV
fi
2024-05-14 08:21:25 +02:00
uploadArtifact
}
main "$@"