Skip to content

Commit fb93aa0

Browse files
enhance dyff job to print in single document
1 parent 7f80ff1 commit fb93aa0

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,40 @@ jobs:
191191
fi
192192
193193
if [ ! -f "$RUNNER_TEMP/old/$templates_file" ]; then
194-
file_content=$(sed -e 's/^/+ /' < "$RUNNER_TEMP/new/$templates_file")
195-
comment_templates_body+="<details><summary>$current_file (added)</summary>\n"
196-
comment_templates_body+='\n```diff\n'
197-
comment_templates_body+="# The full content of the file is available in ${ARTIFACT_URL}\n"
198-
comment_templates_body+=$(head -n 5 <<< "$file_content")
199-
comment_templates_body+='\n...\n```\n</details>\n\n'
194+
api_version=$(yq '.apiVersion' "$RUNNER_TEMP/new/$templates_file")
195+
kind=$(yq '.kind' "$RUNNER_TEMP/new/$templates_file")
196+
name=$(yq '.metadata.name' "$RUNNER_TEMP/new/$templates_file")
197+
namespace=$(yq '.metadata.namespace' "$RUNNER_TEMP/new/$templates_file")
198+
metadata=$(yq '.metadata' "$RUNNER_TEMP/new/$templates_file")
199+
comment_templates_body+="@@ $current_file @@\n"
200+
comment_templates_body+="# $api_version/$kind/$namespace/$name\n"
201+
comment_templates_body+="! + one file added - the full content of the file is available in ${ARTIFACT_URL}\n"
202+
comment_templates_body+="+ apiVersion: $api_version\n"
203+
comment_templates_body+="+ kind: $kind\n"
204+
comment_templates_body+="+ metadata:\n"
205+
while IFS= read -r line; do
206+
comment_templates_body+="+ $line\n"
207+
done <<< "$metadata"
208+
comment_templates_body+="\n\n"
200209
continue
201210
fi
202211
203212
if [ ! -f "$RUNNER_TEMP/new/$templates_file" ]; then
204-
comment_templates_body+="**$current_file** (removed)\n\n"
213+
api_version=$(yq '.apiVersion' "$RUNNER_TEMP/old/$templates_file" )
214+
kind=$(yq '.kind' "$RUNNER_TEMP/old/$templates_file")
215+
name=$(yq '.metadata.name' "$RUNNER_TEMP/old/$templates_file")
216+
namespace=$(yq '.metadata.namespace' "$RUNNER_TEMP/old/$templates_file")
217+
metadata=$(yq '.metadata' "$RUNNER_TEMP/old/$templates_file")
218+
comment_templates_body+="@@ $current_file @@\n"
219+
comment_templates_body+="# $api_version/$kind/$namespace/$name\n"
220+
comment_templates_body+="! - one file removed\n"
221+
comment_templates_body+="- apiVersion: $api_version\n"
222+
comment_templates_body+="- kind: $kind\n"
223+
comment_templates_body+="- metadata:\n"
224+
while IFS= read -r line; do
225+
comment_templates_body+="- $line\n"
226+
done <<< "$metadata"
227+
comment_templates_body+="\n\n"
205228
continue
206229
fi
207230
@@ -212,17 +235,23 @@ jobs:
212235
echo "failed with file $templates_file"
213236
exit 1
214237
fi
215-
comment_templates_body+="<details><summary>$current_file (changed)</summary>\n"
216-
comment_templates_body+='\n```diff\n'
217-
comment_templates_body+=$dyff_detail
218-
comment_templates_body+='\n```\n</details>\n\n'
238+
239+
api_version=$(yq '.apiVersion' "$RUNNER_TEMP/new/$templates_file")
240+
kind=$(yq '.kind' "$RUNNER_TEMP/new/$templates_file")
241+
name=$(yq '.metadata.name' "$RUNNER_TEMP/new/$templates_file")
242+
namespace=$(yq '.metadata.namespace' "$RUNNER_TEMP/new/$templates_file")
243+
resource_metadata="# $api_version/$kind/$namespace/$name"
244+
comment_templates_body+=$(sed -e "1d" -e "/^@@/a$resource_metadata" <<< "$dyff_detail")
245+
comment_templates_body+="\n\n\n"
219246
fi
220247
done <<< "$templates_files"
221248
222249
if [[ -n "$comment_templates_body" ]]; then
223250
comment_body+="<details><summary><b>$values_dir.yaml</b></summary>\n"
251+
comment_body+='\n```diff\n'
224252
comment_body+="$comment_templates_body"
225-
comment_body+="---\n</details>\n"
253+
comment_body+='```\n'
254+
comment_body+="\n</details>\n"
226255
fi
227256
228257
done <<< "$values_directories"
@@ -231,7 +260,7 @@ jobs:
231260
comment_body="No changes in rendered templates"
232261
fi
233262
234-
echo -e "$header$comment_body" | tee "$RUNNER_TEMP/dyff-output"
263+
echo -e "$header$comment_body" | tee "$RUNNER_TEMP/dyff-output.md"
235264
236265
- name: Upload generated manifests
237266
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
@@ -255,5 +284,5 @@ jobs:
255284
with:
256285
comment-id: ${{ steps.find-dyff-comment.outputs.comment-id }}
257286
issue-number: ${{ github.event.pull_request.number }}
258-
body-path: ${{ runner.temp }}/dyff-output
287+
body-path: ${{ runner.temp }}/dyff-output.md
259288
edit-mode: replace

newsfragments/548.internal.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CI: Enhance dyff jobs output to print yaml manifests in a single block code.

0 commit comments

Comments
 (0)