4646 matrix :
4747 dockerfile : ${{ fromJson(needs.get-check-list.outputs.files) }}
4848 fail-fast : false
49+ # outputs:
50+ # comments: ${{ steps.build-check.outputs.comment_message }}
4951 steps :
5052 - name : Checkout PR branch
5153 uses : actions/checkout@v4
@@ -61,59 +63,73 @@ jobs:
6163 dockerfile : ${{ matrix.dockerfile }}
6264 run : |
6365 set -x
64- merged_commit=$(git log -1 --format='%H')
65-
66- [ -z "$dockerfile" ] && continue
67- dir=$(dirname "$dockerfile")
68- file=$(basename "$dockerfile")
69- image_base="pr-image-size-base:$(echo $dir | tr '/' '-')"
70- image_pr="pr-image-size-pr:$(echo $dir | tr '/' '-')"
71-
72- slash_count=$(grep -o "/" <<< "$dockerfile" | wc -l)
73- if [ "$slash_count" -eq 1 ]; then
74- cd "${{github.workspace}}/$dir"
75- elif [ "$slash_count" -gt 1 ]; then
76- if [[ "$dockerfile" == *"ui/"* ]]; then
77- dir=$(echo "$dir" | sed 's|\(.*\)/ui.*|\1/ui|')
78- cd "${{github.workspace}}/$dir"
79- file=docker/$file
80- image_base="pr-image-size-base:$(echo $dir | tr '/' '-')"
81- image_pr="pr-image-size-pr:$(echo $dir | tr '/' '-')"
82- elif [[ "$dockerfile" == *"WorkflowExecAgent/tests"* ]]; then
83- echo "Skipping $dockerfile"
84- exit 0
85- else
86- echo "Error: Multiple '/' in dockerfile path but no 'ui/' found."
87- exit 1
88- fi
89- fi
90-
91- echo "Building base image for $dockerfile"
92- git checkout ${{ github.event.pull_request.base.sha }}
93- echo "::group::Build image_base"
94- docker build -f "$file" -t "$image_base" --no-cache . || true
95- echo "::endgroup::"
96- size_base=$(docker image inspect "$image_base" | jq '.[0].Size / (1024 * 1024) | round')
97-
98- echo "Building PR image for $dockerfile"
99- git checkout $merged_commit
100- echo "PR: $merged_commit"
101- echo "::group::Build image_pr"
102- docker build -f "$file" -t "$image_pr" --no-cache . || true
103- echo "::endgroup::"
104- size_pr=$(docker image inspect "$image_pr" | jq '.[0].Size / (1024 * 1024) | round')
105-
106- diff=$((size_pr - size_base))
107- # echo "::warning::Image size change: $size_base -> $size_pr MB' (diff: $diff MB)"
108- echo "comment to ${{ github.event.pull_request.number }}"
109- if [ "$diff" -gt 50 ]; then
110- comment_message="⚠️ File '$dockerfile' resulted in a change in the image size from $size_base -> $size_pr MB (diff: $diff MB)"
111- else
112- comment_message="File '$dockerfile' resulted in a change in the image size from $size_base -> $size_pr MB (diff: $diff MB)"
113- fi
114- echo "comment_message=$comment_message" >> $GITHUB_OUTPUT
115- echo "File $dockerfile resulted in a change in the image size from $size_base -> $size_pr MB" >> $GITHUB_STEP_SUMMARY
116- docker rmi "$image_base" "$image_pr"
66+ # merged_commit=$(git log -1 --format='%H')
67+
68+ # [ -z "$dockerfile" ] && continue
69+ # dir=$(dirname "$dockerfile")
70+ # file=$(basename "$dockerfile")
71+ # image_base="pr-image-size-base:$(echo $dir | tr '/' '-')"
72+ # image_pr="pr-image-size-pr:$(echo $dir | tr '/' '-')"
73+
74+ # slash_count=$(grep -o "/" <<< "$dockerfile" | wc -l)
75+ # if [ "$slash_count" -eq 1 ]; then
76+ # cd "${{github.workspace}}/$dir"
77+ # elif [ "$slash_count" -gt 1 ]; then
78+ # if [[ "$dockerfile" == *"ui/"* ]]; then
79+ # dir=$(echo "$dir" | sed 's|\(.*\)/ui.*|\1/ui|')
80+ # cd "${{github.workspace}}/$dir"
81+ # file=docker/$file
82+ # image_base="pr-image-size-base:$(echo $dir | tr '/' '-')"
83+ # image_pr="pr-image-size-pr:$(echo $dir | tr '/' '-')"
84+ # elif [[ "$dockerfile" == *"WorkflowExecAgent/tests"* ]]; then
85+ # echo "Skipping $dockerfile"
86+ # exit 0
87+ # else
88+ # echo "Error: Multiple '/' in dockerfile path but no 'ui/' found."
89+ # exit 1
90+ # fi
91+ # fi
92+
93+ # echo "Building base image for $dockerfile"
94+ # git checkout ${{ github.event.pull_request.base.sha }}
95+ # echo "::group::Build image_base"
96+ # docker build -f "$file" -t "$image_base" --no-cache . || true
97+ # echo "::endgroup::"
98+ # size_base=$(docker image inspect "$image_base" | jq '.[0].Size / (1024 * 1024) | round')
99+
100+ # echo "Building PR image for $dockerfile"
101+ # git checkout $merged_commit
102+ # echo "PR: $merged_commit"
103+ # echo "::group::Build image_pr"
104+ # docker build -f "$file" -t "$image_pr" --no-cache . || true
105+ # echo "::endgroup::"
106+ # size_pr=$(docker image inspect "$image_pr" | jq '.[0].Size / (1024 * 1024) | round')
107+
108+ # diff=$((size_pr - size_base))
109+ # # echo "::warning::Image size change: $size_base -> $size_pr MB' (diff: $diff MB)"
110+ # echo "comment to ${{ github.event.pull_request.number }}"
111+ # if [ "$diff" -gt 50 ]; then
112+ # comment_message="⚠️ File '$dockerfile' resulted in a change in the image size from $size_base -> $size_pr MB (diff: $diff MB)"
113+ # else
114+ # comment_message="File '$dockerfile' resulted in a change in the image size from $size_base -> $size_pr MB (diff: $diff MB)"
115+ # fi
116+
117+ # echo "comment_message=$comment_message" >> $GITHUB_OUTPUT
118+ # echo "File $dockerfile resulted in a change in the image size from $size_base -> $size_pr MB" >> $GITHUB_STEP_SUMMARY
119+
120+ ##For debug
121+ comment_message="File size change"
122+ echo "comment_message=$comment_message" >> $GITHUB_STEP_SUMMARY
123+ echo "Summary file path: $GITHUB_STEP_SUMMARY"
124+ ls -la $(dirname "$GITHUB_STEP_SUMMARY")
125+ cat $GITHUB_STEP_SUMMARY
126+ # docker rmi "$image_base" "$image_pr"
127+
128+ - name : Save Summary as Artifact
129+ uses : actions/upload-artifact@v4.3.4
130+ with :
131+ name : comments-summary
132+ path : $GITHUB_STEP_SUMMARY
117133
118134 collect-comments :
119135 needs : build-and-check
@@ -122,45 +138,48 @@ jobs:
122138 outputs :
123139 all_comments : ${{ steps.collect.outputs.all_comments }}
124140 steps :
125- - name : Collect all comment messages
126- id : collect
127- run : |
128- echo "raw outputs: ${{ toJson(needs.build-check.comment_message) }}"
129- comments=$(echo '${{ toJson(needs.build-check.comment_message) }}' | jq -r 'to_entries[] | select(.value != null and .value != "") | .value' | sed ':a;N;$!ba;s/\n/\\n/g')
130- echo "all_comments=$comments"
131- echo "all_comments=$comments" >> $GITHUB_OUTPUT
141+ - name : Download Summary
142+ uses : actions/download-artifact@v4.3.4
143+ with :
144+ name : comments-summary
145+ path : downloaded-summary/
132146
133- Post-comment-on-PR :
134- needs : collect-comments
135- runs-on : ubuntu-latest
136- permissions :
137- contents : read
138- pull-requests : write
139- if : always() && needs.collect-comments.outputs.all_comments != ''
140- steps :
141- - name : Post comment on PR
142- env :
143- all_comments : ${{ needs.collect-comments.outputs.all_comments }}
144- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
147+ - name : Read Summary
145148 run : |
146- echo "comment ${all_comments}"
147-
148- comment_id=$(curl -s \
149- -H "Authorization: token ${GITHUB_TOKEN}" \
150- -H "Accept: application/vnd.github.v3+json" \
151- "https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.pull_request.number }}" \
152- | jq '.[] | select(.user.login=="github-actions[bot]") | .id' | tail -n1)
153-
154- if [ -n "$comment_id" ]; then
155- curl -X PATCH \
156- -H "Authorization: token ${GITHUB_TOKEN}" \
157- -H "Accept: application/vnd.github.v3+json" \
158- "https://api.github.com/repos/opea-project/GenAIExamples/issues/${{ github.event.pull_request.number }}/comments" \
159- -d '{"body":"'"$all_comments"'"}'
160- else
161- curl -X POST \
162- -H "Authorization: token ${GITHUB_TOKEN}" \
163- -H "Accept: application/vnd.github.v3+json" \
164- "https://api.github.com/repos/opea-project/GenAIExamples/issues/${{ github.event.pull_request.number }}/comments" \
165- -d '{"body":"'"$all_comments"'"}'
166- fi
149+ ls downloaded-summary/
150+ # cat /tmp/step_summary_*.md
151+
152+ # Post-comment-on-PR:
153+ # needs: collect-comments
154+ # runs-on: ubuntu-latest
155+ # permissions:
156+ # contents: read
157+ # pull-requests: write
158+ # if: always() && needs.collect-comments.outputs.all_comments != ''
159+ # steps:
160+ # - name: Post comment on PR
161+ # env:
162+ # all_comments: ${{ needs.collect-comments.outputs.all_comments }}
163+ # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
164+ # run: |
165+ # echo "comment ${all_comments}"
166+ # json_body=$(jq -n --arg msg "$all_comments" '{"body": $msg}')
167+ # comment_id=$(curl -s \
168+ # -H "Authorization: token ${GITHUB_TOKEN}" \
169+ # -H "Accept: application/vnd.github.v3+json" \
170+ # "https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.pull_request.number }}" \
171+ # | jq '.[] | select(.user.login=="github-actions[bot]") | .id' | tail -n1)
172+
173+ # if [ -n "$comment_id" ]; then
174+ # curl -X PATCH \
175+ # -H "Authorization: token ${GITHUB_TOKEN}" \
176+ # -H "Accept: application/vnd.github.v3+json" \
177+ # "https://api.github.com/repos/opea-project/GenAIExamples/issues/${{ github.event.pull_request.number }}/comments" \
178+ # -d "$json_body"
179+ # else
180+ # curl -X POST \
181+ # -H "Authorization: token ${GITHUB_TOKEN}" \
182+ # -H "Accept: application/vnd.github.v3+json" \
183+ # "https://api.github.com/repos/opea-project/GenAIExamples/issues/${{ github.event.pull_request.number }}/comments" \
184+ # -d "$json_body"
185+ # fi
0 commit comments