Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 40 additions & 23 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ on:
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:
# Gourmand and Gatehouse dispatch this when they release, because this image
# bakes them. That is what keeps a consuming repo's one pin honest without
# anyone remembering to bump something.
repository_dispatch:
types: [parent-image-updated]

concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}
Expand Down Expand Up @@ -58,8 +53,7 @@ jobs:
set -eu
podman run --rm -v "$PWD:/mnt:ro" -w /mnt \
docker.io/koalaman/shellcheck:v0.11.0 bin/sdlc tests/contract.sh \
tests/test_host_contract.sh tests/test_tiers.sh
tests/test_tiers.sh
tests/test_host_contract.sh
tests/test_host_contract.sh

- name: Build
Expand All @@ -84,24 +78,16 @@ jobs:
- name: Contract test
run: tests/contract.sh "localhost/python-sdlc:$GITHUB_SHA"

# The Container Image profile recommends a CVE scan, and this is the one
# place Trivy belongs: it reads the OS packages in the image layers
# (glibc, openssl, zlib), which pip-audit never sees because pip-audit
# reads a Python lockfile. Scott's call is that Trivy is CI-only, and a
# container-image repo's CI is exactly where the image exists.
#
# `continue-on-error` per the profile: a base-image CVE with no fix
# available must not block a tooling release, but it must be visible.
- name: Trivy
continue-on-error: true
# The planner and the CodeQL path matching, run in the image because
# they need its interpreter and PyYAML.
- name: Unit tests
run: |
set -eu
podman save --format docker-archive \
"localhost/python-sdlc:$GITHUB_SHA" -o /tmp/image.tar
podman run --rm -v /tmp:/tmp:z \
docker.io/aquasec/trivy:0.58.1 image \
--input /tmp/image.tar --scanners vuln \
--severity CRITICAL,HIGH --ignore-unfixed --exit-code 1
for t in tests/test_plan.py tests/test_codeql_globs.py; do
podman run --rm -v "$PWD:/src:ro,z" -w /src \
--entrypoint /opt/constitution-venv/bin/python3 \
"localhost/python-sdlc:$GITHUB_SHA" "$t"
done

- name: Log in to Quay
if: github.event_name != 'pull_request'
Expand Down Expand Up @@ -201,3 +187,34 @@ jobs:
echo "promoted $version"
;;
esac

# Step 3 of a release (update-tools.yml describes all three): once a version
# tag's image is promoted -- so the tag a consumer will pull exists -- open a
# bump PR in every repo that pins python-sdlc. Each repo's own CI decides
# whether its bump lands.
bump-consumers:
name: Bump every repo that pins python-sdlc
needs: promote
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false

- name: Mint CI token
id: ci-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.CRUNCHTOOLS_CI_APP_ID || secrets.CRUNCHTOOLS_CI_APP_ID }}
private-key: ${{ secrets.CRUNCHTOOLS_CI_APP_KEY }}
owner: crunchtools

- name: Open the bump pull requests
env:
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
run: |
gh auth setup-git
python3 scripts/bump_consumers.py "$GITHUB_REF_NAME"
68 changes: 68 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# A merge that changes the version IS the release. When main's pyproject.toml
# names a version with a CHANGELOG heading and no tag yet, this tags it, and the
# tag push runs container.yml, which promotes the image to that version and then
# opens a bump PR in every repo that pins python-sdlc.
#
# Without this, a tool update that merged itself would sit untagged until a
# person noticed, and no repo would receive it.

name: Release

on:
push:
branches: [main]

concurrency:
group: release
cancel-in-progress: false

permissions: {}

jobs:
release:
name: Tag a new version
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7

