Skip to content

Commit f30aa7e

Browse files
committed
actions: add action to validate BRSAs
Signed-off-by: Piyush Jena <[email protected]>
1 parent cd6b045 commit f30aa7e

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: RPM Advisory Build & Verify
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'advisories/**/BRSA-*.toml'
7+
8+
jobs:
9+
find-changes:
10+
name: Find Changed Advisories
11+
runs-on: ubuntu-latest
12+
outputs:
13+
changed_files: ${{ steps.changed-files.outputs.all_changed_files || '[]' }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- name: Get changed files
19+
id: changed-files
20+
uses: tj-actions/changed-files@v47
21+
with:
22+
json: true
23+
escape_json: false
24+
files_ignore_deleted_files: true
25+
files: |
26+
advisories/staging/**.toml
27+
- name: List all changed advisories files
28+
if: steps.changed-files.outputs.any_changed == 'true'
29+
env:
30+
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
31+
run: |
32+
for file in ${ALL_CHANGED_FILES}; do
33+
echo "$file was changed"
34+
done
35+
build-and-verify:
36+
name: Build & Verify
37+
needs: find-changes
38+
runs-on: ubuntu-latest
39+
container:
40+
image: public.ecr.aws/bottlerocket/bottlerocket-sdk:v0.65.1
41+
options: --user 0
42+
43+
# Only run this job if the 'find-changes' job actually found files
44+
if: needs.find-changes.outputs.changed_files != '[]'
45+
strategy:
46+
fail-fast: false # Don't cancel all jobs if one file fails
47+
matrix:
48+
arch: [aarch64]
49+
advisory_file: ${{ fromJson(needs.find-changes.outputs.changed_files) }}
50+
steps:
51+
# This builds the current packages and kits.
52+
- uses: actions/checkout@v4
53+
with:
54+
fetch-depth: 0
55+
- name: Install yq
56+
run: |
57+
echo "Installing yq..."
58+
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq
59+
sudo chmod +x /usr/bin/yq
60+
yq --version
61+
- name: Build, Find, and Verify RPMs
62+
run: |
63+
#!/usr/bin/env bash
64+
65+
echo "Processing advisory: ${{ matrix.advisory_file }}"
66+
cp /usr/lib/rpm/platform/${{ matrix.arch }}-bottlerocket/macros ~/.rpmmacros
67+
68+
if [[ ! -f "${{ matrix.advisory_file }}" ]]; then
69+
echo "::warning::File ${{ matrix.advisory_file }} does not exist. Skipping."
70+
exit 0
71+
fi
72+
73+
while IFS=$'\t' read -r package_name package_epoch package_version; do
74+
rpmspec_file="packages/${package_name}/${package_name}.spec"
75+
package_metadata=$(rpmspec --parse --query --qf "%{Name}:%{Epoch}:%{Version}\n" ${rpmspec_file})
76+
77+
while IFS=: read -r subpackage_name subpackage_epoch subpackage_version; do
78+
if [ ${subpackage_epoch} == "(none)" ]; then
79+
subpackage_epoch="0"
80+
fi
81+
82+
if [[ "${subpackage_name}" = *"${package_name}" ]]; then
83+
echo "Package metadata in ${{ matrix.advisory_file }}: ${package_name}, epoch: ${package_epoch}, version: ${package_version}"
84+
echo "Package metadata in the rpm: ${subpackage_name}, epoch: ${subpackage_epoch}, version: ${subpackage_version}"
85+
86+
if [ "${subpackage_epoch}" = "${package_epoch}" ] && \
87+
[ "${subpackage_version}" = "${package_version}" ]; then
88+
echo "Package metadata in the Advisory is validated."
89+
exit 0
90+
fi
91+
fi
92+
done < <(echo "$package_metadata")
93+
done < <(yq -o tsv '.advisory.products[] | [ .["package-name"], .["patched-epoch"], .["patched-version"] ]' ${{ matrix.advisory_file }})
94+
95+
exit 1

0 commit comments

Comments
 (0)