Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
oneingan committed Jul 30, 2024
1 parent 63de519 commit 0f52ee9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
13 changes: 6 additions & 7 deletions src/std/fwlib/blockTypes/_postDiffToGitHubSnippet.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
_: 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 <<DIFF
## DiffPost
This PR would generate the following \`${cmd}\` diff:
<details><summary>Preview</summary>
<details><summary>${path}</summary>
\`\`\`diff
$(${script})
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/std/fwlib/blockTypes/kubectl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ in
} "$manifest_path/";
}
${postDiffToGitHubSnippet "kubectl" "diff"}
${postDiffToGitHubSnippet fragmentRelPath "kubectl" "diff"}
KUBECTL_EXTERNAL_DIFF="icdiff -N -r"
export KUBECTL_EXTERNAL_DIFF
Expand Down
30 changes: 14 additions & 16 deletions src/std/fwlib/blockTypes/terra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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") {})
Expand Down

0 comments on commit 0f52ee9

Please sign in to comment.