From 803a79e38053a3fdc9ccfe5ab805c149286cf2c2 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 17 May 2024 08:49:26 +0200 Subject: [PATCH 1/4] add tests --- .woodpecker/test-image.yml | 25 +++++++++++++++++++++++-- gitea-package.sh | 27 +++++++++++++++------------ 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/.woodpecker/test-image.yml b/.woodpecker/test-image.yml index 615494d..1b547d3 100644 --- a/.woodpecker/test-image.yml +++ b/.woodpecker/test-image.yml @@ -17,7 +17,6 @@ steps: from_secret: gitea_user password: from_secret: gitea_passwd - debug: "true" owner: "plugins" package_name: "dummy_package" package_version: "0.1.0" @@ -27,7 +26,8 @@ steps: when: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} - next-nodebug: + + next-debug: image: gitea.ocram85.com/plugins/gitea-package:next pull: true secrets: [ gitea_user, gitea_passwd] @@ -42,6 +42,27 @@ steps: file_source: "./README.md" file_name: "readme.md" update: "true" + debug: "true" + when: + event: pull_request + branch: ${CI_REPO_DEFAULT_BRANCH} + + next-no-update: + image: gitea.ocram85.com/plugins/gitea-package:next + pull: true + failure: ignore + secrets: [ gitea_user, gitea_passwd] + settings: + user: + from_secret: gitea_user + password: + from_secret: gitea_passwd + owner: "plugins" + package_name: "dummy_package" + package_version: "0.1.0" + file_source: "./README.md" + file_name: "readme.md" + debug: "true" when: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} diff --git a/gitea-package.sh b/gitea-package.sh index 63b4c7c..7562699 100755 --- a/gitea-package.sh +++ b/gitea-package.sh @@ -26,13 +26,16 @@ sayW() { fi } -showHelp() { - cat << HELP - 🤖 gitea-package Woodpecker-CI Plugin - - Syntax: -HELP -} +# TODO: Disabled for now. No default help output needed if just running as +# Woodpecker CI plugin. +# +#showHelp() { +# cat << HELP +# 🤖 gitea-package Woodpecker-CI Plugin +# +# Syntax: +#HELP +#} showENV() { env | sort @@ -75,23 +78,23 @@ deleteArtifact() { } uploadArtifact() { - say "Testing if the artifact already exists in give package version..." "uploadArtifact" + say "Testing if the given artifact already exists in the package registry..." "uploadArtifact" fexist=$(testArtifact) if [ "$fexist" = "true" ]; then if [ -n "$PLUGIN_UPDATE" ]; then - sayW "Given file already exists. Updating package file..." "uploadArtifact" + sayW "🚧 Given file already exists. Removing remote file..." "uploadArtifact" deleteArtifact else - sayW "A file with the same name exist already in the package." "uploadArtifact" + sayW "🛑 File already exists in the package registry." "uploadArtifact" exit 1 fi fi - say "Starting file upload..." "uploadArtifact" + say "Starting file upload... ($PLUGIN_FILE_SOURCE)" "uploadArtifact" cout=$(curl --silent --output /dev/null --write-out "%{http_code}" \ --user "$PLUGIN_USER:$PLUGIN_PASSWORD" \ --upload-file "$PLUGIN_FILE_SOURCE" \ "$CI_FORGE_URL/api/packages/$PLUGIN_OWNER/generic/$PLUGIN_PACKAGE_NAME/$PLUGIN_PACKAGE_VERSION/$PLUGIN_FILE_NAME") - say "Curl output is: $cout" "uploadArtifact" + say "Curl http response code: $cout" "uploadArtifact" if [ "$cout" = "201" ]; then say "Upload sucessfully finished." "uploadArtifact" -- 2.45.2 From 673cefd0a8ca9a79c2128f01647eeff527c81503 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 17 May 2024 08:59:11 +0200 Subject: [PATCH 2/4] unify output --- gitea-package.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gitea-package.sh b/gitea-package.sh index 7562699..9586081 100755 --- a/gitea-package.sh +++ b/gitea-package.sh @@ -97,22 +97,22 @@ uploadArtifact() { say "Curl http response code: $cout" "uploadArtifact" if [ "$cout" = "201" ]; then - say "Upload sucessfully finished." "uploadArtifact" + say "Upload sucessfully finished. ✅" "uploadArtifact" exit 0 elif [ "$cout" = "400" ]; then - sayE "Upload failed! (Bad Request)" "uploadArtifact" + sayE "Upload failed! (Bad Request) 💣" "uploadArtifact" exit 1 elif [ "$cout" = "409" ]; then - sayE "File already exists in package version!" "uploadArtifact" + sayE "File already exists in package version! 🛑" "uploadArtifact" else - sayE "Unknown upload response! ($cout)" "uploadArtifact" + sayE "Unknown upload response! ($cout) 💣" "uploadArtifact" exit 1 fi } main() { if [ -n "$PLUGIN_DEBUG" ]; then - sayW "Debug mode enabled." + sayW "🐞 Debug mode enabled." showSettings #sayW "Available ENV vars:" #showENV -- 2.45.2 From ae7476ec3b85a14d4ccdb653572f2589bcf9aad5 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 17 May 2024 09:04:31 +0200 Subject: [PATCH 3/4] add step without debug and update mode --- .woodpecker/test-image.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.woodpecker/test-image.yml b/.woodpecker/test-image.yml index 1b547d3..9c94cb7 100644 --- a/.woodpecker/test-image.yml +++ b/.woodpecker/test-image.yml @@ -8,7 +8,7 @@ depends_on: - "ci" steps: - next: + default: image: gitea.ocram85.com/plugins/gitea-package:next pull: true secrets: [ gitea_user, gitea_passwd] @@ -27,7 +27,7 @@ steps: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} - next-debug: + debug-out: image: gitea.ocram85.com/plugins/gitea-package:next pull: true secrets: [ gitea_user, gitea_passwd] @@ -47,7 +47,7 @@ steps: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} - next-no-update: + no-update: image: gitea.ocram85.com/plugins/gitea-package:next pull: true failure: ignore @@ -66,3 +66,22 @@ steps: when: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} + + no-update-debug: + image: gitea.ocram85.com/plugins/gitea-package:next + pull: true + failure: ignore + secrets: [ gitea_user, gitea_passwd] + settings: + user: + from_secret: gitea_user + password: + from_secret: gitea_passwd + owner: "plugins" + package_name: "dummy_package" + package_version: "0.1.0" + file_source: "./README.md" + file_name: "readme.md" + when: + event: pull_request + branch: ${CI_REPO_DEFAULT_BRANCH} -- 2.45.2 From 7db00e52d151e022b7933f6e0016d55e768aae2b Mon Sep 17 00:00:00 2001 From: OCram85 Date: Fri, 17 May 2024 09:20:35 +0200 Subject: [PATCH 4/4] add variables in pipelines --- .woodpecker/test-image.yml | 59 ++++++++++++++------------------------ 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/.woodpecker/test-image.yml b/.woodpecker/test-image.yml index 9c94cb7..9c9e3e7 100644 --- a/.woodpecker/test-image.yml +++ b/.woodpecker/test-image.yml @@ -4,15 +4,10 @@ when: branch: - ${CI_REPO_DEFAULT_BRANCH} -depends_on: - - "ci" -steps: - default: - image: gitea.ocram85.com/plugins/gitea-package:next - pull: true - secrets: [ gitea_user, gitea_passwd] - settings: +variables: + - &build_plugin 'gitea.ocram85.com/plugins/gitea-package:next' + - &default_settings user: from_secret: gitea_user password: @@ -22,25 +17,29 @@ steps: package_version: "0.1.0" file_source: "./README.md" file_name: "readme.md" + #update: "true" + +depends_on: + - "ci" + +steps: + default: + image: *build_plugin + pull: true + secrets: [ gitea_user, gitea_passwd] + settings: + <<: *default_settings update: "true" when: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} debug-out: - image: gitea.ocram85.com/plugins/gitea-package:next + image: *build_plugin pull: true secrets: [ gitea_user, gitea_passwd] settings: - user: - from_secret: gitea_user - password: - from_secret: gitea_passwd - owner: "plugins" - package_name: "dummy_package" - package_version: "0.1.0" - file_source: "./README.md" - file_name: "readme.md" + <<: *default_settings update: "true" debug: "true" when: @@ -48,40 +47,24 @@ steps: branch: ${CI_REPO_DEFAULT_BRANCH} no-update: - image: gitea.ocram85.com/plugins/gitea-package:next + image: *build_plugin pull: true failure: ignore secrets: [ gitea_user, gitea_passwd] settings: - user: - from_secret: gitea_user - password: - from_secret: gitea_passwd - owner: "plugins" - package_name: "dummy_package" - package_version: "0.1.0" - file_source: "./README.md" - file_name: "readme.md" + <<: *default_settings debug: "true" when: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} no-update-debug: - image: gitea.ocram85.com/plugins/gitea-package:next + image: *build_plugin pull: true failure: ignore secrets: [ gitea_user, gitea_passwd] settings: - user: - from_secret: gitea_user - password: - from_secret: gitea_passwd - owner: "plugins" - package_name: "dummy_package" - package_version: "0.1.0" - file_source: "./README.md" - file_name: "readme.md" + <<: *default_settings when: event: pull_request branch: ${CI_REPO_DEFAULT_BRANCH} -- 2.45.2