Skip to content
Closed
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
105 changes: 94 additions & 11 deletions .github/workflows/generate-evidence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Generate source-pinned website evidence

on:
workflow_dispatch:
push:
branches:
- "deps/**"

permissions:
contents: read
Expand All @@ -12,6 +15,7 @@ concurrency:

jobs:
generate-and-verify:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: read
Expand Down Expand Up @@ -113,14 +117,75 @@ jobs:
if-no-files-found: error
retention-days: 1

generate-dependency-locks:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: read
timeout-minutes: 15
steps:
- name: Check out the exact dependency branch commit without a persistent token
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ github.sha }}
fetch-depth: 0
persist-credentials: false

- name: Set up Python for the pinned uv toolchain
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: "3.15"

- name: Install tox and tox-uv (provides the uv CLI used by CI)
run: python -m pip install tox tox-uv

- name: Set up Node for the pinned pnpm toolchain
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: "22.23.4"

- name: Regenerate lockfiles from dependency manifests only
run: |
set -euo pipefail
git fetch origin main
changed="$(git diff --name-only origin/main...HEAD)"

if printf '%s\n' "$changed" | grep -Fxq 'pyproject.toml'; then
uv lock
fi

if printf '%s\n' "$changed" | grep -Fxq 'website/package.json'; then
corepack enable
corepack prepare pnpm@10.12.1 --activate
(cd website && pnpm install --lockfile-only --ignore-scripts)
fi

mkdir -p "$RUNNER_TEMP/dependency-lockfiles/website"
cp uv.lock "$RUNNER_TEMP/dependency-lockfiles/uv.lock"
cp website/pnpm-lock.yaml "$RUNNER_TEMP/dependency-lockfiles/website/pnpm-lock.yaml"

- name: Upload generated lockfiles for the isolated commit job
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: dependency-lockfiles
path: ${{ runner.temp }}/dependency-lockfiles/
if-no-files-found: error
retention-days: 1

commit-evidence:
needs: generate-and-verify
needs: [generate-and-verify, generate-dependency-locks]
if: >-
always() &&
((github.event_name == 'workflow_dispatch' && needs.generate-and-verify.result == 'success') ||
(github.event_name == 'push' && needs.generate-dependency-locks.result == 'success'))
runs-on: ubuntu-latest
permissions:
contents: write
timeout-minutes: 5
steps:
- name: Require the branch to remain at the dispatch commit
- name: Require the branch to remain at the triggering commit
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
case "$GITHUB_REF" in
refs/heads/*) ;;
Expand All @@ -138,12 +203,22 @@ jobs:
persist-credentials: true

- name: Download verified evidence
if: github.event_name == 'workflow_dispatch'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: source-pinned-website-evidence
path: generated-evidence

- name: Commit generated evidence with bot identity
- name: Download generated dependency lockfiles
if: github.event_name == 'push'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: dependency-lockfiles
path: generated-lockfiles

- name: Commit generated files with bot identity
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
set -euo pipefail

Expand All @@ -154,20 +229,28 @@ jobs:
exit 1
fi

test -f generated-evidence/routes.json
test -f generated-evidence/check_versions_output.txt
mkdir -p website/src/data/generated
cp generated-evidence/routes.json website/src/data/generated/routes.json
cp generated-evidence/check_versions_output.txt website/src/data/generated/check_versions_output.txt
if [ "$GITHUB_EVENT_NAME" = "push" ]; then
test -f generated-lockfiles/uv.lock
test -f generated-lockfiles/website/pnpm-lock.yaml
cp generated-lockfiles/uv.lock uv.lock
cp generated-lockfiles/website/pnpm-lock.yaml website/pnpm-lock.yaml
git add -- uv.lock website/pnpm-lock.yaml
else
test -f generated-evidence/routes.json
test -f generated-evidence/check_versions_output.txt
mkdir -p website/src/data/generated
cp generated-evidence/routes.json website/src/data/generated/routes.json
cp generated-evidence/check_versions_output.txt website/src/data/generated/check_versions_output.txt
git add -- website/src/data/generated/routes.json website/src/data/generated/check_versions_output.txt
fi

git diff --check
git add -- website/src/data/generated/routes.json website/src/data/generated/check_versions_output.txt
if git diff --cached --quiet; then
echo "Generated evidence is already current at $GITHUB_SHA."
echo "Generated files are already current at $GITHUB_SHA."
exit 0
fi

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "data: generate source-pinned Segment Lab evidence"
git commit -m "chore(deps): refresh dependency lockfiles"
git push origin "HEAD:refs/heads/$GITHUB_REF_NAME"
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ Follow `AGENTS.md` and the relevant canonical skill in `.agents/skills/`. The pa
- Edit website articles only in `docs/articles/`; generated article copies and RSS output are build products and must not be committed.
- Update `website/pnpm-lock.yaml` from `website/package.json` with the pinned pnpm version on the active topic branch. Do not use npm lockfiles or update dependency locks directly on `main`.

## Dependency lockfiles

- Treat `uv.lock` and `website/pnpm-lock.yaml` as generated artifacts. Never hand-edit either file.
- When `pyproject.toml` changes, regenerate the Python lock with `uv lock` and verify it with `uv lock --check`. Use the same `uv` CLI provided by the repository's `tox-uv` toolchain.
- When `website/package.json` changes, use Node `22.23.4`, Corepack, and the pinned `pnpm@10.12.1`; regenerate with `pnpm install --lockfile-only --ignore-scripts` from `website/`.
- Dependency branches under `deps/` use the guarded lock-refresh path in `.github/workflows/generate-evidence.yml`: generation runs with read-only permissions, and only the isolated commit job can push the generated lockfiles. It does not execute package lifecycle scripts.
- A generated lockfile is not sufficient validation. The PR gate must pass for the final branch head after the lockfile commit.



## Security and dependency policy

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dev = [
"twine>=7.0.0",
"build>=1.6.1",
"djangorestframework>=3.18",
"tomli>=2.0.1; python_version < '3.11'",
"tomli>=2.5.0; python_version < '3.11'",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion requirements-ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ pytest>=9.2.0
pytest-django>=4.14.0
pytest-cov>=7.1.0
djangorestframework>=3.18.3
tomli>=2.0.1; python_version < "3.11"
tomli>=2.5.0; python_version < "3.11"
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mypy>=2.4.0
twine>=7.0.0
build>=1.6.1
djangorestframework>=3.18.3
tomli>=2.0.1; python_version < "3.11"
tomli>=2.5.0; python_version < "3.11"
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading