diff --git a/.woodpecker/ci.yml b/.woodpecker/ci.yml index 2e01d7c..1c1853c 100644 --- a/.woodpecker/ci.yml +++ b/.woodpecker/ci.yml @@ -7,16 +7,18 @@ when: variables: - &build_plugin 'woodpeckerci/plugin-docker-buildx:3.2.1' # deployment targets - - &publish_repos 'ocram85/plugin-gitea-package,gitea.ocram85.com/plugins/gitea-package' + # TODO: Disabled docker hub target until first release is ready / Rate Limits + #- &publish_repos 'ocram85/plugin-gitea-package,gitea.ocram85.com/plugins/gitea-package' + - &publish_repos 'gitea.ocram85.com/plugins/gitea-package' # logins for deployment targets - publish_logins: &publish_logins # Default DockerHub login - - registry: https://index.docker.io/v1/ - username: - from_secret: docker_user - password: - from_secret: docker_passwd - # Additional Quay.IO login + #- registry: https://index.docker.io/v1/ + # username: + # from_secret: docker_user + # password: + # from_secret: docker_passwd + # Additional Gitea login - registry: https://gitea.ocram85.com username: from_secret: gitea_user diff --git a/.woodpecker/test-image.yml b/.woodpecker/test-image.yml index 87c8843..615494d 100644 --- a/.woodpecker/test-image.yml +++ b/.woodpecker/test-image.yml @@ -8,15 +8,39 @@ depends_on: - "ci" steps: - test-next: + next: image: gitea.ocram85.com/plugins/gitea-package:next pull: true + secrets: [ gitea_user, gitea_passwd] settings: + user: + from_secret: gitea_user + password: + from_secret: gitea_passwd debug: "true" - owner: "testuser" + owner: "plugins" package_name: "dummy_package" package_version: "0.1.0" - file_name: "./README.md" + file_source: "./README.md" + file_name: "readme.md" + update: "true" + when: + event: pull_request + branch: ${CI_REPO_DEFAULT_BRANCH} + next-nodebug: + image: gitea.ocram85.com/plugins/gitea-package:next + 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" update: "true" when: event: pull_request diff --git a/README.md b/README.md index 1630e8a..0e7f968 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@

gitea-package @@ -21,8 +21,8 @@

- - Main Branch Build Status + + Main Branch Build Status

diff --git a/assets/social-logo.png b/assets/social-logo.png index 21e3830..8067ad3 100644 Binary files a/assets/social-logo.png and b/assets/social-logo.png differ diff --git a/gitea-package.sh b/gitea-package.sh index 7d37b5a..63b4c7c 100755 --- a/gitea-package.sh +++ b/gitea-package.sh @@ -43,23 +43,78 @@ 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" + say "PLUGIN_FILE_SOURCE: $PLUGIN_FILE_SOURCE" "showSettings" say "PLUGIN_UPDATE: $PLUGIN_UPDATE" "showSettings" } +testArtifact() { + tout=$(curl --silent --output /dev/null --write-out "%{http_code}" \ + "$CI_FORGE_URL/api/packages/$PLUGIN_OWNER/generic/$PLUGIN_PACKAGE_NAME/$PLUGIN_PACKAGE_VERSION/$PLUGIN_FILE_NAME") + + if [ "$tout" = "200" ]; then + echo "true" + else + echo "false" + fi +} + +deleteArtifact() { + dout=$(curl --silent --output /dev/null --write-out "%{http_code}" \ + --user "$PLUGIN_USER:$PLUGIN_PASSWORD" -X DELETE \ + "$CI_FORGE_URL/api/packages/$PLUGIN_OWNER/generic/$PLUGIN_PACKAGE_NAME/$PLUGIN_PACKAGE_VERSION/$PLUGIN_FILE_NAME") + + if [ "$dout" = "204" ]; then + say "Old package file deleted" "deleteArtifact" + elif [ "$dout" = "404" ]; then + sayE "The package or file was not found." "deleteArtifact" + exit 1 + else + sayE "Unknown curl response! ($dout)" "deleteArtifact" + exit 1 + fi +} + uploadArtifact() { - curl --user your_username:your_password_or_token \ - --upload-file path/to/file.bin \ - https://gitea.example.com/api/packages/testuser/generic/test_package/1.0.0/file.bin + say "Testing if the artifact already exists in give package version..." "uploadArtifact" + fexist=$(testArtifact) + if [ "$fexist" = "true" ]; then + if [ -n "$PLUGIN_UPDATE" ]; then + sayW "Given file already exists. Updating package file..." "uploadArtifact" + deleteArtifact + else + sayW "A file with the same name exist already in the package." "uploadArtifact" + exit 1 + fi + fi + say "Starting file upload..." "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" + + 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 + sayE "File already exists in package version!" "uploadArtifact" + else + sayE "Unknown upload response! ($cout)" "uploadArtifact" + exit 1 + fi } main() { if [ -n "$PLUGIN_DEBUG" ]; then sayW "Debug mode enabled." showSettings - sayW "Available ENV vars:" - showENV - exit 0 + #sayW "Available ENV vars:" + #showENV fi + uploadArtifact } main "$@"