Skip to content

Commit a20e5bd

Browse files
authored
ci(release): ask Coven to pin each published engine by default (#491)
Coven installs the engine its engine.lock names, so a coven-code release reaches Coven users only after that pin moves. The pin has been moved by hand for the last two releases. release.yml gains a last job that dispatches OpenCoven/coven's engine-bump workflow once the release is published. That workflow regenerates the lock from the latest release and opens a pull request there for review. The job is on by default (advance_coven_engine) and holds no repository token. It needs COVEN_ENGINE_BUMP_TOKEN, a token allowed to run workflows in OpenCoven/coven. Without the secret it warns and passes, because the release is already out and Coven's scheduled run proposes the pin later. Refs OpenCoven/coven#1773.
1 parent 272768f commit a20e5bd

4 files changed

Lines changed: 117 additions & 1 deletion

File tree

‎.github/workflows/release-version-tests.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
paths:
66
- 'scripts/check-release-version.py'
77
- 'scripts/test-release-version.py'
8+
- 'scripts/test-release-engine-pin.py'
89
- 'scripts/bump-version.py'
910
- '.github/workflows/release.yml'
1011
- '.github/workflows/auto-release.yml'
@@ -27,3 +28,5 @@ jobs:
2728
python-version: '3.12'
2829
- name: Verify release preflight and forward-only ordering
2930
run: python3 -B scripts/test-release-version.py -v
31+
- name: Verify the Coven engine pin request
32+
run: python3 -B scripts/test-release-engine-pin.py -v

‎.github/workflows/release.yml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ on:
1212
required: false
1313
type: boolean
1414
default: false
15+
advance_coven_engine:
16+
description: 'After publishing, ask OpenCoven/coven to propose this release as its pinned engine. Needs the COVEN_ENGINE_BUMP_TOKEN secret; without it the release still succeeds and Coven finds the release on its own schedule.'
17+
required: false
18+
type: boolean
19+
default: true
1520

1621
# Serialize all release versions and asset replacement, not just one tag.
1722
# Preflight rechecks remote versions after acquiring this shared group.
@@ -253,3 +258,31 @@ jobs:
253258
--ref main \
254259
-f version="$RELEASE_VERSION"
255260
echo "Dispatched npm-publish.yml for $RELEASE_VERSION."
261+
262+
# ── Ask Coven to pin the engine just published ──────────────────────
263+
# Coven installs the engine its `crates/coven-cli/engine.lock` names, so a
264+
# release reaches Coven users only after that pin moves. Coven's
265+
# engine-bump workflow regenerates the pin from the latest release here and
266+
# opens a pull request for a person to review and merge; this job starts it
267+
# as soon as the release exists. GITHUB_TOKEN cannot reach another
268+
# repository, so the dispatch needs a token that can run workflows in
269+
# OpenCoven/coven. Without one this job warns and passes: the release is
270+
# already published and Coven's scheduled run proposes the pin later.
271+
advance-coven-engine:
272+
needs: release
273+
if: ${{ inputs.advance_coven_engine }}
274+
runs-on: ubuntu-latest
275+
name: Propose Coven engine pin
276+
permissions: {}
277+
steps:
278+
- name: Dispatch Coven's engine-bump workflow
279+
env:
280+
GH_TOKEN: ${{ secrets.COVEN_ENGINE_BUMP_TOKEN }}
281+
run: |
282+
set -euo pipefail
283+
if [[ -z "${GH_TOKEN:-}" ]]; then
284+
echo "::warning::COVEN_ENGINE_BUMP_TOKEN is not set, so OpenCoven/coven was not asked to pin $RELEASE_VERSION. Its scheduled engine-bump run will propose the pin."
285+
exit 0
286+
fi
287+
gh workflow run engine-bump.yml --repo OpenCoven/coven --ref main
288+
echo "Asked OpenCoven/coven to propose pinning $RELEASE_VERSION."

‎COVEN.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ tag; use a new version for fixes rather than replacing published assets.
203203
`.github/workflows/release.yml` from the approved main commit with the chosen
204204
version. The workflow publishes a GitHub Release; it is not a dry run.
205205
Verify the uploaded archives, installers and checksum manifest before
206-
announcing the release or updating managed engine pins.
206+
announcing the release or merging a managed engine pin. By default the
207+
workflow's last job asks OpenCoven/coven to propose the pin: it dispatches
208+
Coven's `engine-bump.yml`, which regenerates `engine.lock` from the new
209+
release and opens a pull request there for review. The job needs the
210+
`COVEN_ENGINE_BUMP_TOKEN` secret, a token allowed to run workflows in
211+
OpenCoven/coven. Without it the job warns and Coven's scheduled run
212+
proposes the pin later. Pass `advance_coven_engine=false` to skip it.
207213
7. Keep `publish_npm` false. `@opencoven/coven-code` is deprecated; npm publication
208214
is an explicit opt-in through the release workflow, not a routine release step.
209215

‎scripts/test-release-engine-pin.py‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python3
2+
"""Hold the release workflow's Coven engine pin request to its contract.
3+
4+
Runs the job's own script against a recording stand-in for `gh`; nothing is
5+
dispatched.
6+
"""
7+
import os
8+
from pathlib import Path
9+
import re
10+
import subprocess
11+
import tempfile
12+
import textwrap
13+
import unittest
14+
15+
ROOT = Path(__file__).resolve().parents[1]
16+
RELEASE = (ROOT / '.github/workflows/release.yml').read_text(encoding='utf-8')
17+
JOB = RELEASE.split('\n advance-coven-engine:\n', 1)[1]
18+
STAND_IN = '#!/bin/sh\nprintf \'%s\\n\' "$*" >> "$GH_RECORD"\nexit "${GH_EXIT:-0}"\n'
19+
20+
21+
class CovenEnginePinRequestTests(unittest.TestCase):
22+
def run_step(self, token, gh_exit=0):
23+
script = textwrap.dedent(JOB.split(' run: |\n', 1)[1])
24+
with tempfile.TemporaryDirectory() as directory:
25+
record = Path(directory) / 'gh-calls'
26+
stand_in = Path(directory) / 'gh'
27+
stand_in.write_text(STAND_IN, encoding='utf-8')
28+
stand_in.chmod(0o700)
29+
env = {'PATH': f'{directory}:/usr/bin:/bin', 'HOME': directory, 'RELEASE_VERSION': 'v1.2.3',
30+
'GH_RECORD': str(record), 'GH_EXIT': str(gh_exit)}
31+
if token is not None:
32+
env['GH_TOKEN'] = token
33+
done = subprocess.run(['bash', '-c', script], cwd=directory, env=env,
34+
capture_output=True, text=True, timeout=10)
35+
calls = record.read_text(encoding='utf-8').splitlines() if record.exists() else []
36+
return done, calls
37+
38+
def test_requests_the_pin_by_default_and_can_be_turned_off(self):
39+
declared = RELEASE.split(' advance_coven_engine:\n', 1)[1].split('\n\n', 1)[0]
40+
self.assertIn(' type: boolean\n', declared)
41+
self.assertTrue(declared.endswith(' default: true'))
42+
self.assertIn(' if: ${{ inputs.advance_coven_engine }}\n', JOB)
43+
44+
def test_runs_only_after_publication_and_holds_no_repository_token(self):
45+
self.assertIn(' needs: release\n', JOB)
46+
self.assertIn(' permissions: {}\n', JOB)
47+
self.assertEqual(re.findall(r'secrets\.(\w+)', JOB), ['COVEN_ENGINE_BUMP_TOKEN'])
48+
self.assertNotIn('actions/checkout', JOB)
49+
self.assertEqual(RELEASE.count('COVEN_ENGINE_BUMP_TOKEN }}'), 1)
50+
51+
def test_dispatches_the_engine_bump_workflow_on_coven_main(self):
52+
done, calls = self.run_step('token')
53+
self.assertEqual(done.returncode, 0, done.stdout + done.stderr)
54+
self.assertEqual(calls, ['workflow run engine-bump.yml --repo OpenCoven/coven --ref main'])
55+
self.assertIn('v1.2.3', done.stdout)
56+
57+
def test_missing_token_warns_and_does_not_fail_the_published_release(self):
58+
for token in (None, ''):
59+
with self.subTest(token=token):
60+
done, calls = self.run_step(token)
61+
self.assertEqual(done.returncode, 0, done.stdout + done.stderr)
62+
self.assertEqual(calls, [])
63+
self.assertIn('::warning::COVEN_ENGINE_BUMP_TOKEN is not set', done.stdout)
64+
self.assertIn('v1.2.3', done.stdout)
65+
66+
def test_refused_dispatch_fails_the_job(self):
67+
done, calls = self.run_step('token', gh_exit=1)
68+
self.assertNotEqual(done.returncode, 0)
69+
self.assertEqual(len(calls), 1)
70+
self.assertNotIn('Asked OpenCoven/coven', done.stdout)
71+
72+
73+
if __name__ == '__main__':
74+
unittest.main()

0 commit comments

Comments
 (0)