From 366d35039bdff89ca46de9e1a1f9b9ff01614485 Mon Sep 17 00:00:00 2001 From: DavHau Date: Fri, 28 Jul 2023 13:04:09 +0200 Subject: [PATCH] action-ensure-tea-login: init --- .../action-ensure-tea-login/default.nix | 23 +++++++++++++++++++ flake-parts/action-ensure-tea-login/script.sh | 12 ++++++++++ 2 files changed, 35 insertions(+) create mode 100644 flake-parts/action-ensure-tea-login/default.nix create mode 100644 flake-parts/action-ensure-tea-login/script.sh diff --git a/flake-parts/action-ensure-tea-login/default.nix b/flake-parts/action-ensure-tea-login/default.nix new file mode 100644 index 0000000..d137837 --- /dev/null +++ b/flake-parts/action-ensure-tea-login/default.nix @@ -0,0 +1,23 @@ +{ + perSystem = + { config + , pkgs + , ... + }: + let + name = builtins.baseNameOf ./.; + script = config.writers.writePureShellScriptBin + name + [ + pkgs.bash + pkgs.coreutils + pkgs.tea + ] + '' + bash ${./script.sh} + ''; + in + { + packages.${name} = script; + }; +} diff --git a/flake-parts/action-ensure-tea-login/script.sh b/flake-parts/action-ensure-tea-login/script.sh new file mode 100644 index 0000000..4185f5d --- /dev/null +++ b/flake-parts/action-ensure-tea-login/script.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ "$(tea login list -o simple | wc -l)" -gt 0 ]; then + exit 0 +fi + +GITEA_TOKEN="${GITEA_TOKEN:-"$(cat "$GITEA_TOKEN_FILE")"}" + +tea login add \ + --token $GITEA_TOKEN \ + --url $GITEA_URL