mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
CHANGELOG-big.md is the changelog as it was: # Status, # Upcoming and every release in full, with its <details> entries. Everything that writes or edits the changelog uses it - release-all.sh, release-notes.sh and the release workflow, the commit-link repair in build.sh and fix-changelog-hashes.sh, the archive, the wrapper, the version scripts - and the release notes' "More details at ChangeLog" link goes to its section. remote-release.py, shared with FerretDB and the patch repositories, takes the file from its config, and only WeKan's names CHANGELOG-big.md. CHANGELOG.md is new: no Status and no Upcoming, only the In short paragraph of each of the five newest releases and a link to its full section, in plain Markdown - no <details>, <summary>, </summary> or </details>, and HTML links written as Markdown links. releases/changelog-short.mjs writes it; release-all.sh runs it right after naming the release, so it is in the release commit, and changelog.sh does too. The Sandstorm App Market keeps embedding CHANGELOG.md, now the short one. old-CHANGELOG/'s headers say they moved out of CHANGELOG-big.md. References to Upcoming or TODO Later in code comments and docs name CHANGELOG-big.md. CLAUDE.md and AGENTS.md describe both files: CHANGELOG-big.md is written, CHANGELOG.md is generated and never edited by hand. tests/changelogShort.test.cjs: CHANGELOG.md is exactly what the generator writes, the five newest releases with their whole In short, links that resolve, and none of the four tags or an HTML link; the changelog tests read CHANGELOG-big.md. Thanks to xet7 !
309 lines
14 KiB
Python
309 lines
14 KiB
Python
#!/usr/bin/env python3
|
|
"""Human-run release launcher. --check and --audit never prepare or publish a release.
|
|
|
|
Identical standalone copies live in the six release repositories. Review records
|
|
are comparison baselines; findings are advisory and never require AI approval.
|
|
"""
|
|
import argparse
|
|
import datetime
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
DEPENDENCY_NAMES = {
|
|
'package.json', 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock',
|
|
'pnpm-lock.yaml', 'go.mod', 'go.sum', 'go.work', 'go.work.sum', 'Cargo.toml',
|
|
'Cargo.lock', 'requirements.txt', 'pyproject.toml', 'poetry.lock', 'uv.lock',
|
|
'Gemfile', 'Gemfile.lock', 'composer.json', 'composer.lock', 'packages',
|
|
'versions', 'release', 'node-major.txt',
|
|
}
|
|
|
|
|
|
def run(root, *args):
|
|
return subprocess.check_output(args, cwd=root, text=True).strip()
|
|
|
|
|
|
def gh_pages(text):
|
|
"""The pages `gh api --paginate` prints, as a list with one entry per page.
|
|
|
|
Without --slurp, gh prints the pages back to back ([...][...]), which one
|
|
json.loads cannot read. --slurp would wrap them in one array, but it exists
|
|
only from GitHub CLI 2.48 on, and an older gh stopped the release with
|
|
"unknown flag: --slurp". So the pages are read one after another here.
|
|
"""
|
|
decoder = json.JSONDecoder()
|
|
text = text.strip()
|
|
pages, i = [], 0
|
|
while i < len(text):
|
|
page, i = decoder.raw_decode(text, i)
|
|
pages.append(page)
|
|
while i < len(text) and text[i].isspace():
|
|
i += 1
|
|
return pages
|
|
|
|
|
|
def valid_origin(remote, repo):
|
|
"""Accept exact GitHub HTTPS and SSH clone URLs, with optional .git."""
|
|
return remote in {
|
|
prefix + repo + suffix
|
|
for prefix in ('https://github.com/', 'git@github.com:', 'ssh://git@github.com/')
|
|
for suffix in ('', '.git')
|
|
}
|
|
|
|
|
|
def inventory(root):
|
|
# Includes untracked, non-ignored manifests: git add --all would publish them.
|
|
names = run(root, 'git', 'ls-files', '-z', '--cached', '--others', '--exclude-standard').split('\0')
|
|
result = {}
|
|
for name in sorted(set(names)):
|
|
path = root / name
|
|
if not name or path.name not in DEPENDENCY_NAMES:
|
|
continue
|
|
if path.name in {'packages', 'versions', 'release'} and not name.startswith('.meteor/'):
|
|
continue
|
|
if not path.exists():
|
|
continue
|
|
if path.is_symlink() or not path.is_file():
|
|
raise ValueError('Dependency metadata must be a regular file: ' + name)
|
|
data = path.read_bytes().replace(b'\r\n', b'\n')
|
|
if path.name in {'package.json', 'package-lock.json'}:
|
|
doc = json.loads(data)
|
|
# A release number is not a dependency change. Nested package versions
|
|
# remain covered, including every resolved package in the lockfile.
|
|
if name in {'package.json', 'package-lock.json'}:
|
|
doc.pop('version', None)
|
|
if name == 'package-lock.json':
|
|
doc.get('packages', {}).get('', {}).pop('version', None)
|
|
data = json.dumps(doc, sort_keys=True, separators=(',', ':')).encode()
|
|
result[name] = hashlib.sha256(data).hexdigest()
|
|
return result
|
|
|
|
|
|
def audit(root, config):
|
|
"""Best-effort diagnostics only; never approve or block dependency changes."""
|
|
warnings = []
|
|
try:
|
|
expected = json.loads((root / 'releases/dependency-review.json').read_text(encoding='utf-8'))
|
|
actual = inventory(root)
|
|
changes = sorted(k for k in set(actual) | set(expected['files'])
|
|
if actual.get(k) != expected['files'].get(k))
|
|
if changes:
|
|
warnings.append('Dependency fingerprints changed: ' + ', '.join(changes))
|
|
for name in actual:
|
|
text = (root / name).read_text(encoding='utf-8', errors='replace')
|
|
known = expected.get('knownKeywordMatches', {}).get(name, {})
|
|
accepted = set(known.get('lines', [])) if known.get('reason') else set()
|
|
known_count = 0
|
|
unknown = set()
|
|
for line in text.splitlines():
|
|
keywords = re.findall(r'(?i)telemetry|segment|mixpanel|amplitude|posthog|sentry', line)
|
|
if not keywords:
|
|
continue
|
|
if line.strip() in accepted:
|
|
known_count += 1
|
|
else:
|
|
unknown.update(word.lower() for word in keywords)
|
|
if known_count:
|
|
print(f'Info: {name}: {known_count} known dependency keyword matches '
|
|
f'(false positives for default outbound reporting). {known["reason"]}', flush=True)
|
|
if unknown:
|
|
warnings.append('New/unclassified dependency keyword hints in ' + name + ': ' + ', '.join(sorted(unknown)))
|
|
|
|
except (ValueError, OSError, KeyError, subprocess.CalledProcessError) as error:
|
|
warnings.append('Dependency inventory unavailable: ' + str(error))
|
|
for command in config.get('audits', []):
|
|
try:
|
|
result = subprocess.run(command, cwd=root, check=False)
|
|
if result.returncode:
|
|
warnings.append('Source audit reported findings or could not complete: ' + ' '.join(command))
|
|
except OSError as error:
|
|
warnings.append('Source audit unavailable: ' + str(error))
|
|
for warning in warnings:
|
|
print('::warning::' + warning, file=sys.stderr)
|
|
indicator = config.get('indicatorCommand')
|
|
if indicator:
|
|
result = subprocess.run(indicator, cwd=root, check=False)
|
|
if result.returncode == 1:
|
|
raise ValueError('Automated source/dependency risk indicators found; see findings above.')
|
|
if result.returncode:
|
|
print('::warning::Indicator scan could not complete; continuing best effort.', file=sys.stderr)
|
|
print('Best-effort dependency audit completed' +
|
|
(' with warnings; release may continue.' if warnings else '; no metadata changes found.'), flush=True)
|
|
|
|
|
|
# The changelog the release notes are in and the release heading is written to.
|
|
# WeKan writes CHANGELOG-big.md (releases/remote-release.json); the other
|
|
# repositories this script releases keep CHANGELOG.md.
|
|
def changelog_of(config):
|
|
return config.get('changelog', 'CHANGELOG.md')
|
|
|
|
|
|
def notes(root, config, missing=False):
|
|
text = (root / changelog_of(config)).read_text(encoding='utf-8')
|
|
heading = config['upcoming']
|
|
if missing and heading not in text.splitlines():
|
|
# Completing a release does not require new notes or a new version.
|
|
if re.search(r'^#{1,2} (?:\[)?(?:v\d|main-|[0-9a-f]{40})', text, re.M):
|
|
return text
|
|
if text.splitlines().count(heading) != 1:
|
|
raise ValueError(changelog_of(config) + ' must have exactly one ' + heading)
|
|
rest = text.split(heading + '\n', 1)[1]
|
|
body = re.split(r'^#{1,2} (?!#)', rest, maxsplit=1, flags=re.M)[0]
|
|
if not re.search(r'<summary>.*?<a href=|^- \S', body, re.M):
|
|
raise ValueError('Upcoming must contain real changelog entries before releasing.')
|
|
return text
|
|
|
|
|
|
def source_version(root, config, requested=''):
|
|
upstream = config.get('upstream')
|
|
if not upstream:
|
|
return requested
|
|
try:
|
|
record = json.loads((root / upstream['review']).read_text(encoding='utf-8'))
|
|
except (ValueError, OSError):
|
|
record = {}
|
|
approved = record.get('upstreamCommit') or ''
|
|
if config['kind'] == 'node':
|
|
version = requested or run(root, 'bash', 'releases/newest-release.sh', '.')
|
|
major = (root / 'node-major.txt').read_text(encoding='utf-8').strip()
|
|
if not re.fullmatch(r'v' + re.escape(major) + r'\.\d+\.\d+', version):
|
|
raise ValueError('Invalid Node release tag')
|
|
lines = run(root, 'git', 'ls-remote', upstream['url'], 'refs/tags/' + version,
|
|
'refs/tags/' + version + '^{}').splitlines()
|
|
sha = lines[-1].split()[0] if lines else ''
|
|
elif config['kind'] == 'mongosh':
|
|
result = json.loads(run(root, 'node', 'releases/resolve-source.mjs', requested))
|
|
sha, version = result['commit'], result['release']
|
|
else:
|
|
# mongo-tools uses an immutable commit as the release/build identity.
|
|
ref = requested or 'master'
|
|
if re.fullmatch(r'master-[0-9a-f]{7,12}', ref) and approved.startswith(ref.split('-')[1]):
|
|
sha = approved
|
|
elif re.fullmatch('[0-9a-f]{40}', ref):
|
|
sha = ref
|
|
else:
|
|
lines = run(root, 'git', 'ls-remote', upstream['url'], 'refs/heads/' + ref,
|
|
'refs/tags/' + ref, 'refs/tags/' + ref + '^{}').splitlines()
|
|
sha = lines[-1].split()[0] if lines else ''
|
|
version = sha
|
|
if not re.fullmatch('[0-9a-f]{40}', sha):
|
|
raise ValueError('Unable to resolve an immutable upstream commit')
|
|
if sha != approved:
|
|
print('::warning::Upstream fingerprint changed or has no baseline: ' + sha +
|
|
'. Continuing with best-effort dependency checks.', file=sys.stderr)
|
|
return version
|
|
|
|
|
|
def latest(root, config):
|
|
# Network/API errors are fatal; never mistake an outage for a first release.
|
|
rows = gh_pages(run(root, 'gh', 'api', '--paginate',
|
|
'repos/' + config['repo'] + '/releases?per_page=100'))
|
|
return [x['tag_name'] for page in rows for x in page if not x['draft']]
|
|
|
|
|
|
def prepare_version(root, config, text, missing, requested):
|
|
kind = config['kind']
|
|
if kind in {'node', 'mongosh', 'mongo-tools'}:
|
|
if not missing:
|
|
return source_version(root, config, requested)
|
|
published = latest(root, config)
|
|
version = requested or (published[0] if published else '')
|
|
if version not in published:
|
|
raise ValueError('Release All Missing needs an existing published release.')
|
|
source_version(root, config, version)
|
|
return version
|
|
published = latest(root, config)
|
|
if missing:
|
|
version = requested or (published[0] if published else '')
|
|
if version not in published:
|
|
raise ValueError('Release All Missing needs an existing published release.')
|
|
return version
|
|
if kind == 'ferretdb':
|
|
local = re.findall(r'^## \[(v1\.\d+\.\d+)\]\(https://github.com/wekan/FerretDB/', text, re.M)
|
|
remote_tags = run(root, 'git', 'ls-remote', '--tags', 'origin', 'refs/tags/v1.*')
|
|
remote = re.findall(r'refs/tags/(v1\.\d+\.\d+)(?:\^\{\})?(?:\n|$)', remote_tags)
|
|
versions = [v for v in published + local + remote + run(root, 'git', 'tag', '--list').splitlines()
|
|
if re.fullmatch(r'v1\.\d+\.\d+', v)]
|
|
if not versions:
|
|
raise ValueError('No previous FerretDB v1 version found.')
|
|
newest = max(versions, key=lambda v: tuple(map(int, v[1:].split('.'))))
|
|
version = run(root, 'bash', 'build/ferretdb/next-version.sh', newest)
|
|
else:
|
|
versions = published + re.findall(r'^# (v\d+) ', text, re.M)
|
|
version = 'v' + str(max([int(v[1:]) for v in versions if re.fullmatch(r'v\d+', v)] + [0]) + 1)
|
|
if requested and requested != version:
|
|
raise ValueError('Expected next version ' + version)
|
|
return version
|
|
|
|
|
|
def publish(root, config, text, version, missing):
|
|
branch = config['branch']
|
|
if not missing:
|
|
date = datetime.date.today().isoformat()
|
|
if config['kind'] == 'ferretdb':
|
|
heading = f"## [{version}](https://github.com/{config['repo']}/releases/tag/{version}) ({date})"
|
|
else:
|
|
heading = f"# {version} {date} {config['repo'].split('/')[1]} release"
|
|
(root / changelog_of(config)).write_text(text.replace(config['upcoming'], heading, 1), encoding='utf-8')
|
|
# WeKan's CHANGELOG.md is the short changelog, written from CHANGELOG-big.md.
|
|
if (root / 'releases/changelog-short.mjs').exists():
|
|
subprocess.run(['node', 'releases/changelog-short.mjs'], cwd=root, check=True)
|
|
run(root, 'git', 'add', '--all')
|
|
if run(root, 'git', 'diff', '--cached', '--name-only'):
|
|
subprocess.run(['git', 'commit', '-m', ('Complete ' if missing else 'Prepare ') + version + ' release'], cwd=root, check=True)
|
|
subprocess.run(['git', 'push', 'origin', 'HEAD:refs/heads/' + branch], cwd=root, check=True)
|
|
workflow = 'release-all-missing.yml' if missing else 'release-all.yml'
|
|
if config['kind'] == 'wekan':
|
|
version = version.removeprefix('v')
|
|
subprocess.run(['gh', 'workflow', 'run', workflow, '--repo', config['repo'],
|
|
'--ref', branch, '-f', 'version=' + version], cwd=root, check=True)
|
|
print('Dispatched ' + workflow + ' for ' + version)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('mode', choices=['all', 'missing'], nargs='?', default='all')
|
|
parser.add_argument('version', nargs='?', default='')
|
|
parser.add_argument('--check', action='store_true', help='read-only full preflight (uses network)')
|
|
parser.add_argument('--upstream-version', action='store_true', help='verify upstream review and print immutable build input')
|
|
parser.add_argument('--audit', action='store_true', help='offline dependency/source audit only')
|
|
args = parser.parse_args()
|
|
root = Path(__file__).resolve().parent.parent
|
|
config = json.loads((root / 'releases/remote-release.json').read_text(encoding='utf-8'))
|
|
os.environ['DO_NOT_TRACK'] = '1'
|
|
os.environ['GOTELEMETRY'] = 'off'
|
|
(root / '.tools/tmp').mkdir(parents=True, exist_ok=True)
|
|
os.environ['TMPDIR'] = str(root / '.tools/tmp')
|
|
if args.upstream_version:
|
|
print(source_version(root, config, args.version))
|
|
return
|
|
if args.audit:
|
|
audit(root, config)
|
|
return
|
|
text = notes(root, config, args.mode == 'missing')
|
|
audit(root, config)
|
|
if run(root, 'git', 'branch', '--show-current') != config['branch']:
|
|
raise ValueError('Release from ' + config['branch'] + ' only.')
|
|
remote = run(root, 'git', 'remote', 'get-url', 'origin')
|
|
if not valid_origin(remote, config['repo']):
|
|
raise ValueError('origin must point to ' + config['repo'])
|
|
if run(root, 'git', 'diff', '--name-only', '--diff-filter=U'):
|
|
raise ValueError('Resolve merge conflicts before releasing.')
|
|
run(root, 'gh', 'auth', 'status')
|
|
version = prepare_version(root, config, text, args.mode == 'missing', args.version)
|
|
print('Release preflight passed: ' + version, flush=True)
|
|
if not args.check:
|
|
publish(root, config, text, version, args.mode == 'missing')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except (ValueError, OSError, subprocess.CalledProcessError) as error:
|
|
print('::error::Release stopped: ' + str(error), file=sys.stderr)
|
|
sys.exit(1)
|