Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Release notes: try an ordered list of Sonnet ids, move on only when the model is not available

v0lumehi50aed96a5dec
diff --git a/.github/release-notes/README.md b/.github/release-notes/README.md
index ecd012ba..1f4f4db9 100644
--- a/.github/release-notes/README.md
+++ b/.github/release-notes/README.md
@@ -3,7 +3,7 @@
`.github/workflows/release-notes.yml` writes the notes of a final release with the GitHub Copilot CLI and checks them before they are used. It follows the issue triage (`.github/triage/README.md`): the model only reads and never holds a write token. It runs on a Copilot subscription.
- **Where it runs:** the build of a final tag (`build-mac-app.yml`, job `notes`, before the step that creates the release), and by hand: Actions > release-notes > Run workflow.
-- **Setup:** the Actions secret `COPILOT_TOKEN` is the same one the triage uses (a fine-grained personal access token with only the account permission "Copilot Requests"). Optional: the repository variable `RELEASE_NOTES_MODEL` (Settings > Secrets and variables > Actions > Variables), a model id the CLI accepts, passed as `--model` like `TRIAGE_MODEL`. Unset, the workflow uses `claude-sonnet-5.5`, the newest Sonnet class model in GitHub's list of supported models. The notes need a stronger model than the triage's Haiku for the English and the Chinese text. Never set a Haiku here. Without the secret the model job writes nothing and the release gets the short body.
+- **Setup:** the Actions secret `COPILOT_TOKEN` is the same one the triage uses (a fine-grained personal access token with only the account permission "Copilot Requests"). Optional: the repository variable `RELEASE_NOTES_MODEL` (Settings > Secrets and variables > Actions > Variables), a model id the CLI accepts, passed as `--model` like `TRIAGE_MODEL`. Unset, the write job tries the ids in `NOTES_MODEL_CANDIDATES` at the top of the workflow, newest Sonnet first (`claude-sonnet-5.5`, `claude-sonnet-5`, `claude-sonnet-4.6`, `claude-sonnet-4.5`). The CLI lists no models and has no alias, so an id the account does not offer fails with `Model "<id>" from --model flag is not available.` and only that error moves on to the next id (`.github/scripts/notes_model.py`). Any other failure stops and the release gets the short body. The list never holds a Haiku or `auto`. The id that answered is in the job summary of `check`. To update the list, put a newer Sonnet from GitHub's supported models page in front. The variable replaces the whole list with one id and has no fallback. The notes need a stronger model than the triage's Haiku for the English and the Chinese text. Without the secret the model job writes nothing and the release gets the short body.
- **Jobs:** `gather` (`contents: read`, `pull-requests: read`, no secrets) writes the row of the version from `CHANGELOG.md` and `CHANGELOG.zh-CN.md`, the pull requests merged since the previous final tag (number, title, author, labels) and the template into one prompt. `write` (no permissions, the model token) runs the Copilot CLI in an empty directory with `--available-tools=view`, shell, write and URLs denied, no MCP servers and no repository instructions. `check` (no model token) runs `tools/release_notes.py check` on the answer and uploads it.
- **What reaches the release:** only a text that passes the check. The build adds `---` and GitHub's generated notes (`tools/release_notes.py build`, which checks the text again). A reviewed `release-notes/vX.Y.Z.md` wins over the model text. With no secret, a failed model job, an empty answer or a failed check the release gets the short body and a warning, and the job summary of `check` says why. A problem with the notes never stops a release.
- **Title:** the first line of the text is the title in bold, `**vX.Y.Z: English / Chinese**`. When the model text is used and that line can be read, the build sets the title with `gh release edit <tag> --title`. If it cannot be read, the title stays the tag.
diff --git a/.github/scripts/notes_model.py b/.github/scripts/notes_model.py
new file mode 100644
index 00000000..256113c5
--- /dev/null
+++ b/.github/scripts/notes_model.py
@@ -0,0 +1,100 @@
+"""Run the Copilot CLI for the release notes with the first model id the account accepts.
+
+The CLI does not list its models and has no alias for "the newest Sonnet": an id the account does not offer fails with
+`Error: Model "<id>" from --model flag is not available.` (copilot 1.0.105). So the ids come in an ordered list, newest first, and only that
+error moves on to the next one. Any other failure stops the chain. A Haiku id and `auto` are never used.
+
+ notes_model.py --prompt FILE --out ANSWER [--candidates "ID ID ..."] [--override ID]
+ --override (the repository variable RELEASE_NOTES_MODEL) replaces the list: that id alone, no fallback.
+Writes the answer to ANSWER and the id used to <ANSWER dir>/model.txt, sets `ran` and `model` in $GITHUB_OUTPUT. Exit 1 when no model answered.
+"""
+import argparse
+import os
+import re
+import subprocess
+import sys
+
+MODEL_ID = re.compile(r'^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$')
+NOT_AVAILABLE = re.compile(r'Model "[^"\n]*" from --model flag is not available\.')
+TIMEOUT = 600
+COPILOT_ARGS = ['--silent', '--no-ask-user', '--no-custom-instructions', '--no-auto-update', '--disable-builtin-mcps', '--disable-client-telemetry',
+ '--available-tools=view', '--allow-all-tools', '--deny-tool=shell', '--deny-tool=write', '--deny-tool=url',
+ '--secret-env-vars=COPILOT_GITHUB_TOKEN']
+
+
+class ChainError(Exception):
+ pass
+
+
+def check_candidates(ids, override=False):
+ """The ids, validated. The list never holds a Haiku or `auto`. A set override is only validated like TRIAGE_MODEL."""
+ if not ids:
+ raise ChainError('no model id to try')
+ for i in ids:
+ if not MODEL_ID.match(i):
+ raise ChainError('%r is not a model id' % i)
+ if not override and (i.lower() == 'auto' or 'haiku' in i.lower()):
+ raise ChainError('%r is not allowed in the list (no auto, no Haiku)' % i)
+ return list(ids)
+
+
+def is_not_available(text):
+ return bool(NOT_AVAILABLE.search(text))
+
+
+def run_chain(ids, run, log=print):
+ """Try `run(model)` -> (returncode, stdout, stderr) in order. Returns (model, stdout) of the first success.
+ Only the "not available" error goes on to the next id, anything else raises ChainError."""
+ for model in ids:
+ log('trying model %s' % model)
+ code, out, err = run(model)
+ if err.strip():
+ log('copilot said: %s' % err.strip()[:2000])
+ if code == 0:
+ return model, out
+ if is_not_available(out + '\n' + err):
+ log('model %s is not available to this account' % model)
+ continue
+ raise ChainError('copilot failed with exit code %s for model %s (not a model error, so no other model is tried)' % (code, model))
+ raise ChainError('none of the models is available to this account: %s' % ', '.join(ids))
+
+
+def copilot_runner(prompt):
+ def run(model):
+ try:
+ r = subprocess.run(['copilot', '--model', model, '-p', prompt, *COPILOT_ARGS], capture_output=True, text=True, timeout=TIMEOUT)
+ except subprocess.TimeoutExpired:
+ return 124, '', 'timed out after %d s' % TIMEOUT
+ return r.returncode, r.stdout, r.stderr
+ return run
+
+
+def main(argv=None):
+ p = argparse.ArgumentParser()
+ p.add_argument('--prompt', required=True)
+ p.add_argument('--out', required=True)
+ p.add_argument('--candidates', default='')
+ p.add_argument('--override', default='')
+ args = p.parse_args(argv)
+ try:
+ override = args.override.strip()
+ ids = check_candidates([override] if override else args.candidates.split(), bool(override))
+ with open(args.prompt, encoding='utf-8') as f:
+ prompt = f.read()
+ model, answer = run_chain(ids, copilot_runner(prompt))
+ except (ChainError, OSError) as e:
+ print('::error title=Release notes::%s' % e)
+ return 1
+ with open(args.out, 'w', encoding='utf-8') as f:
+ f.write(answer)
+ with open(os.path.join(os.path.dirname(os.path.abspath(args.out)), 'model.txt'), 'w', encoding='utf-8') as f:
+ f.write(model + '\n')
+ print('model used: %s' % model)
+ if os.environ.get('GITHUB_OUTPUT'):
+ with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as f:
+ f.write('ran=true\nmodel=%s\n' % model)
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
diff --git a/.github/scripts/tests/test_notes_model.py b/.github/scripts/tests/test_notes_model.py
new file mode 100644
index 00000000..27622be9
--- /dev/null
+++ b/.github/scripts/tests/test_notes_model.py
@@ -0,0 +1,130 @@
+import os
+import sys
+import tempfile
+import unittest
+from pathlib import Path
+from unittest import mock
+
+sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
+import notes_model as nm # noqa: E402
+
+ROOT = Path(__file__).resolve().parents[3]
+LIST = ['claude-sonnet-5.5', 'claude-sonnet-5', 'claude-sonnet-4.6', 'claude-sonnet-4.5']
+
+
+def refused(model):
+ return 1, '', 'Error: Model "%s" from --model flag is not available.\n' % model
+
+
+class Fake:
+ """A runner that accepts only some ids and records the calls."""
+ def __init__(self, accepted=(), other_failure=()):
+ self.accepted, self.other, self.calls = set(accepted), set(other_failure), []
+
+ def __call__(self, model):
+ self.calls.append(model)
+ if model in self.accepted:
+ return 0, 'the notes\n', ''
+ if model in self.other:
+ return 2, '', 'Error: authentication failed'
+ return refused(model)
+
+
+class Chain(unittest.TestCase):
+ def run_chain(self, fake, ids=LIST):
+ logs = []
+ return nm.run_chain(ids, fake, logs.append), logs
+
+ def test_first_id_works(self):
+ fake = Fake(LIST)
+ (model, out), _ = self.run_chain(fake)
+ self.assertEqual((model, out, fake.calls), ('claude-sonnet-5.5', 'the notes\n', ['claude-sonnet-5.5']))
+
+ def test_goes_on_after_not_available(self):
+ fake = Fake(['claude-sonnet-4.6'])
+ (model, _), logs = self.run_chain(fake)
+ self.assertEqual((model, fake.calls), ('claude-sonnet-4.6', LIST[:3]))
+ self.assertTrue(any('copilot said: Error: Model "claude-sonnet-5.5" from --model flag is not available.' in l for l in logs))
+
+ def test_none_available(self):
+ fake = Fake()
+ with self.assertRaises(nm.ChainError) as c:
+ self.run_chain(fake)
+ self.assertEqual(fake.calls, LIST)
+ self.assertIn('none of the models', str(c.exception))
+
+ def test_other_failure_stops_the_chain(self):
+ fake = Fake(['claude-sonnet-4.5'], other_failure=['claude-sonnet-5'])
+ with self.assertRaises(nm.ChainError):
+ self.run_chain(fake)
+ self.assertEqual(fake.calls, ['claude-sonnet-5.5', 'claude-sonnet-5'])
+
+ def test_message_is_matched_on_stdout_too(self):
+ run = lambda m: (1, 'Error: Model "%s" from --model flag is not available.' % m, '') if m == 'a' else (0, 'ok', '')
+ self.assertEqual(nm.run_chain(['a', 'b'], run, lambda s: None), ('b', 'ok'))
+
+ def test_a_similar_message_is_not_a_model_error(self):
+ self.assertFalse(nm.is_not_available('Error: rate limit, the service is not available'))
+ self.assertFalse(nm.is_not_available('Model rejected'))
+ self.assertTrue(nm.is_not_available('Error: Model "x-1.0" from --model flag is not available.'))
+
+
+class Candidates(unittest.TestCase):
+ def test_list_is_fine(self):
+ self.assertEqual(nm.check_candidates(LIST), LIST)
+
+ def test_no_haiku_no_auto_in_the_list(self):
+ for bad in ('claude-haiku-4.5', 'Claude-HAIKU-5.5', 'auto', 'AUTO'):
+ with self.assertRaises(nm.ChainError, msg=bad):
+ nm.check_candidates(['claude-sonnet-5.5', bad])
+
+ def test_not_an_id(self):
+ for bad in ('', '-x', 'a b'.split()[0] + ';rm', 'x' * 65, '$(id)'):
+ with self.assertRaises(nm.ChainError, msg=bad):
+ nm.check_candidates([bad])
+
+ def test_empty_list(self):
+ with self.assertRaises(nm.ChainError):
+ nm.check_candidates([])
+
+ def test_override_is_validated_like_triage_model(self):
+ self.assertEqual(nm.check_candidates(['gpt-5.4'], override=True), ['gpt-5.4'])
+ with self.assertRaises(nm.ChainError):
+ nm.check_candidates(['bad id;'], override=True)
+
+ def test_workflow_list_is_clean_and_newest_first(self):
+ text = (ROOT / '.github/workflows/release-notes.yml').read_text(encoding='utf-8')
+ line = next(l for l in text.splitlines() if l.strip().startswith('NOTES_MODEL_CANDIDATES:'))
+ ids = line.split(':', 1)[1].split('#')[0].strip().strip("'\"").split()
+ self.assertEqual(nm.check_candidates(ids), ids)
+ self.assertEqual(ids[0], 'claude-sonnet-5.5')
+ self.assertTrue(all('sonnet' in i for i in ids))
+
+
+class Main(unittest.TestCase):
+ def go(self, runner, *extra):
+ with tempfile.TemporaryDirectory() as d:
+ prompt, out, gh = (os.path.join(d, n) for n in ('prompt.txt', 'answer.txt', 'gh_out'))
+ Path(prompt).write_text('p', encoding='utf-8')
+ with mock.patch.object(nm, 'copilot_runner', return_value=runner), mock.patch.dict(os.environ, {'GITHUB_OUTPUT': gh}):
+ code = nm.main(['--prompt', prompt, '--out', out, *extra])
+ read = lambda p: Path(p).read_text(encoding='utf-8') if os.path.exists(p) else None
+ return code, read(out), read(os.path.join(d, 'model.txt')), read(gh)
+
+ def test_success_writes_answer_model_and_outputs(self):
+ code, answer, model, gh = self.go(Fake(['claude-sonnet-5']), '--candidates', ' '.join(LIST))
+ self.assertEqual((code, answer, model, gh), (0, 'the notes\n', 'claude-sonnet-5\n', 'ran=true\nmodel=claude-sonnet-5\n'))
+
+ def test_override_has_no_fallback(self):
+ fake = Fake(['claude-sonnet-5.5'])
+ code, answer, _, gh = self.go(fake, '--candidates', ' '.join(LIST), '--override', 'gpt-5.4')
+ self.assertEqual((code, answer, gh), (1, None, None))
+ self.assertEqual(fake.calls, ['gpt-5.4'])
+
+ def test_failure_writes_nothing(self):
+ code, answer, model, gh = self.go(Fake(), '--candidates', ' '.join(LIST))
+ self.assertEqual((code, answer, model, gh), (1, None, None, None))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/.github/workflows/release-notes.yml b/.github/workflows/release-notes.yml
index ba98d46c..e99a0f15 100644
--- a/.github/workflows/release-notes.yml
+++ b/.github/workflows/release-notes.yml
@@ -42,6 +42,11 @@ on:
permissions: {}
env:
+ # The model ids to try, newest Sonnet first, separated by spaces. The CLI lists no models and has no alias for "the newest Sonnet", so the
+ # write job takes the first id the account accepts: only the error `Model "<id>" from --model flag is not available.` moves on to the next
+ # one. No Haiku and no `auto` (notes_model.py refuses them). To update: put a new id in front when GitHub's supported models page lists
+ # a newer Sonnet, and drop ids that are gone. The repository variable RELEASE_NOTES_MODEL replaces the whole list with one id.
+ NOTES_MODEL_CANDIDATES: claude-sonnet-5.5 claude-sonnet-5 claude-sonnet-4.6 claude-sonnet-4.5
TAG: ${{ inputs.tag }}
PUBLISH: ${{ inputs.publish }}
@@ -69,7 +74,9 @@ jobs:
- name: Prepare the data for the model
env:
GH_TOKEN: ${{ github.token }}
- run: python3 -I .github/scripts/notes_gather.py --repo "$GITHUB_REPOSITORY" --tag "$TAG" --out "$RUNNER_TEMP/notes"
+ run: |
+ python3 -I .github/scripts/notes_gather.py --repo "$GITHUB_REPOSITORY" --tag "$TAG" --out "$RUNNER_TEMP/notes"
+ cp .github/scripts/notes_model.py "$RUNNER_TEMP/notes/" # the write job has no checkout
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: notes-input
@@ -113,28 +120,20 @@ jobs:
if: steps.secret.outputs.set == 'true'
env:
COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_TOKEN }}
- # Optional repository variable (a model id). Unset, the default is the newest Sonnet class model Copilot lists (Claude Sonnet 5.5): the
- # notes need a stronger model than the triage's Haiku for the English and the Chinese text. Never a Haiku. Bump on purpose.
- NOTES_MODEL: ${{ vars.RELEASE_NOTES_MODEL || 'claude-sonnet-5.5' }}
+ NOTES_MODEL_VAR: ${{ vars.RELEASE_NOTES_MODEL }} # optional repository variable (a model id): that id alone, no fallback
run: |
# An empty directory holds nothing to read. The model can only call `view`; shell, file writes and URLs are denied
- # (deny rules win over --allow-all-tools, which prompt mode needs), no MCP servers, no repository instructions.
- mkdir -p "$RUNNER_TEMP/empty"
+ # (deny rules win over --allow-all-tools, which prompt mode needs), no MCP servers, no repository instructions. The flags are in notes_model.py.
+ mkdir -p "$RUNNER_TEMP/empty" "$RUNNER_TEMP/out"
cd "$RUNNER_TEMP/empty"
- [[ "$NOTES_MODEL" =~ ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$ ]] || { echo "::error::RELEASE_NOTES_MODEL is not a model id"; exit 1; }
- model=(--model "$NOTES_MODEL") # one argument, never part of a shell string
- echo "model: $NOTES_MODEL"
# prompt.txt is at most 90000 bytes (notes_gather.py), below the 128 KiB limit of one argument
- timeout 600 copilot "${model[@]}" -p "$(cat "$RUNNER_TEMP/notes/prompt.txt")" --silent --no-ask-user --no-custom-instructions \
- --no-auto-update --disable-builtin-mcps --disable-client-telemetry \
- --available-tools=view --allow-all-tools --deny-tool=shell --deny-tool=write --deny-tool=url \
- --secret-env-vars=COPILOT_GITHUB_TOKEN > "$RUNNER_TEMP/notes/answer.txt"
- echo "ran=true" >> "$GITHUB_OUTPUT"
+ python3 -I "$RUNNER_TEMP/notes/notes_model.py" --prompt "$RUNNER_TEMP/notes/prompt.txt" --out "$RUNNER_TEMP/out/answer.txt" \
+ --candidates "$NOTES_MODEL_CANDIDATES" --override "$NOTES_MODEL_VAR"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: steps.copilot.outputs.ran == 'true'
with:
name: notes-answer
- path: ${{ runner.temp }}/notes/answer.txt
+ path: ${{ runner.temp }}/out
retention-days: 3
check:
@@ -174,6 +173,7 @@ jobs:
mv "$out/model.md" "$out/rejected.md"
fi
fi
+ model=$(cat "$RUNNER_TEMP/answer/model.txt" 2> /dev/null || true)
title=""
if [ -f "$out/model.md" ]; then
title=$(python3 -I .github/scripts/notes_finish.py title "$out/model.md" "$TAG")
@@ -182,6 +182,8 @@ jobs:
{
echo "## Release notes for $TAG"
echo
+ echo "Model used: ${model:-none (no model answered, see the log of the write job)}"
+ echo
if [ -n "$reason" ]; then
echo "No model text is used: $reason. The release gets the short body, or a reviewed release-notes/$TAG.md if there is one."
if [ -f "$out/check.txt" ]; then echo; echo '```'; cat "$out/check.txt"; echo '```'; fi