Skip to content

Commit 2e4bd03

Browse files
committed
test
Signed-off-by: ZePan110 <ze.pan@intel.com>
1 parent e01249d commit 2e4bd03

1 file changed

Lines changed: 108 additions & 67 deletions

File tree

.github/workflows/pr-image-size.yml

Lines changed: 108 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ jobs:
4141
permissions:
4242
contents: read
4343
pull-requests: write
44+
actions:write
4445
if: needs.get-check-list.outputs.files != ''
4546
strategy:
4647
matrix:
4748
dockerfile: ${{ fromJson(needs.get-check-list.outputs.files) }}
4849
fail-fast: false
50+
# outputs:
51+
# comments: ${{ steps.build-check.outputs.comment_message }}
4952
steps:
5053
- name: Checkout PR branch
5154
uses: actions/checkout@v4
@@ -61,7 +64,7 @@ jobs:
6164
dockerfile: ${{ matrix.dockerfile }}
6265
run: |
6366
set -x
64-
merged_commit=$(git log -1 --format='%H')
67+
# merged_commit=$(git log -1 --format='%H')
6568
6669
[ -z "$dockerfile" ] && continue
6770
dir=$(dirname "$dockerfile")
@@ -88,79 +91,117 @@ jobs:
8891
fi
8992
fi
9093
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"
94+
# echo "Building base image for $dockerfile"
95+
# git checkout ${{ github.event.pull_request.base.sha }}
96+
# echo "::group::Build image_base"
97+
# docker build -f "$file" -t "$image_base" --no-cache . || true
98+
# echo "::endgroup::"
99+
# size_base=$(docker image inspect "$image_base" | jq '.[0].Size / (1024 * 1024) | round')
100+
101+
# echo "Building PR image for $dockerfile"
102+
# git checkout $merged_commit
103+
# echo "PR: $merged_commit"
104+
# echo "::group::Build image_pr"
105+
# docker build -f "$file" -t "$image_pr" --no-cache . || true
106+
# echo "::endgroup::"
107+
# size_pr=$(docker image inspect "$image_pr" | jq '.[0].Size / (1024 * 1024) | round')
108+
109+
# diff=$((size_pr - size_base))
110+
# # echo "::warning::Image size change: $size_base -> $size_pr MB' (diff: $diff MB)"
111+
# echo "comment to ${{ github.event.pull_request.number }}"
112+
# if [ "$diff" -gt 50 ]; then
113+
# comment_message="⚠️ File '$dockerfile' resulted in a change in the image size from $size_base -> $size_pr MB (diff: $diff MB)"
114+
# else
115+
# comment_message="File '$dockerfile' resulted in a change in the image size from $size_base -> $size_pr MB (diff: $diff MB)"
116+
# fi
117+
118+
# echo "comment_message=$comment_message" >> $GITHUB_OUTPUT
119+
# echo "File $dockerfile resulted in a change in the image size from $size_base -> $size_pr MB" >> $GITHUB_STEP_SUMMARY
120+
# docker rmi "$image_base" "$image_pr"
121+
122+
##For debug
123+
comment_message="File size change"
124+
echo "comment_message=$comment_message" >> $GITHUB_STEP_SUMMARY
125+
image_name=$(echo $dir | tr '/' '-')
126+
cp "$GITHUB_STEP_SUMMARY" ${{github.workspace}}/build-$image_name.md
127+
echo "name=comment-$image_name">> $GITHUB_ENV
128+
echo "file_name=build-$image_name.md" >> $GITHUB_ENV
129+
echo "summary_path=${{github.workspace}}/build-$image_name.md" >> $GITHUB_ENV
130+
131+
- name: Download origin artifact log
132+
uses: actions/download-artifact@v4.3.4
133+
with:
134+
name: build-comments
135+
path: merged-files
136+
137+
- name: Merge logs
138+
run: |
139+
mkdir -p merged-files
140+
ls merged-files/
141+
cp ${{ env.summary_path }} merged-files/
142+
143+
144+
- name: Save Summary as Artifact
145+
uses: actions/upload-artifact@v4
146+
with:
147+
name: build-comments
148+
path: merged-files/
149+
overwrite: true
117150

118151
collect-comments:
119152
needs: build-and-check
153+
permissions:
154+
actions: read
120155
if: always()
121156
runs-on: ubuntu-latest
122157
outputs:
123158
all_comments: ${{ steps.collect.outputs.all_comments }}
124159
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
160+
- name: Download Summary
161+
uses: actions/download-artifact@v4
162+
with:
163+
name: build-comments
164+
path: downloaded-files
132165

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 }}
166+
- name: Read Summary
145167
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
168+
ls downloaded-files/
169+
cat downloaded-files/*.md
170+
171+
# - name: Remove merged-files
172+
# uses: actions/
173+
174+
# Post-comment-on-PR:
175+
# needs: collect-comments
176+
# runs-on: ubuntu-latest
177+
# permissions:
178+
# contents: read
179+
# pull-requests: write
180+
# if: always() && needs.collect-comments.outputs.all_comments != ''
181+
# steps:
182+
# - name: Post comment on PR
183+
# env:
184+
# all_comments: ${{ needs.collect-comments.outputs.all_comments }}
185+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
186+
# run: |
187+
# echo "comment ${all_comments}"
188+
# json_body=$(jq -n --arg msg "$all_comments" '{"body": $msg}')
189+
# comment_id=$(curl -s \
190+
# -H "Authorization: token ${GITHUB_TOKEN}" \
191+
# -H "Accept: application/vnd.github.v3+json" \
192+
# "https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.pull_request.number }}" \
193+
# | jq '.[] | select(.user.login=="github-actions[bot]") | .id' | tail -n1)
194+
195+
# if [ -n "$comment_id" ]; then
196+
# curl -X PATCH \
197+
# -H "Authorization: token ${GITHUB_TOKEN}" \
198+
# -H "Accept: application/vnd.github.v3+json" \
199+
# "https://api.github.com/repos/opea-project/GenAIExamples/issues/${{ github.event.pull_request.number }}/comments" \
200+
# -d "$json_body"
201+
# else
202+
# curl -X POST \
203+
# -H "Authorization: token ${GITHUB_TOKEN}" \
204+
# -H "Accept: application/vnd.github.v3+json" \
205+
# "https://api.github.com/repos/opea-project/GenAIExamples/issues/${{ github.event.pull_request.number }}/comments" \
206+
# -d "$json_body"
207+
# fi

0 commit comments

Comments
 (0)