mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-20 11:25:56 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5796cffb5e | ||
|
|
112cb7e69c | ||
|
|
517e04dace | ||
|
|
e87cd0bb78 |
No files matched your search
@@ -16,7 +16,34 @@ permissions:
|
|||||||
contents: write
|
contents: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
release-intent:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
build: ${{ steps.intent.outputs.build }}
|
||||||
|
steps:
|
||||||
|
- id: intent
|
||||||
|
name: Keep already published release assets immutable
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
REQUEST_PUBLISH: ${{ inputs.publish_release && 'true' || 'false' }}
|
||||||
|
run: |
|
||||||
|
python3 - <<'PY'
|
||||||
|
import json, os, subprocess
|
||||||
|
build = True
|
||||||
|
if os.environ['GITHUB_EVENT_NAME'] == 'push' or os.environ.get('REQUEST_PUBLISH') == 'true':
|
||||||
|
result = subprocess.run(['gh', 'api', 'repos/' + os.environ['GITHUB_REPOSITORY'] + '/releases/tags/' + os.environ['GITHUB_REF_NAME']], capture_output=True, text=True)
|
||||||
|
if result.returncode == 0:
|
||||||
|
build = json.loads(result.stdout)['draft']
|
||||||
|
if not build:
|
||||||
|
print('Published release already exists; preserve its assets and prerelease status.')
|
||||||
|
elif 'HTTP 404' not in result.stderr:
|
||||||
|
raise RuntimeError('Could not establish whether this release already exists: ' + result.stderr)
|
||||||
|
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
|
||||||
|
output.write('build=' + str(build).lower() + '\n')
|
||||||
|
PY
|
||||||
installer:
|
installer:
|
||||||
|
needs: release-intent
|
||||||
|
if: needs.release-intent.outputs.build == 'true'
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
timeout-minutes: 60
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
+21
-7
@@ -42,7 +42,7 @@ def published(repo, component):
|
|||||||
|
|
||||||
|
|
||||||
def fragment_note(text, areas):
|
def fragment_note(text, areas):
|
||||||
sections = text.strip().split('---', 2)
|
sections = text.lstrip('\ufeff').strip().split('---', 2)
|
||||||
if len(sections) != 3 or sections[0]:
|
if len(sections) != 3 or sections[0]:
|
||||||
raise ValueError('Invalid release fragment')
|
raise ValueError('Invalid release fragment')
|
||||||
fields = dict(line.split(':', 1) for line in sections[1].splitlines() if ':' in line)
|
fields = dict(line.split(':', 1) for line in sections[1].splitlines() if ':' in line)
|
||||||
@@ -58,12 +58,12 @@ def fragment_note(text, areas):
|
|||||||
return title
|
return title
|
||||||
|
|
||||||
|
|
||||||
def remote_fragments(repo, sha, seen, areas):
|
def remote_fragments(repo, sha, seen, areas, excluded_blobs=()):
|
||||||
if not re.fullmatch(r'[0-9a-f]{40}', sha):
|
if not re.fullmatch(r'[0-9a-f]{40}', sha):
|
||||||
raise ValueError('Changelog collection requires an immutable source SHA')
|
raise ValueError('Changelog collection requires an immutable source SHA')
|
||||||
listing = api(f'repos/{repo}/contents/changelog.d?ref={sha}')
|
listing = api(f'repos/{repo}/contents/changelog.d?ref={sha}')
|
||||||
files = [f for f in listing if re.fullmatch(r'\d{8}-[a-z0-9-]+\.md', f['name'])]
|
files = [f for f in listing if re.fullmatch(r'\d{8}-[a-z0-9-]+\.md', f['name'])]
|
||||||
new = [f for f in files if repo + ':' + f['name'] not in seen]
|
new = [f for f in files if repo + ':' + f['name'] not in seen and f['sha'] not in excluded_blobs]
|
||||||
|
|
||||||
def read(item):
|
def read(item):
|
||||||
blob = api(f'repos/{repo}/git/blobs/{item["sha"]}')
|
blob = api(f'repos/{repo}/git/blobs/{item["sha"]}')
|
||||||
@@ -75,32 +75,46 @@ def remote_fragments(repo, sha, seen, areas):
|
|||||||
|
|
||||||
|
|
||||||
def collect_manager(root, tag, seen):
|
def collect_manager(root, tag, seen):
|
||||||
sha = subprocess.check_output(['git', '-C', str(root), 'rev-parse', tag + '^{commit}'], encoding='utf8', newline='\n').strip()
|
sha = subprocess.check_output(['git', '-C', str(root), 'rev-parse', tag + '^{commit}'], encoding='utf8').strip()
|
||||||
paths = subprocess.check_output(['git', '-C', str(root), 'ls-tree', '-r', '--name-only', sha, 'changelog.d'], encoding='utf8', newline='\n').splitlines()
|
paths = subprocess.check_output(['git', '-C', str(root), 'ls-tree', '-r', '--name-only', sha, 'changelog.d'], encoding='utf8').splitlines()
|
||||||
paths = [p for p in paths if re.fullmatch(r'changelog.d/\d{8}-[a-z0-9-]+\.md', p)]
|
paths = [p for p in paths if re.fullmatch(r'changelog.d/\d{8}-[a-z0-9-]+\.md', p)]
|
||||||
repo = 'Corfirean/coa-server-manager'
|
repo = 'Corfirean/coa-server-manager'
|
||||||
notes = []
|
notes = []
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if repo + ':' + Path(path).name not in seen:
|
if repo + ':' + Path(path).name not in seen:
|
||||||
text = subprocess.check_output(['git', '-C', str(root), 'show', f'{sha}:{path}'], encoding='utf8', newline='\n')
|
text = subprocess.check_output(['git', '-C', str(root), 'show', f'{sha}:{path}'], encoding='utf8')
|
||||||
note = fragment_note(text, MANAGER_AREAS)
|
note = fragment_note(text, MANAGER_AREAS)
|
||||||
if note:
|
if note:
|
||||||
notes.append(note)
|
notes.append(note)
|
||||||
return notes, [repo + ':' + Path(p).name for p in paths], {'commit': sha}
|
return notes, [repo + ':' + Path(p).name for p in paths], {'commit': sha}
|
||||||
|
|
||||||
|
|
||||||
|
def upstream_fragment_blobs(lock):
|
||||||
|
upstream = lock['components'].get('upstream')
|
||||||
|
if not upstream:
|
||||||
|
return set()
|
||||||
|
prefix = 'repos/' + upstream['repository'] + '/git/trees/'
|
||||||
|
tree = api(prefix + upstream['sha'])['tree']
|
||||||
|
directory = next((item for item in tree if item['path'] == 'changelog.d' and item['type'] == 'tree'), None)
|
||||||
|
if not directory:
|
||||||
|
return set()
|
||||||
|
files = api(prefix + directory['sha'])['tree']
|
||||||
|
return {item['sha'] for item in files if item['type'] == 'blob' and re.fullmatch(r'\d{8}-[a-z0-9-]+\.md', item['path'])}
|
||||||
|
|
||||||
|
|
||||||
def collect_server(repo, tag, seen, previous):
|
def collect_server(repo, tag, seen, previous):
|
||||||
with tempfile.TemporaryDirectory() as folder:
|
with tempfile.TemporaryDirectory() as folder:
|
||||||
subprocess.run(['gh', 'release', 'download', tag, '--repo', repo, '--pattern', 'release-lock.json', '--dir', folder], check=True)
|
subprocess.run(['gh', 'release', 'download', tag, '--repo', repo, '--pattern', 'release-lock.json', '--dir', folder], check=True)
|
||||||
lock = json.loads((Path(folder) / 'release-lock.json').read_text(encoding='utf-8-sig'))
|
lock = json.loads((Path(folder) / 'release-lock.json').read_text(encoding='utf-8-sig'))
|
||||||
notes, ids = [], []
|
notes, ids = [], []
|
||||||
|
imported_blobs = upstream_fragment_blobs(lock)
|
||||||
for role in ('core', 'bots', 'scaling', 'build'):
|
for role in ('core', 'bots', 'scaling', 'build'):
|
||||||
item = lock['components'].get(role)
|
item = lock['components'].get(role)
|
||||||
if not item:
|
if not item:
|
||||||
raise ValueError('Release lock has no ' + role + ' source')
|
raise ValueError('Release lock has no ' + role + ' source')
|
||||||
if item['repository'] == 'Corfirean/coa-server-manager':
|
if item['repository'] == 'Corfirean/coa-server-manager':
|
||||||
raise ValueError('A Manager source cannot supply server release notes')
|
raise ValueError('A Manager source cannot supply server release notes')
|
||||||
entries, found = remote_fragments(item['repository'], item['sha'], seen, SERVER_AREAS)
|
entries, found = remote_fragments(item['repository'], item['sha'], seen, SERVER_AREAS, imported_blobs if role == 'core' else ())
|
||||||
notes.extend(entries)
|
notes.extend(entries)
|
||||||
ids.extend(found)
|
ids.extend(found)
|
||||||
old = previous.get('components', {})
|
old = previous.get('components', {})
|
||||||
|
|||||||
@@ -51,6 +51,48 @@ class ComponentHistoryTests(unittest.TestCase):
|
|||||||
api.assert_called_once_with('repos/owner/repo/contents/changelog.d?ref=' + 'a' * 40)
|
api.assert_called_once_with('repos/owner/repo/contents/changelog.d?ref=' + 'a' * 40)
|
||||||
with self.assertRaises(ValueError): sync.remote_fragments('owner/repo', 'main', set(), sync.SERVER_AREAS)
|
with self.assertRaises(ValueError): sync.remote_fragments('owner/repo', 'main', set(), sync.SERVER_AREAS)
|
||||||
|
|
||||||
|
def test_manager_collection_reads_the_real_frozen_tag(self):
|
||||||
|
with tempfile.TemporaryDirectory() as folder:
|
||||||
|
root = Path(folder)
|
||||||
|
fragments = root / 'changelog.d'
|
||||||
|
fragments.mkdir()
|
||||||
|
own = fragments / '20261021-own.md'
|
||||||
|
own.write_text('---\narea: manager\ntitle: Characters show their saved versions\n---\n', encoding='utf8')
|
||||||
|
(fragments / '20261021-server.md').write_text('---\narea: server\ntitle: Server only\n---\n', encoding='utf8')
|
||||||
|
subprocess.run(['git', 'init', '-q', str(root)], check=True)
|
||||||
|
subprocess.run(['git', '-C', str(root), 'add', '.'], check=True)
|
||||||
|
subprocess.run(['git', '-C', str(root), '-c', 'user.name=Fixture', '-c', 'user.email=fixture@example.invalid', '-c', 'commit.gpgsign=false', 'commit', '-qm', 'Frozen notes'], check=True)
|
||||||
|
subprocess.run(['git', '-C', str(root), 'tag', 'v0.7.0'], check=True)
|
||||||
|
own.write_text('Uncommitted content must not become release notes', encoding='utf8')
|
||||||
|
notes, ids, source = sync.collect_manager(root, 'v0.7.0', set())
|
||||||
|
self.assertEqual(notes, ['Characters show their saved versions'])
|
||||||
|
self.assertEqual(len(ids), 2)
|
||||||
|
self.assertEqual(len(source['commit']), 40)
|
||||||
|
seen = {'Corfirean/coa-server-manager:20261021-own.md'}
|
||||||
|
self.assertEqual(sync.collect_manager(root, 'v0.7.0', seen)[0], [])
|
||||||
|
|
||||||
|
def test_utf8_bom_does_not_break_a_valid_historical_fragment(self):
|
||||||
|
text = '\ufeff---\narea: bots\ntitle: Companions keep their combat form\n---\n'
|
||||||
|
self.assertEqual(sync.fragment_note(text, sync.SERVER_AREAS), 'Companions keep their combat form')
|
||||||
|
|
||||||
|
def test_imported_upstream_fragments_are_not_credited_as_our_changes(self):
|
||||||
|
import base64
|
||||||
|
listing = [{'name': '20261021-imported.md', 'sha': 'upstream'}, {'name': '20261021-own.md', 'sha': 'own'}]
|
||||||
|
body = base64.b64encode(b'---\narea: server\ntitle: Our portable sessions\n---\n').decode()
|
||||||
|
with patch.object(sync, 'api', side_effect=[listing, {'content': body}]) as calls:
|
||||||
|
notes, consumed = sync.remote_fragments('owner/core', 'a' * 40, set(), sync.SERVER_AREAS, {'upstream'})
|
||||||
|
self.assertEqual(notes, ['Our portable sessions'])
|
||||||
|
self.assertEqual(len(consumed), 2)
|
||||||
|
self.assertEqual(calls.call_count, 2)
|
||||||
|
self.assertTrue(calls.call_args.args[0].endswith('/git/blobs/own'))
|
||||||
|
|
||||||
|
def test_upstream_exclusions_use_the_frozen_source_tree(self):
|
||||||
|
lock = {'components': {'upstream': {'repository': 'upstream/core', 'sha': 'frozen'}}}
|
||||||
|
with patch.object(sync, 'api', side_effect=[{'tree': [{'path': 'changelog.d', 'type': 'tree', 'sha': 'notes-tree'}]}, {'tree': [{'path': '20261021-imported.md', 'type': 'blob', 'sha': 'imported'}, {'path': 'README.md', 'type': 'blob', 'sha': 'readme'}]}]) as calls:
|
||||||
|
self.assertEqual(sync.upstream_fragment_blobs(lock), {'imported'})
|
||||||
|
self.assertEqual(calls.call_args_list[0].args[0], 'repos/upstream/core/git/trees/frozen')
|
||||||
|
self.assertEqual(calls.call_args_list[1].args[0], 'repos/upstream/core/git/trees/notes-tree')
|
||||||
|
|
||||||
def test_render_is_component_scoped_and_stable(self):
|
def test_render_is_component_scoped_and_stable(self):
|
||||||
text = sync.render(self.history())
|
text = sync.render(self.history())
|
||||||
self.assertIn('# CoA Server Manager changelog', text)
|
self.assertIn('# CoA Server Manager changelog', text)
|
||||||
|
|||||||
Reference in new issue
Block a user