- name: Is there an untagged version?
id: version
env:
GH_TOKEN: ${{ github.token }}
run: |
set -eu
v=$(sed -n 's/^version = "\(.*\)"$/\1/p' pyproject.toml | head -1)
[ -n "$v" ] || { echo "pyproject.toml names no version" >&2; exit 1; }
if gh release view "v$v" >/dev/null 2>&1; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOW (General Review): This suppresses every error from gh release view, making an existing release indistinguishable from an authentication, API, or network failure. The workflow then proceeds as though the version were untagged, obscuring the original failure and potentially producing a less informative error later.

Suggestion: Capture the command result and treat only a confirmed not-found response as an untagged version; report or fail on other errors.

Evidence:

if gh release view "v$v" >/dev/null 2>&1; then

echo "v$v is already released"
echo "tag=" >> "$GITHUB_OUTPUT"
elif grep -q "^## \[$v\]" CHANGELOG.md; then
echo "tag=v$v" >> "$GITHUB_OUTPUT"
else
echo "v$v has no CHANGELOG heading; not releasing" >&2
exit 1
fi

# The App's token, because a tag created with GITHUB_TOKEN does not start
# container.yml, and the release would never be promoted.
- name: Mint CI token
if: steps.version.outputs.tag != ''
id: ci-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.CRUNCHTOOLS_CI_APP_ID || secrets.CRUNCHTOOLS_CI_APP_ID }}
private-key: ${{ secrets.CRUNCHTOOLS_CI_APP_KEY }}
owner: crunchtools

