Skip to content

Commit a4604a6

Browse files
authored
feat: add sboms and vulnscans (#92)
1 parent df6431a commit a4604a6

11 files changed

Lines changed: 111 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ jobs:
6969
run: task -v init
7070
- name: Validate the repo
7171
run: task -v validate
72-
- name: Set up QEMU for cross-platform emulation
73-
uses: docker/setup-qemu-action@v2
7472
- name: Run the tests
7573
run: task -v test
7674
bump-version:
@@ -80,8 +78,6 @@ jobs:
8078
permissions:
8179
contents: write
8280
runs-on: ubuntu-22.04
83-
outputs:
84-
tag: ${{ steps.bump-version.outputs.tag }}
8581
steps:
8682
- name: Checkout the repository
8783
uses: actions/checkout@v3
@@ -120,5 +116,6 @@ jobs:
120116
with:
121117
name: ${{ steps.bump-version.outputs.tag }}
122118
tag_name: ${{ steps.bump-version.outputs.tag }}
119+
generate_release_notes: true
123120
draft: false
124121
prerelease: false

.github/workflows/security.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name: "Security"
33

44
on:
5-
- workflow_dispatch
5+
workflow_dispatch:
66

77
env:
88
python_version: "3.11"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.task/*
2+
sbom.*.json
3+
vulns.*.json
24

35
# Created by https://www.toptal.com/developers/gitignore/api/vim,emacs,visualstudiocode,python,macos,windows
46
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,emacs,visualstudiocode,python,macos,windows

Taskfile.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ tasks:
9797

9898
release:
9999
desc: Cut a project release
100-
deps: [test]
101100
cmds:
102101
- task: py:release
102+
103+
sbom:
104+
desc: Generate project SBOMs
105+
cmds:
106+
- task: bash:sbom
107+
108+
vulnscan:
109+
desc: Vuln scan the SBOM
110+
cmds:
111+
- task: bash:vulnscan

tests/test_cookiecutter.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import itertools
88
import json
99
import os
10+
import platform as plat
1011
import re
1112
import subprocess
1213
import sys
@@ -18,6 +19,8 @@
1819
import yaml
1920
from jinja2 import Template
2021

22+
LOCAL_PLATFORM = f"{plat.system().lower()}/{plat.machine()}"
23+
2124

2225
def get_config() -> dict:
2326
"""Generate all the config keys"""
@@ -168,6 +171,7 @@ def test_default_project(cookies):
168171
# Build and test all supported architectures
169172
env = os.environ.copy()
170173
env["PLATFORM"] = "all"
174+
# We don't test sbom or vulnscan here because multiplatform builds aren't loaded into the local docker daemon
171175
subprocess.run(
172176
["task", "init", "lint", "validate", "build", "test"],
173177
capture_output=True,
@@ -187,6 +191,16 @@ def test_default_project(cookies):
187191
env=env,
188192
)
189193

194+
# This is because only the build for the local platform is loaded into the docker daemon
195+
if platform == LOCAL_PLATFORM:
196+
subprocess.run(
197+
["task", "sbom", "vulnscan"],
198+
capture_output=True,
199+
check=True,
200+
cwd=project,
201+
env=env,
202+
)
203+
190204
# Do two releases to ensure they work
191205
for _ in range(2):
192206
subprocess.run(

{{cookiecutter.project_name|replace(" ", "")}}/.github/workflows/commit.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ jobs:
5151
${{ "{{ runner.os }}" }}-python-${{ "{{ env.python_version }}" }}-pipenv-
5252
${{ "{{ runner.os }}" }}-python-
5353
- name: Install the dependencies
54-
run: python -m pip install --upgrade pipenv
54+
run: |
55+
python -m pip install --upgrade pipenv
56+
mkdir "${RUNNER_TEMP}/bin"
57+
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
58+
chmod +x "${RUNNER_TEMP}/bin/syft"
59+
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b "${RUNNER_TEMP}/bin"
60+
chmod +x "${RUNNER_TEMP}/bin/grype"
61+
echo "${RUNNER_TEMP}/bin" >> "${GITHUB_PATH}"
5562
- name: Install Task
5663
uses: arduino/setup-task@v1
5764
- name: Initialize the repo
@@ -68,6 +75,26 @@ jobs:
6875
run: task -v test
6976
env:
7077
PLATFORM: ${{ "{{ matrix.platform }}" }}
78+
- name: Generate the SBOMs
79+
run: task -v sbom
80+
env:
81+
PLATFORM: ${{ "{{ matrix.platform }}" }}
82+
- name: Upload the SBOMs
83+
uses: actions/upload-artifact@v3
84+
with:
85+
name: SBOM
86+
path: sbom.*.json
87+
if-no-files-found: error
88+
- name: Generate vuln scan results
89+
run: task -v vulnscan
90+
env:
91+
PLATFORM: ${{ "{{ matrix.platform }}" }}
92+
- name: Upload the vuln scan results
93+
uses: actions/upload-artifact@v3
94+
with:
95+
name: Vulns
96+
path: vulns.*.json
97+
if-no-files-found: error
7198
{%- if cookiecutter.versioning == "CalVer" %}
7299
bump-version:
73100
name: Bump version
@@ -109,13 +136,21 @@ jobs:
109136
BRANCH="$(git branch --show-current)"
110137
git push --atomic origin "${BRANCH}" "${TAG}"
111138
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
139+
- name: Download the SBOMs and Vuln scan results
140+
uses: actions/download-artifact@v3
141+
with:
142+
path: ${{ "{{ runner.temp }}" }}
112143
- name: Publish the release to GitHub
113144
uses: softprops/action-gh-release@v1
114145
env:
115146
GITHUB_TOKEN: ${{ "{{ secrets.GITHUB_TOKEN }}" }}
116147
with:
117148
name: ${{ "{{ steps.bump-version.outputs.tag }}" }}
118149
tag_name: ${{ "{{ steps.bump-version.outputs.tag }}" }}
150+
generate_release_notes: true
151+
files: |
152+
${{ "{{ runner.temp }}" }}/Vulns/vulns.*.json
153+
${{ "{{ runner.temp }}" }}/SBOM/sbom.*.json
119154
draft: false
120155
prerelease: false
121156
{%- endif -%}

{{cookiecutter.project_name|replace(" ", "")}}/.github/workflows/release.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ jobs:
1818
distribute:
1919
name: Distribute
2020
runs-on: ubuntu-22.04
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
platform:
25+
- linux/amd64
26+
- linux/arm64
2127
permissions:
2228
contents: write
2329
steps:
@@ -42,14 +48,41 @@ jobs:
4248
uses: arduino/setup-task@v1
4349
- name: Initialize the repo
4450
run: task -v init
51+
- name: Set up QEMU for cross-platform emulation
52+
uses: docker/setup-qemu-action@v2
4553
- name: Build the image(s)
4654
run: task -v build
55+
- name: Generate the SBOMs
56+
run: task -v sbom
57+
env:
58+
PLATFORM: ${{ "{{ matrix.platform }}" }}
59+
- name: Upload the SBOMs
60+
uses: actions/upload-artifact@v3
61+
with:
62+
name: SBOM
63+
path: sbom.*.json
64+
if-no-files-found: error
65+
- name: Generate vuln scan results
66+
run: task -v vulnscan
67+
env:
68+
PLATFORM: ${{ "{{ matrix.platform }}" }}
69+
- name: Upload the vuln scan results
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: Vulns
73+
path: vulns.*.json
74+
if-no-files-found: error
4775
- name: Publish the release to GitHub
4876
uses: softprops/action-gh-release@v1
4977
env:
5078
GITHUB_TOKEN: ${{ "{{ secrets.GITHUB_TOKEN }}" }}
5179
with:
5280
name: ${{ "{{ env.TAG }}" }}
81+
tag_name: ${{ "{{ env.TAG }}" }}
82+
generate_release_notes: true
83+
files: |
84+
vulns.*.json
85+
sbom.*.json
5386
draft: false
5487
prerelease: false
5588
{%- if cookiecutter.dockerhub == 'yes' %}
@@ -65,8 +98,6 @@ jobs:
6598
password: ${{ "{{ secrets.DOCKERHUB_TOKEN }}" }}
6699
repository: seiso/{{ cookiecutter.project_slug }}
67100
short-description: {{ cookiecutter.project_short_description }}
68-
- name: Set up QEMU for cross-platform emulation
69-
uses: docker/setup-qemu-action@v2
70101
- name: Publish the release to Docker Hub
71102
run: task -v publish
72103
env:

{{cookiecutter.project_name|replace(" ", "")}}/.github/workflows/security.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ on:
1111
- main
1212
schedule:
1313
- cron: '{{ range(0, 59) | random }} {{ range(2, 4) | random }} * * *'
14-
{%- elif cookiecutter.public == 'no' %}
15-
- workflow_dispatch
1614
{%- endif %}
15+
workflow_dispatch:
1716

1817
env:
1918
python_version: "{{ cookiecutter.python_version }}"

{{cookiecutter.project_name|replace(" ", "")}}/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.task/*
2+
sbom.*.json
3+
vulns.*.json
24

35
# Created by https://www.toptal.com/developers/gitignore/api/vim,emacs,visualstudiocode,python,macos,windows
46
# Edit at https://www.toptal.com/developers/gitignore?templates=vim,emacs,visualstudiocode,python,macos,windows

0 commit comments

Comments
 (0)