Skip to content

Commit 3e548bc

Browse files
enhance dyff job to print in single document
1 parent 1787463 commit 3e548bc

1 file changed

Lines changed: 42 additions & 13 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,38 @@ jobs:
192192
193193
if [ ! -f "$RUNNER_TEMP/old/$templates_file" ]; then
194194
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'
195+
api_version=$(yq '.apiVersion' "$RUNNER_TEMP/new/$templates_file")
196+
kind=$(yq '.kind' "$RUNNER_TEMP/new/$templates_file")
197+
name=$(yq '.metadata.name' "$RUNNER_TEMP/new/$templates_file")
198+
namespace=$(yq '.metadata.namespace' "$RUNNER_TEMP/new/$templates_file")
199+
metadata=$(yq '.metadata' "$RUNNER_TEMP/new/$templates_file")
200+
comment_templates_body+="@@ $current_file @@\n"
201+
comment_templates_body+="# $api_version/$kind/$namespace/$name\n"
202+
comment_templates_body+="! + one file added - the full content of the file is available in ${ARTIFACT_URL}\n"
203+
comment_templates_body+="+ apiVersion: $api_version\n"
204+
comment_templates_body+="+ kind: $kind\n"
205+
comment_templates_body+="+ metadata:\n"
206+
while IFS= read -r line; do
207+
comment_templates_body+="+ $line\n"
208+
done <<< "$metadata"
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.namespace' "$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"
205227
continue
206228
fi
207229
@@ -212,17 +234,24 @@ jobs:
212234
echo "failed with file $templates_file"
213235
exit 1
214236
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'
237+
238+
api_version=$(yq '.apiVersion' "$RUNNER_TEMP/new/$templates_file")
239+
kind=$(yq '.kind' "$RUNNER_TEMP/new/$templates_file")
240+
name=$(yq '.metadata.name' "$RUNNER_TEMP/new/$templates_file")
241+
namespace=$(yq '.metadata.namespace' "$RUNNER_TEMP/new/$templates_file")
242+
resource_metadata="# $api_version/$kind/$namespace/$name"
243+
comment_templates_body+='\n'
244+
comment_templates_body+=$(sed "/^@@/a$resource_metadata" <<< "$dyff_detail")
219245
fi
246+
comment_templates_body="\n"
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```\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

0 commit comments

Comments
 (0)