- name: Release
if: steps.version.outputs.tag != ''
env:
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
TAG: ${{ steps.version.outputs.tag }}
run: |
set -eu
v=${TAG#v}
notes=$(awk -v h="## [$v]" 'index($0, h) == 1 {f=1; next} f && /^## \[/ {exit} f' CHANGELOG.md)
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --notes "$notes"
71 changes: 71 additions & 0 deletions .github/workflows/update-tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# A Gourmand or Gatehouse release reaches every Python repo in three steps, and
# this is the first: move the pin and bump this image's patch version, as a pull
# request that merges itself when CI is green.
#
# 1. this workflow new tool release -> PR moving the pin here
# 2. release.yml that PR merges -> python-sdlc vX.Y.Z is released
# 3. container.yml the release is promoted -> a bump PR in every repo
# that pins python-sdlc (scripts/bump_consumers.py)
#
# Gourmand and Gatehouse send `parent-image-updated` when they release. The
# weekly run catches a dispatch that was lost.

name: Update baked tools

on:
repository_dispatch:
types: [parent-image-updated]
schedule:
- cron: "0 7 * * 1"
workflow_dispatch:

concurrency:
group: update-tools
cancel-in-progress: false

permissions: {}

jobs:
update:
name: Move the Gourmand and Gatehouse pins
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# The crunchtools-ci App's token, not GITHUB_TOKEN: a pull request opened
# with GITHUB_TOKEN does not trigger CI, so it could never turn green and
# merge itself.
- name: Mint CI token
id: ci-token
uses: actions/create-github-app-token@v3
with:
app-id: ${{ vars.CRUNCHTOOLS_CI_APP_ID || secrets.CRUNCHTOOLS_CI_APP_ID }}
private-key: ${{ secrets.CRUNCHTOOLS_CI_APP_KEY }}
owner: crunchtools

- uses: actions/checkout@v7
with:
token: ${{ steps.ci-token.outputs.token }}

- name: Compare the pins to the latest releases
id: update
env:
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
run: python3 scripts/update_tools.py

- name: Open the pull request and let it merge itself
if: steps.update.outputs.changed == 'true'
env:
GH_TOKEN: ${{ steps.ci-token.outputs.token }}
VERSION: ${{ steps.update.outputs.version }}
SUMMARY: ${{ steps.update.outputs.summary }}
run: |
set -eu
branch="chore/tools-$VERSION"
git switch -c "$branch"
git -c user.name=crunchtools-ci -c user.email=ci@crunchtools.com \
commit -qam "chore: python-sdlc $VERSION ($SUMMARY)"
git push -q -u origin "$branch"
url=$(gh pr create --head "$branch" --title "chore: python-sdlc $VERSION" \
--body "Moves the baked tool pins: $SUMMARY. Merging releases python-sdlc $VERSION, which opens a bump PR in every repo that pins it.")
gh pr merge "$url" --auto --merge
47 changes: 10 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
# This repo's own gates.
#
# Deliberately the CLASSIC fleet shape, not python-sdlc's own hooks, for two
# reasons:
# The classic fleet shape, not python-sdlc's own two hooks: this repo builds the
# image, so gating it on that image is circular on a first clone. Constitution
# XII (v1.30.0) exempts it by name (`sdlc_exempt`), with gourmand and gatehouse.
#
# 1. Constitution XII currently REQUIRES a hook with `id: gourmand` running
# `quay.io/crunchtools/gourmand` and one with `id: gatehouse` running
# `quay.io/crunchtools/gatehouse`, and `validate-constitution.py` greps
# this file for those strings. Until the XII amendment lands, a repo using
# python-sdlc's hooks fails `Constitution / Validate constitution`.
# 2. Bootstrapping. This repo builds the image, so gating it on the image it
# has not built yet is circular on a first clone.
#
# This file switches to the one-block form once the amendment is tagged. That
# is the point at which python-sdlc gates itself.
# No container build at pre-push: that is minutes, and Scott's rule is that a
# push never waits on one. CI builds the image and runs the contract test
# against the pushed digest.

default_install_hook_types: [pre-commit, pre-merge-commit, pre-push]

Expand All @@ -27,12 +21,12 @@ repos:
rev: v0.17.1
hooks:
- id: ruff-check
args: [--fix, sdlc, validate, tests]
args: [--fix, sdlc, validate, tests, scripts]
pass_filenames: false
always_run: true
stages: [pre-commit, pre-merge-commit]
- id: ruff-format
args: [sdlc, validate, tests]
args: [sdlc, validate, tests, scripts]
pass_filenames: false
always_run: true
stages: [pre-commit, pre-merge-commit]
Expand All @@ -41,22 +35,13 @@ repos:
hooks:
- id: shellcheck
name: shellcheck (bin/sdlc and the tests)
entry: podman --events-backend=none run --rm --log-driver=none -v .:/mnt:ro,Z -w /mnt docker.io/koalaman/shellcheck:v0.11.0 bin/sdlc tests/contract.sh tests/test_host_contract.sh tests/test_tiers.sh
entry: podman --events-backend=none run --rm --log-driver=none -v .:/mnt:ro,Z -w /mnt docker.io/koalaman/shellcheck:v0.11.0 bin/sdlc tests/contract.sh tests/test_host_contract.sh
language: system
pass_filenames: false
always_run: true
stages: [pre-commit, pre-merge-commit]

# The two tests that keep this repo's own promises. Both are pure host
# work -- no image needed -- so they belong at commit, where they are free.
- id: tiers
name: tier membership agrees with .pre-commit-hooks.yaml
entry: tests/test_tiers.sh
language: script
pass_filenames: false
always_run: true
stages: [pre-commit, pre-merge-commit]

# Pure host work, no image needed, so it belongs at commit.
- id: host-contract
name: bin/sdlc needs only git, podman, pre-commit and gh
entry: tests/test_host_contract.sh
Expand Down Expand Up @@ -95,15 +80,3 @@ repos:
pass_filenames: false
always_run: true
stages: [pre-commit, pre-merge-commit]

# The contract test needs a built image, so it runs at pre-push rather than
# on every commit.
- repo: local
hooks:
- id: contract
name: contract test (builds the image)
entry: sh -c 'podman build -q -f Containerfile -t localhost/python-sdlc:precommit . && tests/contract.sh localhost/python-sdlc:precommit'
language: system
pass_filenames: false
always_run: true
stages: [pre-push]
Loading
Loading