From 0f52ee9b6b5379b644f6adcea93b741c83a1c314 Mon Sep 17 00:00:00 2001 From: Juanjo Presa Date: Tue, 30 Jul 2024 14:22:17 +0200 Subject: [PATCH] wip --- .../blockTypes/_postDiffToGitHubSnippet.nix | 13 ++++---- src/std/fwlib/blockTypes/kubectl.nix | 2 +- src/std/fwlib/blockTypes/terra.nix | 30 +++++++++---------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/src/std/fwlib/blockTypes/_postDiffToGitHubSnippet.nix b/src/std/fwlib/blockTypes/_postDiffToGitHubSnippet.nix index b50f0be6..607857f6 100644 --- a/src/std/fwlib/blockTypes/_postDiffToGitHubSnippet.nix +++ b/src/std/fwlib/blockTypes/_postDiffToGitHubSnippet.nix @@ -1,8 +1,10 @@ -_: cmd: script: '' +_: path: cmd: script: '' # GitHub case if [[ -v CI ]] && [[ -v BRANCH ]] && [[ -v OWNER_AND_REPO ]] && command gh > /dev/null ; then + gh pr view "$BRANCH" >/dev/null || exit 0 + set +e # diff exits 1 if diff existed read -r -d "" DIFFSTREAM <Preview +
${path} \`\`\`diff $(${script}) @@ -21,11 +23,8 @@ _: cmd: script: '' set -e # we're past the invocation of diff - if ! gh pr --repo "$OWNER_AND_REPO" comment "$BRANCH" --edit-last -b "$DIFFSTREAM"; then - echo "Make a first post ..." - gh pr --repo "$OWNER_AND_REPO" comment "$BRANCH" -b "$DIFFSTREAM" - fi - + gh pr --repo "$OWNER_AND_REPO" comment "$BRANCH" -b "$DIFFSTREAM" + exit 0 fi diff --git a/src/std/fwlib/blockTypes/kubectl.nix b/src/std/fwlib/blockTypes/kubectl.nix index 05342133..cc9f0192 100644 --- a/src/std/fwlib/blockTypes/kubectl.nix +++ b/src/std/fwlib/blockTypes/kubectl.nix @@ -137,7 +137,7 @@ in } "$manifest_path/"; } - ${postDiffToGitHubSnippet "kubectl" "diff"} + ${postDiffToGitHubSnippet fragmentRelPath "kubectl" "diff"} KUBECTL_EXTERNAL_DIFF="icdiff -N -r" export KUBECTL_EXTERNAL_DIFF diff --git a/src/std/fwlib/blockTypes/terra.nix b/src/std/fwlib/blockTypes/terra.nix index 98f9aaef..201f0231 100644 --- a/src/std/fwlib/blockTypes/terra.nix +++ b/src/std/fwlib/blockTypes/terra.nix @@ -79,28 +79,26 @@ in wrap = cmd: setup - + ( - (pkgs.lib.optionalString (cmd == "plan")) ( - postDiffToGitHubSnippet cmd '' - terraform-backend-git git \ - --dir "$dir" \ - --repository ${git.repo} \ - --ref ${git.ref} \ - --state ${git.state} \ - terraform plan \ - -lock=false \ - -no-color - '' - ) - ) + '' terraform-backend-git git \ --dir "$dir" \ --repository ${git.repo} \ --ref ${git.ref} \ --state ${git.state} \ - terraform ${cmd} "$@"; - ''; + terraform ${cmd} ${pkgs.lib.optionalString (cmd == "plan") "-out=\"$dir/plan\""} "$@"; + '' + + ( + (pkgs.lib.optionalString (cmd == "plan")) ( + postDiffToGitHubSnippet fragmentRelPath cmd '' + terraform-backend-git git \ + --dir "$dir" \ + --repository ${git.repo} \ + --ref ${git.ref} \ + --state ${git.state} \ + terraform show -no-color "$dir/plan" + '' + ) + ); in [ (mkCommand currentSystem "init" "tf init" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "init") {}) (mkCommand currentSystem "plan" "tf plan" [pkgs.jq pkgs.terraform pkgs.terraform-backend-git] (wrap "plan") {})