Skip to content

Commit 3f0bcba

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

1 file changed

Lines changed: 43 additions & 13 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,40 @@ 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"
209+
comment_templates_body+="\n\n"
200210
continue
201211
fi
202212
203213
if [ ! -f "$RUNNER_TEMP/new/$templates_file" ]; then
204-
comment_templates_body+="**$current_file** (removed)\n\n"
214+
api_version=$(yq '.apiVersion' "$RUNNER_TEMP/old/$templates_file" )
215+
kind=$(yq '.kind' "$RUNNER_TEMP/old/$templates_file")
216+
name=$(yq '.metadata.name' "$RUNNER_TEMP/old/$templates_file")
217+
namespace=$(yq '.metadata.namespace' "$RUNNER_TEMP/old/$templates_file")
218+
metadata=$(yq '.metadata' "$RUNNER_TEMP/old/$templates_file")
219+
comment_templates_body+="@@ $current_file @@\n"
220+
comment_templates_body+="# $api_version/$kind/$namespace/$name\n"
221+
comment_templates_body+="! - one file removed\n"
222+
comment_templates_body+="- apiVersion: $api_version\n"
223+
comment_templates_body+="- kind: $kind\n"
224+
comment_templates_body+="- metadata:\n"
225+
while IFS= read -r line; do
226+
comment_templates_body+="- $line\n"
227+
done <<< "$metadata"
228+
comment_templates_body+="\n\n"
205229
continue
206230
fi
207231
@@ -212,17 +236,23 @@ jobs:
212236
echo "failed with file $templates_file"
213237
exit 1
214238
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'
239+
240+
api_version=$(yq '.apiVersion' "$RUNNER_TEMP/new/$templates_file")
241+
kind=$(yq '.kind' "$RUNNER_TEMP/new/$templates_file")
242+
name=$(yq '.metadata.name' "$RUNNER_TEMP/new/$templates_file")
243+
namespace=$(yq '.metadata.namespace' "$RUNNER_TEMP/new/$templates_file")
244+
resource_metadata="# $api_version/$kind/$namespace/$name"
245+
comment_templates_body+=$(sed -e "1d" -e "/^@@/a$resource_metadata" <<< "$dyff_detail")
246+
comment_templates_body+="\n\n\n"
219247
fi
220248
done <<< "$templates_files"
221249
222250
if [[ -n "$comment_templates_body" ]]; then
223251
comment_body+="<details><summary><b>$values_dir.yaml</b></summary>\n"
252+
comment_body+='\n```diff\n'
224253
comment_body+="$comment_templates_body"
225-
comment_body+="---\n</details>\n"
254+
comment_body+='```\n'
255+
comment_body+="\n</details>\n"
226256
fi
227257
228258
done <<< "$values_directories"
@@ -231,7 +261,7 @@ jobs:
231261
comment_body="No changes in rendered templates"
232262
fi
233263
234-
echo -e "$header$comment_body" | tee "$RUNNER_TEMP/dyff-output"
264+
echo -e "$header$comment_body" | tee "$RUNNER_TEMP/dyff-output.md"
235265
236266
- name: Upload generated manifests
237267
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
@@ -255,5 +285,5 @@ jobs:
255285
with:
256286
comment-id: ${{ steps.find-dyff-comment.outputs.comment-id }}
257287
issue-number: ${{ github.event.pull_request.number }}
258-
body-path: ${{ runner.temp }}/dyff-output
288+
body-path: ${{ runner.temp }}/dyff-output.md
259289
edit-mode: replace

0 commit comments

Comments
 (0)