diff --git a/flake-parts/action-create-pr/default.nix b/flake-parts/action-create-pr/default.nix new file mode 100644 index 0000000..46e4e75 --- /dev/null +++ b/flake-parts/action-create-pr/default.nix @@ -0,0 +1,25 @@ +{ + perSystem = + { config + , pkgs + , ... + }: + let + name = builtins.baseNameOf ./.; + script = config.writers.writePureShellScriptBin + name + [ + pkgs.bash + pkgs.coreutils + pkgs.git + pkgs.tea + pkgs.openssh + ] + '' + bash ${./script.sh} + ''; + in + { + packages.${name} = script; + }; +} diff --git a/flake-parts/action-create-pr/script.sh b/flake-parts/action-create-pr/script.sh new file mode 100644 index 0000000..56c1117 --- /dev/null +++ b/flake-parts/action-create-pr/script.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +set -euo pipefail + +REMOTE_BRANCH="${REMOTE_BRANCH:-auto-pr}" +PR_TITLE="${PR_TITLE:-'This PR was created automatically'}" + +git diff --quiet || { + echo -e "\e[31mWorking tree is dirty, please commit first\e[0m" + git status + exit 1 +} + +git push origin "HEAD:$REMOTE_BRANCH" + +tea pr create \ + --head "$REMOTE_BRANCH" \ + --labels "0.kind: automation" \ + --title "$PR_TITLE" diff --git a/flake.nix b/flake.nix index f9c6afb..28537af 100644 --- a/flake.nix +++ b/flake.nix @@ -43,7 +43,7 @@ inputs.treefmt-nix.flakeModule inputs.clan-core.modules.flake-parts.writers ./flake-parts/action-flake-update - ./flake-parts/action-open-pull-request + ./flake-parts/action-create-pr ./targets/flake-module.nix ./modules/flake-module.nix ./pkgs/flake-module.nix