-
Notifications
You must be signed in to change notification settings - Fork 17
159 lines (142 loc) · 6.96 KB
/
pr_image_id.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
# Use the latest published version of the cirrus-ci_retrospective container
# to determine the execution context of _this_ workflow run. If it is a
# pull request, post the to-be VM/Container image ID string as a comment.
on:
check_suite: # ALWAYS triggered from the default branch
# Ref: https://help.github.com/en/actions/reference/events-that-trigger-workflows#check-suite-event-check_suite
types:
- completed
jobs:
comment_image_id:
# Do not execute for other github applications, only works with cirrus-ci
if: github.event.check_suite.app.name == 'Cirrus CI'
runs-on: ubuntu-latest
env:
# This is the last component of the gist URL
# i.e. https://gist.github.com/<user>/<id>
built_images_gist_id: f505b6fb78db279855862e035629f8aa
steps:
- name: Execute latest upstream cirrus-ci_retrospective
uses: docker://quay.io/libpod/cirrus-ci_retrospective:latest
env:
GITHUB_TOKEN: ${{ github.token }}
# Writes $GITHUB_WORKSPACE/cirrus-ci_retrospective.json
- name: Debug cirrus-ci_retrospective JSON
run: jq --indent 4 --color-output . $GITHUB_WORKSPACE/cirrus-ci_retrospective.json
- name: Load JSON into github workflow output variables
id: retro
run: |
ccirjson=$GITHUB_WORKSPACE/cirrus-ci_retrospective.json
prn=$(jq --raw-output \
'.[] | select(.name == "'success'") | .build.pullRequest' \
"$ccirjson")
bid=$(jq --raw-output \
'.[] | select(.name == "'success'") | .build.id' \
"$ccirjson")
status=$(jq --raw-output \
'.[] | select(.name == "'success'") | .status' \
"$ccirjson")
if [[ -n "$prn" ]] && \
[[ "$prn" != "null" ]] && \
[[ $prn -gt 0 ]] && \
[[ "$status" == "COMPLETED" ]]
then
printf "prn=%s\n" "$prn" >> $GITHUB_OUTPUT
printf "bid=%s\n" "$bid" >> $GITHUB_OUTPUT
printf "is_pr=%s\n" "true" >> $GITHUB_OUTPUT
else
printf "prn=%s\n" "0" >> $GITHUB_OUTPUT
printf "bid=%s\n" "0" >> $GITHUB_OUTPUT
printf "is_pr=%s\n" "false" >> $GITHUB_OUTPUT
fi
- if: steps.retro.outputs.is_pr == 'true'
uses: actions/checkout@v4
with:
persist-credentials: false
- if: steps.retro.outputs.is_pr == 'true'
name: Retrieve and process any manifest artifacts
# Use the CCIA image produce by the `Build Tooling images`
# task of the PR we're looking at. This allows testing
# of changes to the CCIA container before merging into `main`
# (where this workflow runs from). If that should fail,
# fall back to using the latest built CCIA image.
run: |
PODMAN="podman run --rm -v $GITHUB_WORKSPACE:/data -w /data"
$PODMAN quay.io/libpod/ccia:latest --verbose "${{ steps.retro.outputs.bid }}" ".*/manifest.json"
- if: steps.retro.outputs.is_pr == 'true'
name: Count the number of manifest.json files downloaded
id: manifests
run: |
dled=$(find $GITHUB_WORKSPACE -type f -name 'manifest.json' -not -path '*fake_manifests/*/manifest.json' | wc -l)
if [[ "$dled" =~ ^[0-9]+$ ]]; then
printf "count=%s\n" "$dled" >> $GITHUB_OUTPUT
else
printf "count=0\n" >> $GITHUB_OUTPUT
fi
- if: steps.manifests.outputs.count > 0
name: Extract build details from manifest files
env:
FLTR: >-
{"stage": .builds[].custom_data.STAGE,
"name": .builds[].name,
"sfx": .builds[].custom_data.IMG_SFX,
"task": .builds[].custom_data.TASK}
run: |
cd $GITHUB_WORKSPACE
find ./ -type f -name 'manifest.json' -print0 | \
xargs --null jq -e -c "$FLTR" | \
jq -e -s '.' > ./built_images.json
- if: steps.manifests.outputs.count > 0
name: Debug built_images.json contents
run: |
jq --color-output . $GITHUB_WORKSPACE/built_images.json
- if: steps.manifests.outputs.count > 0
id: body
name: Format PR-comment body
# Consumes $GITHUB_WORKSPACE/built_images.json
run: .github/actions/bin/create_image_table.py
- if: steps.manifests.outputs.count > 0
name: Debug images.md contents
# Produced by create_image_table.py
run: cat $GITHUB_WORKSPACE/images.md
- if: steps.manifests.outputs.count > 0
name: Debug images.json contents
# Produced by create_image_table.py
run: jq --color-output . $GITHUB_WORKSPACE/images.json
# jungwinter/comment cannot consume a file as comment input
- if: steps.manifests.outputs.count > 0
name: Debug PR comment markdown
# Use a here-document to display to avoid any
# problems with passing special-characters into echo
# The quoted-EOD prevents any shell interpretation.
run: |
cat <<"EOD"
${{ env.IMAGE_TABLE }}
EOD
- if: steps.manifests.outputs.count > 0
name: Post PR comment with image name/id table
uses: jungwinter/[email protected]
with:
issue_number: '${{ steps.retro.outputs.prn }}'
type: 'create'
token: '${{ secrets.GITHUB_TOKEN }}'
body: |
${{ env.IMAGE_TABLE }}
# Ref: https://github.com/marketplace/actions/deploy-to-gist
- if: steps.manifests.outputs.count > 0
name: Publish image name/id MD table to gist
uses: exuanbo/[email protected]
with:
token: ${{ secrets.IMG_GIST_TOKEN }}
gist_id: ${{ env.built_images_gist_id }}
file_path: images.md
file_type: text
- if: steps.manifests.outputs.count > 0
name: Publish image name/id JSON table to gist
uses: exuanbo/[email protected]
with:
token: ${{ secrets.IMG_GIST_TOKEN }}
gist_id: ${{ env.built_images_gist_id }}
file_path: images.json
file_type: text