-
Notifications
You must be signed in to change notification settings - Fork 0
170 lines (165 loc) · 5.99 KB
/
build.yaml
File metadata and controls
170 lines (165 loc) · 5.99 KB
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
160
161
162
163
164
165
166
167
168
169
170
name: Build
on:
pull_request:
types:
- opened
- synchronize
push:
branches:
- main
tags:
- "*"
env:
QUAY_STACKROX_IO_RW_USERNAME: ${{ secrets.QUAY_STACKROX_IO_RW_USERNAME }}
QUAY_STACKROX_IO_RW_PASSWORD: ${{ secrets.QUAY_STACKROX_IO_RW_PASSWORD }}
QUAY_RHACS_ENG_RW_USERNAME: ${{ secrets.QUAY_RHACS_ENG_RW_USERNAME }}
QUAY_RHACS_ENG_RW_PASSWORD: ${{ secrets.QUAY_RHACS_ENG_RW_PASSWORD }}
jobs:
build-and-push-builder-images:
runs-on: ubuntu-latest
strategy:
matrix:
image-flavor:
- scanner-build
- stackrox-build
- stackrox-ui-test
- jenkins-plugin
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/build-and-push-image
id: build-and-push-image
with:
image-flavor: "${{ matrix.image-flavor }}"
- name: Push latest tag
if: startsWith(github.ref, 'refs/tags/')
run: |
if ! git merge-base --is-ancestor "${{ github.sha }}" origin/main; then
echo "Skipping latest push: tagged commit is not on main"
exit 0
fi
CURRENT="${{ github.ref_name }}"
LATEST="$(git tag --merged origin/main --sort=-version:refname | head -1)"
if [[ "${CURRENT}" != "${LATEST}" ]]; then
echo "Skipping latest push: ${CURRENT} is not the highest version tag on main (${LATEST} is)"
exit 0
fi
IMAGE="${{ steps.build-and-push-image.outputs.image-tag }}"
LATEST_IMAGE="quay.io/stackrox-io/apollo-ci:${{ matrix.image-flavor }}-latest"
docker tag "${IMAGE}" "${LATEST_IMAGE}"
docker push "${LATEST_IMAGE}"
- name: Save image info
run: |
mkdir -p image-info
echo "${{ steps.build-and-push-image.outputs.image-tag }}" > "image-info/${{ matrix.image-flavor }}.txt"
- name: Upload image info
uses: actions/upload-artifact@v4
with:
name: image-info-${{ matrix.image-flavor }}
path: image-info/${{ matrix.image-flavor }}.txt
retention-days: 1
build-and-push-test-images:
needs: build-and-push-builder-images
runs-on: ubuntu-latest
strategy:
matrix:
image-flavor:
- stackrox-test
- scanner-test
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/actions/build-and-push-image
id: build-and-push-image
with:
image-flavor: "${{ matrix.image-flavor }}"
- name: Push latest tag
if: startsWith(github.ref, 'refs/tags/')
run: |
if ! git merge-base --is-ancestor "${{ github.sha }}" origin/main; then
echo "Skipping latest push: tagged commit is not on main"
exit 0
fi
CURRENT="${{ github.ref_name }}"
LATEST="$(git tag --merged origin/main --sort=-version:refname | head -1)"
if [[ "${CURRENT}" != "${LATEST}" ]]; then
echo "Skipping latest push: ${CURRENT} is not the highest version tag on main (${LATEST} is)"
exit 0
fi
IMAGE="${{ steps.build-and-push-image.outputs.image-tag }}"
LATEST_IMAGE="quay.io/stackrox-io/apollo-ci:${{ matrix.image-flavor }}-latest"
docker tag "${IMAGE}" "${LATEST_IMAGE}"
docker push "${LATEST_IMAGE}"
- name: Save image info
run: |
mkdir -p image-info
echo "${{ steps.build-and-push-image.outputs.image-tag }}" > "image-info/${{ matrix.image-flavor }}.txt"
- name: Upload image info
uses: actions/upload-artifact@v4
with:
name: image-info-${{ matrix.image-flavor }}
path: image-info/${{ matrix.image-flavor }}.txt
retention-days: 1
test-cci-export:
runs-on: ubuntu-latest
needs:
- build-and-push-builder-images
- build-and-push-test-images
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Test cci-export in a context similar to how it is used in CI
run: |
docker login -u "$QUAY_STACKROX_IO_RW_USERNAME" --password-stdin <<<"$QUAY_STACKROX_IO_RW_PASSWORD" quay.io
make test-cci-export
comment-build-images:
runs-on: ubuntu-latest
needs:
- build-and-push-builder-images
- build-and-push-test-images
steps:
- name: Download all image info artifacts
uses: actions/download-artifact@v4
with:
pattern: image-info-*
merge-multiple: true
path: image-info
- name: Build comment message
id: build-message
run: |
echo "message<<EOF" >> $GITHUB_OUTPUT
echo "## Build Images" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "| Image Flavor | Image Tag |" >> $GITHUB_OUTPUT
echo "|--------------|-----------|" >> $GITHUB_OUTPUT
for file in image-info/*.txt; do
if [ -f "$file" ]; then
flavor=$(basename "$file" .txt)
image=$(cat "$file")
echo "| ${flavor} | \`${image}\` |" >> $GITHUB_OUTPUT
fi
done
echo "EOF" >> $GITHUB_OUTPUT
- name: Comment PR with build images
if: ${{ github.event_name == 'pull_request' }}
uses: thollander/actions-comment-pull-request@v3
with:
message: ${{ steps.build-message.outputs.message }}
comment-tag: build-images
- name: Print the comment message to step summary
run: |
# Need to cat here, because echo would interpret the backticks in the message as commands.
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
${{ steps.build-message.outputs.message }}
EOF