Skip to content

Commit

Permalink
use new diffSnippet function
Browse files Browse the repository at this point in the history
  • Loading branch information
oneingan committed Oct 24, 2024
1 parent 9f75d7d commit 52ef13e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
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 fragmentRelPath "kubectl" "diff"}
${postDiffToGitHubSnippet "${fragmentRelPath}:diff" "$(diff || true)" "<code>std ${fragmentRelPath}:diff</code>"}
KUBECTL_EXTERNAL_DIFF="icdiff -N -r"
export KUBECTL_EXTERNAL_DIFF
Expand Down
24 changes: 11 additions & 13 deletions src/std/fwlib/blockTypes/terra.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ in
inherit (inputs) terranix;
pkgs = inputs.nixpkgs.${currentSystem};

repoFolder = with pkgs.lib;
concatStringsSep "/" (["./nix"] ++ (init (splitString "/" fragmentRelPath)));

git = {
inherit repo;
# repo = "[email protected]:myorg/myrepo.git";
ref = "main";
state = fragmentRelPath + "/state.json";
};
Expand All @@ -67,7 +63,7 @@ in
export TF_PLUGIN_CACHE_DIR="$PRJ_CACHE_HOME/tf-plugin-cache"
mkdir -p "$TF_DATA_DIR"
mkdir -p "$TF_PLUGIN_CACHE_DIR"
dir="$PRJ_ROOT/.cache/${fragmentRelPath}/.tf"
dir="$PRJ_ROOT/.tf/${fragmentRelPath}/.tf"
mkdir -p "$dir"
cat << MESSAGE > "$dir/readme.md"
This is a tf staging area.
Expand All @@ -81,20 +77,22 @@ in
${setup}
# Run the command and capture output
export TF_CLI_ARGS_plan="-lock=false -no-color"
export TF_CLI_ARGS_plan=""
terraform-backend-git git \
--dir "$dir" \
--repository ${git.repo} \
--ref ${git.ref} \
--state ${git.state} \
terraform ${cmd} "$@" \
${pkgs.lib.optionalString (cmd == "plan") "| tee \"$PRJ_CACHE_HOME/tf.console.txt\""}
--dir "$dir" \
--repository ${git.repo} \
--ref ${git.ref} \
--state ${git.state} \
terraform ${cmd} "$@" \
${pkgs.lib.optionalString (cmd == "plan") ''
-lock=false -no-color | tee "$PRJ_CACHE_HOME/tf.console.txt"
''}
# Pass output to the snippet
${pkgs.lib.optionalString (cmd == "plan") ''
output=$(cat "$PRJ_CACHE_HOME/tf.console.txt")
summary_plan=$(tac "$PRJ_CACHE_HOME/tf.console.txt" | grep -m 1 -E '^(Error:|Plan:|Apply complete!|No changes.|Success)' | tac || echo "View output.")
summary="\`std ${fragmentRelPath}:${cmd}\`: $summary_plan"
summary="<code>std ${fragmentRelPath}:${cmd}</code>: $summary_plan"
${postDiffToGitHubSnippet "${fragmentRelPath}:${cmd}" "$output" "$summary"}
''}
'';
Expand Down

0 comments on commit 52ef13e

Please sign in to comment.