From 9f7ab04cda35118af01389a7c2133b5f5c6c7ee4 Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Fri, 13 Mar 2020 19:59:15 +0100 Subject: [PATCH 1/7] Add first draft of the package update notification --- .gitlab-ci.yml | 11 +++++ .utilities/package_update_notifier.sh | 71 +++++++++++++++++++++++++++ .utilities/utilities.sh | 5 ++ 3 files changed, 87 insertions(+) create mode 100644 .utilities/package_update_notifier.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f7ee1f1..793ad38 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -55,3 +55,14 @@ description_templater: artifacts: paths: - "*.description" + +bot:package_update_notification: + image: alpine:latest + script: bash -e .utilities/package_update_notifier.sh + only: + - schedules + # see https://docs.gitlab.com/ce/ci/yaml/README.html#onlyexcept-advanced for feature updates + # refs: + # - schedules + # variables: + # - $SCHEDULE_ID == $PACKAGE_UPDATE_NOTIFICATION_SCHEDULE_ID \ No newline at end of file diff --git a/.utilities/package_update_notifier.sh b/.utilities/package_update_notifier.sh new file mode 100644 index 0000000..b0bcbef --- /dev/null +++ b/.utilities/package_update_notifier.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# Docker Seafile client, help you mount a Seafile library as a volume. +# Copyright (C) 2019-2020, flow.gunso@gmail.com +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +apk add curl jq + +# Load utilities functions. +SCRIPT_DIRECTORY=$(dirname ${BASH_SOURCE[0]}) +source $SCRIPT_DIRECTORY/utilities.sh + +# Restrict the job to the right schedule. +if [[ "$SCHEDULE_ID" != "$PACKAGE_UPDATE_NOTIFICATION_SCHEDULE_ID" ]]; then + exit_with_message_and_code "Schedule ID did not match." 0 +fi + +# Fetch the issue state if the ISSUE_ID variable is set, +# if that state is closed remove the ISSUE_ID variable and continue the job, otherwise exit the job. +if [[ -n "$ISSUE_ID" ]]; then + issue_state="$(curl -H \"PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN\" \ + https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/issue/$ISSUE_ID | jq .state)" + if [[ "$issue_state" == "closed" ]]; then + echo "An issue exist, but is closed. Removing ISSUE_ID schedule variable..." + echo 'curl -X DELETE \ + -H "PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN" \ + https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/pipeline_schedules/$SCHEDULE_ID/variables/ISSUES_ID' + else + exit_with_message_and_code "An issue already exists, it is not closed yet." 0 + fi +fi + +# Get the installed and candidate versions of the seafile-cli package from the latest Docker image. +docker pull $CI_REGISTRY_IMAGE:latest +candidate_version=$(docker run --rm --entrypoint="" $CI_REGISTRY_IMAGE:latest \ + bash -c "\ + apt-get -qq update;\ + apt-cache policy seafile-cli | grep 'Candidate:' | awk '{print \$2}'") +installed_version=$(docker run --rm --entrypoint="" $CI_REGISTRY_IMAGE:latest \ + bash -c "\ + apt-get -qq update;\ + apt-cache policy seafile-cli | grep 'Installed:' | awk '{print \$2}'") + +# Create an issue if a new version was released. +if [[ "$installed_version" == "$candidate_version"]; then + exit_with_message_and_code "No new version of the seafile-cli package have been released." 0 +else + echo "A new version of the seafile-cli package have been released. Creating a new issue..." + data=$(jq -n \ + --arg title "seafile-cli v${candidate_version} was released" \ + --arg description "Check for new feature, breaking changes or anything worth updating to update the Docker image." \ + --arg labels "enhancement" \ + '{title: $title, description: $description, labels: [$labels]}') + echo 'curl -X POST \ + -H "PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d "$data" + https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/issues' +fi diff --git a/.utilities/utilities.sh b/.utilities/utilities.sh index b115d67..b09c6bf 100644 --- a/.utilities/utilities.sh +++ b/.utilities/utilities.sh @@ -19,3 +19,8 @@ load_images_artifacts() { docker load --input $CI_PROJECT_NAME.tar } + +exit_with_message_and_code() { + echo $1 + exit $2 +} From 9483b81767fad9341d07d72cf1d55f1bf15d0d4a Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Fri, 13 Mar 2020 21:22:02 +0100 Subject: [PATCH 2/7] Move the check script down into the bulid stage --- .gitlab-ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 793ad38..8edfa67 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,11 +10,12 @@ stages: before_script: - apk add bash git - - /bin/bash .utilities/check.sh build: stage: build - script: /bin/bash -e .utilities/build.sh + script: + - /bin/bash .utilities/check.sh + - /bin/bash -e .utilities/build.sh only: - tags artifacts: From cdd6d82a45758abd6b91d7007579aa6e709f2eaa Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Fri, 13 Mar 2020 21:31:22 +0100 Subject: [PATCH 3/7] Add the stage report, remove schedules from test stage, add bot:package_update_notification to report stage --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8edfa67..01520a5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ services: - docker:dind stages: + - report - build - test - publish @@ -27,7 +28,6 @@ test: script: /bin/bash -e .utilities/test.sh only: - tags - - schedules artifacts: paths: - "$CI_PROJECT_NAME.tar" @@ -58,7 +58,7 @@ description_templater: - "*.description" bot:package_update_notification: - image: alpine:latest + stage: report script: bash -e .utilities/package_update_notifier.sh only: - schedules From ba772172357cabf26f49d786586dba11ec1226d2 Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Fri, 13 Mar 2020 21:38:06 +0100 Subject: [PATCH 4/7] Fix Bash syntax --- .utilities/package_update_notifier.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.utilities/package_update_notifier.sh b/.utilities/package_update_notifier.sh index b0bcbef..f7da826 100644 --- a/.utilities/package_update_notifier.sh +++ b/.utilities/package_update_notifier.sh @@ -54,7 +54,7 @@ installed_version=$(docker run --rm --entrypoint="" $CI_REGISTRY_IMAGE:latest \ apt-cache policy seafile-cli | grep 'Installed:' | awk '{print \$2}'") # Create an issue if a new version was released. -if [[ "$installed_version" == "$candidate_version"]; then +if [[ "$installed_version" == "$candidate_version" ]]; then exit_with_message_and_code "No new version of the seafile-cli package have been released." 0 else echo "A new version of the seafile-cli package have been released. Creating a new issue..." From 13d2ca6f7871524aa8f7162072ca253bd5a465e7 Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Fri, 13 Mar 2020 23:14:26 +0100 Subject: [PATCH 5/7] Testing some hard to reach instrunctions --- .utilities/package_update_notifier.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.utilities/package_update_notifier.sh b/.utilities/package_update_notifier.sh index f7da826..7854811 100644 --- a/.utilities/package_update_notifier.sh +++ b/.utilities/package_update_notifier.sh @@ -32,13 +32,13 @@ fi if [[ -n "$ISSUE_ID" ]]; then issue_state="$(curl -H \"PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN\" \ https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/issue/$ISSUE_ID | jq .state)" - if [[ "$issue_state" == "closed" ]]; then +# if [[ "$issue_state" == "closed" ]]; then echo "An issue exist, but is closed. Removing ISSUE_ID schedule variable..." echo 'curl -X DELETE \ -H "PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN" \ https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/pipeline_schedules/$SCHEDULE_ID/variables/ISSUES_ID' - else - exit_with_message_and_code "An issue already exists, it is not closed yet." 0 +# else +# exit_with_message_and_code "An issue already exists, it is not closed yet." 0 fi fi @@ -55,8 +55,8 @@ installed_version=$(docker run --rm --entrypoint="" $CI_REGISTRY_IMAGE:latest \ # Create an issue if a new version was released. if [[ "$installed_version" == "$candidate_version" ]]; then - exit_with_message_and_code "No new version of the seafile-cli package have been released." 0 -else +# exit_with_message_and_code "No new version of the seafile-cli package have been released." 0 +#else echo "A new version of the seafile-cli package have been released. Creating a new issue..." data=$(jq -n \ --arg title "seafile-cli v${candidate_version} was released" \ From 7b02f7c360168ed4c476b6e62cb28b609c429e71 Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Sat, 14 Mar 2020 09:58:39 +0100 Subject: [PATCH 6/7] Fix Bash syntax --- .utilities/package_update_notifier.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.utilities/package_update_notifier.sh b/.utilities/package_update_notifier.sh index 7854811..6baf5e7 100644 --- a/.utilities/package_update_notifier.sh +++ b/.utilities/package_update_notifier.sh @@ -39,7 +39,7 @@ if [[ -n "$ISSUE_ID" ]]; then https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/pipeline_schedules/$SCHEDULE_ID/variables/ISSUES_ID' # else # exit_with_message_and_code "An issue already exists, it is not closed yet." 0 - fi +# fi fi # Get the installed and candidate versions of the seafile-cli package from the latest Docker image. From 2470dcb124fcee8a1793fcb984c85781f2d2c4a4 Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Sat, 14 Mar 2020 10:14:21 +0100 Subject: [PATCH 7/7] Remove tests (#18) --- .utilities/package_update_notifier.sh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.utilities/package_update_notifier.sh b/.utilities/package_update_notifier.sh index 6baf5e7..c01516b 100644 --- a/.utilities/package_update_notifier.sh +++ b/.utilities/package_update_notifier.sh @@ -32,14 +32,14 @@ fi if [[ -n "$ISSUE_ID" ]]; then issue_state="$(curl -H \"PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN\" \ https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/issue/$ISSUE_ID | jq .state)" -# if [[ "$issue_state" == "closed" ]]; then + if [[ "$issue_state" == "closed" ]]; then echo "An issue exist, but is closed. Removing ISSUE_ID schedule variable..." - echo 'curl -X DELETE \ + curl -X DELETE \ -H "PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN" \ - https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/pipeline_schedules/$SCHEDULE_ID/variables/ISSUES_ID' -# else -# exit_with_message_and_code "An issue already exists, it is not closed yet." 0 -# fi + https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/pipeline_schedules/$SCHEDULE_ID/variables/ISSUES_ID + else + exit_with_message_and_code "An issue already exists, it is not closed yet." 0 + fi fi # Get the installed and candidate versions of the seafile-cli package from the latest Docker image. @@ -55,17 +55,17 @@ installed_version=$(docker run --rm --entrypoint="" $CI_REGISTRY_IMAGE:latest \ # Create an issue if a new version was released. if [[ "$installed_version" == "$candidate_version" ]]; then -# exit_with_message_and_code "No new version of the seafile-cli package have been released." 0 -#else + exit_with_message_and_code "No new version of the seafile-cli package have been released." 0 +else echo "A new version of the seafile-cli package have been released. Creating a new issue..." data=$(jq -n \ --arg title "seafile-cli v${candidate_version} was released" \ --arg description "Check for new feature, breaking changes or anything worth updating to update the Docker image." \ --arg labels "enhancement" \ '{title: $title, description: $description, labels: [$labels]}') - echo 'curl -X POST \ + curl -X POST \ -H "PRIVATE-TOKEN: $REPORTER_BOT_ACCESS_TOKEN" \ -H "Content-Type: application/json" \ -d "$data" - https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/issues' + https://gitlab.com/api/v4/projects/$CI_PROJECT_ID/issues fi