gandalf#55, part 1 (no server changes needed).
- .gitea/workflows/ci.yml replaces lint.yml, test.yml and security.yml.
Jobs: Lint (Python) with the dash check, Lint (JS), Test, Security,
Scan (gitleaks over the full history, actionlint, shellcheck), Deploy
and Notify. Deploy needs every check, so failing tests or a bandit or
gitleaks finding no longer reach production.
- Pinned: actions/checkout to a full SHA, job images to digests (Python
3.13 on Debian 13 like CT 157, Node 22 for eslint), Python tools in the
new requirements-dev.txt, scanner downloads by SHA-256. No setup-python
(the runner's shared tool cache broke Pulse twice).
- Builds run on pull requests and on pushes to main only, plus a weekly
run on main; concurrency queues deploys and never cancels one.
- Deploy signs {"ref", "sha", "ts"} (unique per request), then waits up to
5 minutes until /health reports that commit for both processes, and only
then tags deploy-<date>-<run>.
- /health reports `sha` (version.py reads .git at startup, no subprocess)
and `monitor_sha` (the monitor writes it every cycle).
Part 2 (server side): the pinned deploy script that refuses stale or
replayed requests, deploys exactly that sha and rolls back.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
"""Tests for version.py: the running commit, read from .git without git itself (gandalf#55)."""
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
import version # noqa: E402
|
|
|
|
A, B = 'a' * 40, 'b' * 40
|
|
|
|
|
|
def _git(tmp_path, head, loose=None, packed=None):
|
|
g = tmp_path / '.git'
|
|
g.mkdir()
|
|
(g / 'HEAD').write_text(head + '\n')
|
|
if loose:
|
|
ref, sha = loose
|
|
p = g.joinpath(*ref.split('/'))
|
|
p.parent.mkdir(parents=True)
|
|
p.write_text(sha + '\n')
|
|
if packed:
|
|
(g / 'packed-refs').write_text('# pack-refs with: peeled fully-peeled sorted\n' + packed)
|
|
return str(tmp_path)
|
|
|
|
|
|
def test_detached_head_is_the_sha(tmp_path):
|
|
assert version.running_sha(_git(tmp_path, A)) == A
|
|
|
|
|
|
def test_branch_with_a_loose_ref(tmp_path):
|
|
assert version.running_sha(_git(tmp_path, 'ref: refs/heads/main', loose=('refs/heads/main', B))) == B
|
|
|
|
|
|
def test_branch_in_packed_refs(tmp_path):
|
|
packed = f'{A} refs/heads/other\n{B} refs/heads/main\n^{A}\n'
|
|
assert version.running_sha(_git(tmp_path, 'ref: refs/heads/main', packed=packed)) == B
|
|
|
|
|
|
def test_anything_unreadable_is_empty(tmp_path):
|
|
assert version.running_sha(str(tmp_path)) == '' # no .git
|
|
assert version.running_sha(_git(tmp_path, 'garbage')) == ''
|
|
other = tmp_path / 'y'
|
|
other.mkdir()
|
|
assert version.running_sha(_git(other, 'ref: refs/heads/gone')) == '' # ref missing
|
|
|
|
|
|
def test_this_checkout_reports_a_sha():
|
|
assert version.SHA == '' or len(version.SHA) == 40
|