From 919c98f67cbc65778b83e882ced02ff579e4da9e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Jun 2021 20:42:56 +0200 Subject: [PATCH 01/17] WIP test out markdown --- matrix-notifier | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-notifier b/matrix-notifier index 34a46b2..95394df 100755 --- a/matrix-notifier +++ b/matrix-notifier @@ -36,7 +36,7 @@ rawurlencode() { } default_drone_message() { - local msg="Build ${DRONE_BUILD_STATUS}" + local msg="Build *${DRONE_BUILD_STATUS}*" msg="$msg ${DRONE_SYSTEM_PROTO}://${DRONE_SYSTEM_HOST}/${DRONE_REPO}/${DRONE_BUILD_NUMBER}" msg="$msg (${DRONE_TAG:-$DRONE_BRANCH})" printf '%s' "$msg" From fe0de738b070e7275b9f6c476d8a36eac595568f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Jun 2021 20:57:44 +0200 Subject: [PATCH 02/17] matrix-notifier: add option to disable mardown --- matrix-notifier | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/matrix-notifier b/matrix-notifier index 34a46b2..ab9a6e4 100755 --- a/matrix-notifier +++ b/matrix-notifier @@ -9,6 +9,9 @@ usage() { print_err "" print_err " -h, --help" print_err " print this usage screen and exit" + print_err " -f, --format" + print_err " should the message be formatted using 'pandoc'." + print_err " Must be either 'true' or 'false'." print_err " -t, --type" print_err " which message type should be sent must be one of" print_err " 'text' or 'notice', or 'auto'." @@ -72,12 +75,13 @@ get_message_type() { } make_message_json() { - jq -s '.[0] * .[1]' \ - <(printf '%s' "$1" | + { + printf '%s' "$1" | + jq --raw-input --slurp "{msgtype: \"$(get_message_type)\", body: .}" + [ "$FORMAT" == "true" ] && printf '%s' "$1" | pandoc | - jq --raw-input --slurp "{format: \"org.matrix.custom.html\", formatted_body: .}") \ - <(printf '%s' "$1" | - jq --raw-input --slurp "{msgtype: \"$(get_message_type)\", body: .}") + jq --raw-input --slurp "{format: \"org.matrix.custom.html\", formatted_body: .}" + } | jq -s 'add' } send_message() { @@ -110,12 +114,25 @@ send_message() { } MSG_TYPE='auto' +FORMAT='true' while [ $# -gt 0 ]; do opt="$1" shift case "$opt" in + -f|--format) + arg="$1" + shift + + if [ "$arg" == "true" ] || [ "$arg" == "false" ]; then + FORMAT="$arg" + continue + fi + + print_err "Must give value 'true' or 'false' with '-t|--type'" + exit 1 + ;; -t|--type) arg="$1" shift From d2b019f29db59f96d22110808c7d8490829817b4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Jun 2021 20:42:56 +0200 Subject: [PATCH 03/17] matrix-notifier: use link formatting when enabled Make the link formatted to provide a shorter, more good-looking message. --- matrix-notifier | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/matrix-notifier b/matrix-notifier index ab9a6e4..af9cdb8 100755 --- a/matrix-notifier +++ b/matrix-notifier @@ -40,7 +40,12 @@ rawurlencode() { default_drone_message() { local msg="Build ${DRONE_BUILD_STATUS}" - msg="$msg ${DRONE_SYSTEM_PROTO}://${DRONE_SYSTEM_HOST}/${DRONE_REPO}/${DRONE_BUILD_NUMBER}" + local drone_url="${DRONE_SYSTEM_PROTO}://${DRONE_SYSTEM_HOST}/${DRONE_REPO}/${DRONE_BUILD_NUMBER}" + if [ "$FORMAT" == "true" ]; then + msg="$msg [${DRONE_REPO_OWNER}/${DRONE_REPO_NAME}#${DRONE_COMMIT:0:8}]($drone_url)" + else + msg="$msg $drone_url" + fi msg="$msg (${DRONE_TAG:-$DRONE_BRANCH})" printf '%s' "$msg" } From 05ab9425ddcce5ce8295409c1af5798c4456a08a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Jun 2021 21:14:14 +0200 Subject: [PATCH 04/17] doc: mention pandoc formatting --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d05f48..420c711 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,4 @@ export MESSAGE='This is my test message' This script is packaged with `Nix`, you can just use `nix run .` to run it. The only dependencies are `bash`, `curl`, and `jq`, install those and you should -be ready to go! +be ready to go! Format is needed when using formatting (enabled by default). From 5f1fb1c1a460f77370c2c2a79fa697cb31f84b09 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Jun 2021 21:11:39 +0200 Subject: [PATCH 05/17] flake: bump version to v0.2.0 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index df25640..7c2bc1c 100644 --- a/flake.nix +++ b/flake.nix @@ -75,7 +75,7 @@ packages = { matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec { pname = "matrix-notifier"; - version = "0.1.2"; + version = "0.2.0"; src = ./matrix-notifier; From b6a9c7e6a4194c85bdd0d4133879c0b63230167b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 8 Oct 2021 15:49:05 +0200 Subject: [PATCH 06/17] nix: use 'inputsFrom' --- flake.nix | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 7c2bc1c..1437d34 100644 --- a/flake.nix +++ b/flake.nix @@ -63,10 +63,8 @@ devShell = pkgs.mkShell { name = "matrix-notifier"; - buildInputs = with pkgs; [ - curl - jq - shellcheck + inputsFrom = with self.packages.${system}; [ + matrix-notifier ]; inherit (self.checks.${system}.pre-commit) shellHook; From 007994e0a2cadc9503457f04751baf896c45a50b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 3 Jun 2022 16:30:12 +0200 Subject: [PATCH 07/17] nix: migrate from deprecated attributes --- flake.nix | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/flake.nix b/flake.nix index 1437d34..5ddc848 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,8 @@ in rec { apps = { + default = apps.matrix-notifier; + matrix-notifier = futils.lib.mkApp { drv = packages.matrix-notifier; }; }; @@ -56,21 +58,21 @@ }; }; - defaultApp = apps.matrix-notifier; + devShells = { + default = pkgs.mkShell { + name = "matrix-notifier"; - defaultPackage = packages.matrix-notifier; + inputsFrom = with self.packages.${system}; [ + matrix-notifier + ]; - devShell = pkgs.mkShell { - name = "matrix-notifier"; - - inputsFrom = with self.packages.${system}; [ - matrix-notifier - ]; - - inherit (self.checks.${system}.pre-commit) shellHook; + inherit (self.checks.${system}.pre-commit) shellHook; + }; }; packages = { + default = packages.matrix-notifier; + matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec { pname = "matrix-notifier"; version = "0.2.0"; From 0bc11d85d57dd83bdcbf7b5cf6fe3a1d9d81bcbf Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 18 Mar 2023 12:42:02 +0000 Subject: [PATCH 08/17] nix: fix flake description --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 5ddc848..00e1a27 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Ambroisie's blog"; + description = "A simple Matrix notifier for CI purposes"; inputs = { futils = { From eebe509b02983819855deeeb65a78a6cab13acd8 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 18 Mar 2023 12:46:36 +0000 Subject: [PATCH 09/17] matrix-notifier: add woodpecker integration --- matrix-notifier | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/matrix-notifier b/matrix-notifier index af9cdb8..0b99989 100755 --- a/matrix-notifier +++ b/matrix-notifier @@ -16,7 +16,7 @@ usage() { print_err " which message type should be sent must be one of" print_err " 'text' or 'notice', or 'auto'." print_err " The special value 'auto' defaults to 'notice', unless" - print_err " 'DRONE_BUILD_STATUS' indicates a failure." + print_err " 'CI_PIPELINE_STATUS'/'DRONE_BUILD_STATUS' indicates a failure." } # Blessed Stack Overflow @@ -38,6 +38,18 @@ rawurlencode() { echo "$encoded") } +default_woodpecker_message() { + local msg="Build ${CI_PIPELINE_STATUS}" + local woodpecker_url="${CI_SYSTEM_LINK}/${CI_REPO}/${CI_PIPELINE_NUMBER}" + if [ "$FORMAT" == "true" ]; then + msg="$msg [${CI_REPO}#${CI_COMMIT_SHA:0:8}]($woodpecker_url)" + else + msg="$msg $woodpecker_url" + fi + msg="$msg (${CI_COMMIT_TAG:-$CI_COMMIT_BRANCH})" + printf '%s' "$msg" +} + default_drone_message() { local msg="Build ${DRONE_BUILD_STATUS}" local drone_url="${DRONE_SYSTEM_PROTO}://${DRONE_SYSTEM_HOST}/${DRONE_REPO}/${DRONE_BUILD_NUMBER}" @@ -51,7 +63,9 @@ default_drone_message() { } ensure_variables() { - if [ "$DRONE" == "true" ] && [ -z "$MESSAGE" ]; then + if [ "$CI" == "woodpecker" ] && [ -z "$MESSAGE" ]; then + MESSAGE="$(default_woodpecker_message)" + elif [ "$DRONE" == "true" ] && [ -z "$MESSAGE" ]; then MESSAGE="$(default_drone_message)" fi @@ -69,7 +83,9 @@ ensure_variables() { get_message_type() { if [ "$MSG_TYPE" == "auto" ]; then - if [ "$DRONE_BUILD_STATUS" == "failure" ]; then + if [ "$CI_PIPELINE_STATUS" == "failure" ]; then + MSG_TYPE="text" + elif [ "$DRONE_BUILD_STATUS" == "failure" ]; then MSG_TYPE="text" else MSG_TYPE="notice" From 04758f81f23c693cca00f8eeb9e12eaa910353c4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 18 Mar 2023 12:48:28 +0000 Subject: [PATCH 10/17] flake: bump version to v0.3.0 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 00e1a27..7bda786 100644 --- a/flake.nix +++ b/flake.nix @@ -75,7 +75,7 @@ matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec { pname = "matrix-notifier"; - version = "0.2.0"; + version = "0.3.0"; src = ./matrix-notifier; From cb62f179a348a2dbd99041c93e293fe9b14e6de9 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 1 Apr 2023 16:41:16 +0100 Subject: [PATCH 11/17] ci: add Woodpecker CI workflow --- .woodpecker/check.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .woodpecker/check.yml diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml new file mode 100644 index 0000000..9de6915 --- /dev/null +++ b/.woodpecker/check.yml @@ -0,0 +1,26 @@ +labels: + type: exec + +pipeline: +- name: pre-commit checks + image: bash + commands: + - nix flake check + +- name: notifiy + image: bash + secrets: + - source: matrix_password + target: pass + - source: matrix_homeserver + target: address + - source: matrix_roomid + target: room + - source: matrix_username + target: user + commands: + - nix run . + when: + status: + - failure + - success From 436483aac7455fe7c157d8f247761bcd7c0abc62 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 1 Apr 2023 17:12:44 +0100 Subject: [PATCH 12/17] ci: remove Drone CI --- .drone.yml | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml deleted file mode 100644 index cd4c77d..0000000 --- a/.drone.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -kind: pipeline -type: exec -name: Matrix Notifier check - -steps: -- name: Pre-commit checks - commands: - - nix flake check - -- name: Notifiy - commands: - - nix run . - environment: - ADDRESS: - from_secret: matrix_homeserver - ROOM: - from_secret: matrix_roomid - USER: - from_secret: matrix_username - PASS: - from_secret: matrix_password - when: - status: - - failure - - success -... From d30a2d73667db3cfbcee7b65bdb9da1f98b0705e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 18 Nov 2023 20:20:45 +0000 Subject: [PATCH 13/17] ci: remove deprecated syntax --- .woodpecker/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml index 9de6915..39bd018 100644 --- a/.woodpecker/check.yml +++ b/.woodpecker/check.yml @@ -1,7 +1,7 @@ labels: type: exec -pipeline: +steps: - name: pre-commit checks image: bash commands: From a57f1cfa71e861ac4eb63b30a35ccc6c9db12370 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 18 Nov 2023 20:21:05 +0000 Subject: [PATCH 14/17] ci: add package check --- .woodpecker/check.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml index 39bd018..14aabfe 100644 --- a/.woodpecker/check.yml +++ b/.woodpecker/check.yml @@ -7,6 +7,11 @@ steps: commands: - nix flake check +- name: package check + image: bash + commands: + - nix build + - name: notifiy image: bash secrets: From 48dad0c96254421a77cee4969a36e401f659f0fc Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 18 Nov 2023 20:21:24 +0000 Subject: [PATCH 15/17] ci: use more explicit step name --- .woodpecker/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/check.yml b/.woodpecker/check.yml index 14aabfe..baa5da1 100644 --- a/.woodpecker/check.yml +++ b/.woodpecker/check.yml @@ -2,7 +2,7 @@ labels: type: exec steps: -- name: pre-commit checks +- name: flake check image: bash commands: - nix flake check From 37491e91e6599eec6b577243ea5c2e0bf3a0272b Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 14:33:39 +0000 Subject: [PATCH 16/17] matrix-notifier: fix link to pipeline --- matrix-notifier | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-notifier b/matrix-notifier index 0b99989..838396a 100755 --- a/matrix-notifier +++ b/matrix-notifier @@ -40,7 +40,7 @@ rawurlencode() { default_woodpecker_message() { local msg="Build ${CI_PIPELINE_STATUS}" - local woodpecker_url="${CI_SYSTEM_LINK}/${CI_REPO}/${CI_PIPELINE_NUMBER}" + local woodpecker_url="${CI_PIPELINE_URL}" if [ "$FORMAT" == "true" ]; then msg="$msg [${CI_REPO}#${CI_COMMIT_SHA:0:8}]($woodpecker_url)" else From 31b3b9fd2482a0704b5cfadb9ab440977d529d4d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 14:34:55 +0000 Subject: [PATCH 17/17] flake: bump version to v0.4.0 --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 7bda786..e02328a 100644 --- a/flake.nix +++ b/flake.nix @@ -75,7 +75,7 @@ matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec { pname = "matrix-notifier"; - version = "0.3.0"; + version = "0.4.0"; src = ./matrix-notifier;