Skip to content

Commit 16edd0f

Browse files
committed
feat(kubectl): publish diff if on github ci as PR comment
1 parent b71778b commit 16edd0f

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/std/fwlib/blockTypes/kubectl.nix

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ in
123123
${build}
124124
build
125125
126-
KUBECTL_EXTERNAL_DIFF="icdiff -N -r"
127-
export KUBECTL_EXTERNAL_DIFF
128-
129126
diff() {
130127
kubectl diff ${
131128
if usesKustomize
@@ -134,7 +131,34 @@ in
134131
} "$manifest_path";
135132
}
136133
137-
diff
134+
# GitHub case
135+
if [[ -v CI ]] && [[ -v BRANCH ]] && [[ -v OWNER_AND_REPO ]] && command gh > /dev/null ; then
136+
137+
set +e # diff exits 1 if diff existed
138+
read -r -d "" DIFFSTREAM <<DIFF
139+
## Standard DiffPost
140+
141+
This PR would generate the following \`kubectl\` diff:
142+
143+
<details><summary>Preview</summary>
144+
145+
\`\`\`diff
146+
$(diff)
147+
\`\`\`
148+
149+
</details>
150+
DIFF
151+
set -e # we're past the invocation of diff
152+
153+
if ! gh pr --repo "$OWNER_AND_REPO" comment "$BRANCH" --edit-last -b "$DIFFSTREAM"; then
154+
echo "Make a first post ..."
155+
gh pr --repo "$OWNER_AND_REPO" comment "$BRANCH" -b "$DIFFSTREAM"
156+
fi
157+
else
158+
KUBECTL_EXTERNAL_DIFF="icdiff -N -r"
159+
export KUBECTL_EXTERNAL_DIFF
160+
diff
161+
fi
138162
'' {})
139163
(mkCommand currentSystem "apply" "Apply the manifests to K8s" [pkgs.kubectl pkgs.icdiff] ''
140164
${build}

0 commit comments

Comments
 (0)