Compare commits
1 commit
main
...
919c98f67c
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 919c98f67c |
27
.drone.yml
Normal file
27
.drone.yml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
---
|
||||||
|
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
|
||||||
|
...
|
|
@ -1,31 +0,0 @@
|
||||||
labels:
|
|
||||||
type: exec
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: flake check
|
|
||||||
image: bash
|
|
||||||
commands:
|
|
||||||
- nix flake check
|
|
||||||
|
|
||||||
- name: package check
|
|
||||||
image: bash
|
|
||||||
commands:
|
|
||||||
- nix build
|
|
||||||
|
|
||||||
- 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
|
|
|
@ -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.
|
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
|
The only dependencies are `bash`, `curl`, and `jq`, install those and you should
|
||||||
be ready to go! Format is needed when using formatting (enabled by default).
|
be ready to go!
|
||||||
|
|
22
flake.nix
22
flake.nix
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "A simple Matrix notifier for CI purposes";
|
description = "Ambroisie's blog";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
futils = {
|
futils = {
|
||||||
|
@ -36,8 +36,6 @@
|
||||||
in
|
in
|
||||||
rec {
|
rec {
|
||||||
apps = {
|
apps = {
|
||||||
default = apps.matrix-notifier;
|
|
||||||
|
|
||||||
matrix-notifier =
|
matrix-notifier =
|
||||||
futils.lib.mkApp { drv = packages.matrix-notifier; };
|
futils.lib.mkApp { drv = packages.matrix-notifier; };
|
||||||
};
|
};
|
||||||
|
@ -58,24 +56,26 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells = {
|
defaultApp = apps.matrix-notifier;
|
||||||
default = pkgs.mkShell {
|
|
||||||
|
defaultPackage = packages.matrix-notifier;
|
||||||
|
|
||||||
|
devShell = pkgs.mkShell {
|
||||||
name = "matrix-notifier";
|
name = "matrix-notifier";
|
||||||
|
|
||||||
inputsFrom = with self.packages.${system}; [
|
buildInputs = with pkgs; [
|
||||||
matrix-notifier
|
curl
|
||||||
|
jq
|
||||||
|
shellcheck
|
||||||
];
|
];
|
||||||
|
|
||||||
inherit (self.checks.${system}.pre-commit) shellHook;
|
inherit (self.checks.${system}.pre-commit) shellHook;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
packages = {
|
packages = {
|
||||||
default = packages.matrix-notifier;
|
|
||||||
|
|
||||||
matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec {
|
matrix-notifier = pkgs.stdenvNoCC.mkDerivation rec {
|
||||||
pname = "matrix-notifier";
|
pname = "matrix-notifier";
|
||||||
version = "0.4.0";
|
version = "0.1.2";
|
||||||
|
|
||||||
src = ./matrix-notifier;
|
src = ./matrix-notifier;
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,11 @@ usage() {
|
||||||
print_err ""
|
print_err ""
|
||||||
print_err " -h, --help"
|
print_err " -h, --help"
|
||||||
print_err " print this usage screen and exit"
|
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 " -t, --type"
|
||||||
print_err " which message type should be sent must be one of"
|
print_err " which message type should be sent must be one of"
|
||||||
print_err " 'text' or 'notice', or 'auto'."
|
print_err " 'text' or 'notice', or 'auto'."
|
||||||
print_err " The special value 'auto' defaults to 'notice', unless"
|
print_err " The special value 'auto' defaults to 'notice', unless"
|
||||||
print_err " 'CI_PIPELINE_STATUS'/'DRONE_BUILD_STATUS' indicates a failure."
|
print_err " 'DRONE_BUILD_STATUS' indicates a failure."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Blessed Stack Overflow
|
# Blessed Stack Overflow
|
||||||
|
@ -38,34 +35,15 @@ rawurlencode() {
|
||||||
echo "$encoded")
|
echo "$encoded")
|
||||||
}
|
}
|
||||||
|
|
||||||
default_woodpecker_message() {
|
|
||||||
local msg="Build ${CI_PIPELINE_STATUS}"
|
|
||||||
local woodpecker_url="${CI_PIPELINE_URL}"
|
|
||||||
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() {
|
default_drone_message() {
|
||||||
local msg="Build ${DRONE_BUILD_STATUS}"
|
local msg="Build *${DRONE_BUILD_STATUS}*"
|
||||||
local drone_url="${DRONE_SYSTEM_PROTO}://${DRONE_SYSTEM_HOST}/${DRONE_REPO}/${DRONE_BUILD_NUMBER}"
|
msg="$msg ${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})"
|
msg="$msg (${DRONE_TAG:-$DRONE_BRANCH})"
|
||||||
printf '%s' "$msg"
|
printf '%s' "$msg"
|
||||||
}
|
}
|
||||||
|
|
||||||
ensure_variables() {
|
ensure_variables() {
|
||||||
if [ "$CI" == "woodpecker" ] && [ -z "$MESSAGE" ]; then
|
if [ "$DRONE" == "true" ] && [ -z "$MESSAGE" ]; then
|
||||||
MESSAGE="$(default_woodpecker_message)"
|
|
||||||
elif [ "$DRONE" == "true" ] && [ -z "$MESSAGE" ]; then
|
|
||||||
MESSAGE="$(default_drone_message)"
|
MESSAGE="$(default_drone_message)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -83,9 +61,7 @@ ensure_variables() {
|
||||||
|
|
||||||
get_message_type() {
|
get_message_type() {
|
||||||
if [ "$MSG_TYPE" == "auto" ]; then
|
if [ "$MSG_TYPE" == "auto" ]; then
|
||||||
if [ "$CI_PIPELINE_STATUS" == "failure" ]; then
|
if [ "$DRONE_BUILD_STATUS" == "failure" ]; then
|
||||||
MSG_TYPE="text"
|
|
||||||
elif [ "$DRONE_BUILD_STATUS" == "failure" ]; then
|
|
||||||
MSG_TYPE="text"
|
MSG_TYPE="text"
|
||||||
else
|
else
|
||||||
MSG_TYPE="notice"
|
MSG_TYPE="notice"
|
||||||
|
@ -96,13 +72,12 @@ get_message_type() {
|
||||||
}
|
}
|
||||||
|
|
||||||
make_message_json() {
|
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 |
|
pandoc |
|
||||||
jq --raw-input --slurp "{format: \"org.matrix.custom.html\", formatted_body: .}"
|
jq --raw-input --slurp "{format: \"org.matrix.custom.html\", formatted_body: .}") \
|
||||||
} | jq -s 'add'
|
<(printf '%s' "$1" |
|
||||||
|
jq --raw-input --slurp "{msgtype: \"$(get_message_type)\", body: .}")
|
||||||
}
|
}
|
||||||
|
|
||||||
send_message() {
|
send_message() {
|
||||||
|
@ -135,25 +110,12 @@ send_message() {
|
||||||
}
|
}
|
||||||
|
|
||||||
MSG_TYPE='auto'
|
MSG_TYPE='auto'
|
||||||
FORMAT='true'
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
opt="$1"
|
opt="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
case "$opt" in
|
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)
|
-t|--type)
|
||||||
arg="$1"
|
arg="$1"
|
||||||
shift
|
shift
|
||||||
|
|
Loading…
Reference in a new issue