Skip to content

Commit e27a249

Browse files
authored
Merge pull request #28 from artagon/fix/workflow-heredoc-yaml-syntax
fix(ci): properly indent heredoc content in workflow YAML
2 parents 65025bf + 86ef843 commit e27a249

3 files changed

Lines changed: 17 additions & 43 deletions

File tree

.github/workflows/build-push.yml

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
5656
- name: Install AppArmor tooling
5757
run: |
58+
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list /etc/apt/sources.list.d/azure-cli.list || true
5859
sudo apt-get update
5960
sudo apt-get install -y apparmor-utils
6061
@@ -140,60 +141,47 @@ jobs:
140141
set -e
141142
142143
- name: Attest vulnerability scan metadata
144+
env:
145+
TARGET: ${{ matrix.target }}
146+
TRIVY_EXIT: ${{ steps.trivy.outputs.trivy_exit }}
147+
GRYPE_EXIT: ${{ steps.grype.outputs.grype_exit }}
143148
run: |
144149
TRIVY_VERSION="$(trivy --version | head -n 1 | sed 's/^Version: //')"
145150
GRYPE_VERSION="$(grype version | head -n 1 | sed 's/^Version: //')"
146-
TARGET="${{ matrix.target }}"
147-
TRIVY_EXIT="${{ steps.trivy.outputs.trivy_exit }}"
148-
GRYPE_EXIT="${{ steps.grype.outputs.grype_exit }}"
149-
IMAGE_REF="${REGISTRY}:${{ matrix.target }}"
150-
python3 <<'PY'
151-
import json
152-
import os
151+
IMAGE_REF="${REGISTRY}:${TARGET}"
152+
export TRIVY_VERSION GRYPE_VERSION
153+
python3 - <<'EOF'
154+
import json, os
153155
from datetime import datetime, timezone
154-
155156
target = os.environ["TARGET"]
156157
trivy_path = f"attestations/trivy-{target}.json"
157158
grype_path = f"attestations/grype-{target}.json"
158-
159159
def count_trivy(data):
160160
counts = {}
161161
for result in data.get("Results", []):
162162
for vuln in result.get("Vulnerabilities") or []:
163163
sev = vuln.get("Severity", "UNKNOWN")
164164
counts[sev] = counts.get(sev, 0) + 1
165165
return counts
166-
167166
def count_grype(data):
168167
counts = {}
169168
for match in data.get("matches", []):
170169
sev = match.get("vulnerability", {}).get("severity", "Unknown")
171170
counts[sev] = counts.get(sev, 0) + 1
172171
return counts
173-
174172
with open(trivy_path, "r", encoding="utf-8") as fh:
175173
trivy_data = json.load(fh)
176174
with open(grype_path, "r", encoding="utf-8") as fh:
177175
grype_data = json.load(fh)
178-
179176
payload = {
180177
"target": target,
181178
"generated_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
182-
"trivy": {
183-
"version": os.environ["TRIVY_VERSION"],
184-
"exit_code": int(os.environ["TRIVY_EXIT"]),
185-
"counts": count_trivy(trivy_data),
186-
},
187-
"grype": {
188-
"version": os.environ["GRYPE_VERSION"],
189-
"exit_code": int(os.environ["GRYPE_EXIT"]),
190-
"counts": count_grype(grype_data),
191-
},
179+
"trivy": {"version": os.environ["TRIVY_VERSION"], "exit_code": int(os.environ["TRIVY_EXIT"]), "counts": count_trivy(trivy_data)},
180+
"grype": {"version": os.environ["GRYPE_VERSION"], "exit_code": int(os.environ["GRYPE_EXIT"]), "counts": count_grype(grype_data)},
192181
}
193-
194182
with open(f"attestations/scan-{target}.json", "w", encoding="utf-8") as fh:
195183
json.dump(payload, fh, indent=2)
196-
PY
184+
EOF
197185
cosign attest --yes \
198186
--predicate attestations/scan-${{ matrix.target }}.json \
199187
--type https://artagon.dev/attestations/vulnerability-scan/v1 \

.github/workflows/ci-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363

6464
- name: Install AppArmor tooling
6565
run: |
66+
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list /etc/apt/sources.list.d/azure-cli.list || true
6667
sudo apt-get update
6768
sudo apt-get install -y apparmor-utils
6869

.github/workflows/release.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,50 +108,35 @@ jobs:
108108
export GRYPE_VERSION
109109
export TRIVY_EXIT="$(cat scan/trivy-exit-${tag}.txt)"
110110
export GRYPE_EXIT="$(cat scan/grype-exit-${tag}.txt)"
111-
python3 <<'PY'
112-
import json
113-
import os
111+
python3 - <<'PY'
112+
import json, os
114113
from datetime import datetime, timezone
115-
116114
target = os.environ["TARGET"]
117115
trivy_path = f"scan/trivy-{target}.json"
118116
grype_path = f"scan/grype-{target}.json"
119-
120117
def count_trivy(data):
121118
counts = {}
122119
for result in data.get("Results", []):
123120
for vuln in result.get("Vulnerabilities") or []:
124121
sev = vuln.get("Severity", "UNKNOWN")
125122
counts[sev] = counts.get(sev, 0) + 1
126123
return counts
127-
128124
def count_grype(data):
129125
counts = {}
130126
for match in data.get("matches", []):
131127
sev = match.get("vulnerability", {}).get("severity", "Unknown")
132128
counts[sev] = counts.get(sev, 0) + 1
133129
return counts
134-
135130
with open(trivy_path, "r", encoding="utf-8") as fh:
136131
trivy_data = json.load(fh)
137132
with open(grype_path, "r", encoding="utf-8") as fh:
138133
grype_data = json.load(fh)
139-
140134
payload = {
141135
"target": target,
142136
"generated_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
143-
"trivy": {
144-
"version": os.environ["TRIVY_VERSION"],
145-
"exit_code": int(os.environ["TRIVY_EXIT"]),
146-
"counts": count_trivy(trivy_data),
147-
},
148-
"grype": {
149-
"version": os.environ["GRYPE_VERSION"],
150-
"exit_code": int(os.environ["GRYPE_EXIT"]),
151-
"counts": count_grype(grype_data),
152-
},
137+
"trivy": {"version": os.environ["TRIVY_VERSION"], "exit_code": int(os.environ["TRIVY_EXIT"]), "counts": count_trivy(trivy_data)},
138+
"grype": {"version": os.environ["GRYPE_VERSION"], "exit_code": int(os.environ["GRYPE_EXIT"]), "counts": count_grype(grype_data)},
153139
}
154-
155140
with open(f"attestations/scan-{target}.json", "w", encoding="utf-8") as fh:
156141
json.dump(payload, fh, indent=2)
157142
PY

0 commit comments

Comments
 (0)