diff --git a/.github/workflows/build-gpgui-linux.yaml b/.github/workflows/build-gpgui-linux.yaml index aa2c9cb..64514ea 100644 --- a/.github/workflows/build-gpgui-linux.yaml +++ b/.github/workflows/build-gpgui-linux.yaml @@ -12,6 +12,9 @@ on: channel: required: true type: string + build: + required: true + type: string builder: required: true type: string @@ -85,7 +88,7 @@ jobs: - name: Build gpgui in Docker env: GPGUI_BUILDER: ${{ inputs.builder }} - GPGUI_BUILD_VERSION: ${{ github.run_number }}.${{ github.run_attempt }} + GPGUI_BUILD_VERSION: ${{ inputs.build }} GPGUI_UPDATE_CHANNEL: ${{ inputs.channel }} GPGUI_LICENSE_SIGNING_KEYS: ${{ vars.GPGUI_LICENSE_SIGNING_KEYS }} run: | diff --git a/.github/workflows/build-gpgui-nsh-linux.yaml b/.github/workflows/build-gpgui-nsh-linux.yaml index e98eb68..478f040 100644 --- a/.github/workflows/build-gpgui-nsh-linux.yaml +++ b/.github/workflows/build-gpgui-nsh-linux.yaml @@ -12,6 +12,9 @@ on: channel: required: true type: string + build: + required: true + type: string secrets: GH_PAT: required: true @@ -35,7 +38,7 @@ jobs: env: CARGO_INCREMENTAL: '0' CARGO_BUILD_JOBS: '2' - GPGUI_BUILD_VERSION: ${{ github.run_number }}.${{ github.run_attempt }} + GPGUI_BUILD_VERSION: ${{ inputs.build }} GPGUI_GIT_COMMIT: ${{ inputs.gpgui_ref }} GPGUI_UPDATE_CHANNEL: ${{ inputs.channel }} GPGUI_LICENSE_SIGNING_KEYS: ${{ vars.GPGUI_LICENSE_SIGNING_KEYS }} diff --git a/.github/workflows/publish-macos-assets.yaml b/.github/workflows/publish-macos-assets.yaml index 76077b2..2a34c17 100644 --- a/.github/workflows/publish-macos-assets.yaml +++ b/.github/workflows/publish-macos-assets.yaml @@ -1,6 +1,21 @@ name: Publish macOS assets on: + workflow_call: + inputs: + build_run_id: + required: true + type: string + release_tag: + required: true + type: string + expected_gui: + required: false + default: nsh + type: string + secrets: + GH_PAT: + required: false workflow_dispatch: inputs: build_run_id: diff --git a/.github/workflows/publish-windows-update-feed.yaml b/.github/workflows/publish-windows-update-feed.yaml index 085f36e..cfdfa4e 100644 --- a/.github/workflows/publish-windows-update-feed.yaml +++ b/.github/workflows/publish-windows-update-feed.yaml @@ -1,6 +1,33 @@ name: Publish Windows update feed on: + workflow_call: + inputs: + gpgui_ref: + required: true + type: string + release_tag: + required: true + type: string + version: + required: true + type: string + channel: + required: true + type: string + build: + required: true + type: string + highlights: + required: true + type: string + secrets: + GH_PAT: + required: true + CLOUDFLARE_ACCOUNT_ID: + required: false + CLOUDFLARE_API_TOKEN: + required: false workflow_dispatch: inputs: gpgui_ref: diff --git a/scripts/record-build-sources.py b/scripts/record-build-sources.py index c45ecad..956bbb2 100644 --- a/scripts/record-build-sources.py +++ b/scripts/record-build-sources.py @@ -1,33 +1,45 @@ #!/usr/bin/env python3 -"""Retain one source pair per build run so retries cannot move branch refs.""" +"""Retain one source and version identity per build run, including retries.""" import argparse import json import os import re +import runpy import subprocess from pathlib import Path -def record(path, gp, gpgui, output): +def record(path, gp, gpgui, output, build_version): if path.exists(): - sources = json.loads(path.read_text()) + identity = json.loads(path.read_text()) else: - sources = { + identity = { name: subprocess.check_output(["git", "-C", str(root), "rev-parse", "HEAD"], text=True, stderr=subprocess.DEVNULL).strip() for name, root in (("gp_sha", gp), ("gpgui_sha", gpgui)) } - if set(sources) != {"gp_sha", "gpgui_sha"} or any( + cargo_version = runpy.run_path(str(Path(__file__).with_name("validate-release-version.py")))["cargo_version"] + version = cargo_version(gp) + if cargo_version(gpgui) != version: + raise ValueError("public and desktop product versions differ") + identity.update(version=version, build_version=build_version) + if set(identity) != {"gp_sha", "gpgui_sha", "version", "build_version"} or any( not isinstance(value, str) or not re.fullmatch(r"[0-9a-f]{40}", value) - for value in sources.values() + for name, value in identity.items() if name.endswith("_sha") ): raise ValueError("invalid retained build source refs") + if not isinstance(identity["version"], str) or not re.fullmatch(r"\d+\.\d+\.\d+", identity["version"]): + raise ValueError("invalid retained product version") + if not isinstance(identity["build_version"], str) or not re.fullmatch( + r"(0|[1-9]\d*)\.(0|[1-9]\d*)", identity["build_version"] + ): + raise ValueError("invalid retained build version") path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(json.dumps(sources, indent=2) + "\n") + path.write_text(json.dumps(identity, indent=2) + "\n") with output.open("a") as stream: - for name, sha in sources.items(): - stream.write(f"{name}={sha}\n") + for name, value in identity.items(): + stream.write(f"{name}={value}\n") def main(): @@ -35,9 +47,10 @@ def main(): parser.add_argument("path", type=Path) parser.add_argument("--gp", type=Path, required=True) parser.add_argument("--gpgui", type=Path, required=True) + parser.add_argument("--build-version", required=True) args = parser.parse_args() try: - record(args.path, args.gp, args.gpgui, Path(os.environ["GITHUB_OUTPUT"])) + record(args.path, args.gp, args.gpgui, Path(os.environ["GITHUB_OUTPUT"]), args.build_version) except (OSError, ValueError, subprocess.CalledProcessError): parser.exit(1, "Could not retain the selected build source refs.\n") diff --git a/scripts/tests/test_release_flow.py b/scripts/tests/test_release_flow.py index 20f0c88..6eeeff3 100644 --- a/scripts/tests/test_release_flow.py +++ b/scripts/tests/test_release_flow.py @@ -90,24 +90,43 @@ class ReleaseVersionTests(unittest.TestCase): versions.validate(root, package=package) -class SourceSelectionTests(unittest.TestCase): +class BuildIdentityTests(unittest.TestCase): def test_retry_uses_original_sources_after_both_branches_advance(self): with tempfile.TemporaryDirectory() as temp: root = Path(temp) paths = [root / 'gp', root / 'gpgui'] for repo in paths: initialize(repo) + write_version(repo) (repo / 'source').write_text('first') commit(repo, 'first') path, output = root / 'sources.json', root / 'output' - sources.record(path, *paths, output) + sources.record(path, *paths, output, '42.1') original = json.loads(path.read_text()) for repo in paths: + write_version(repo, '3.2.0') (repo / 'source').write_text('second') commit(repo, 'second') - sources.record(path, *paths, output) + sources.record(path, *paths, output, '42.2') self.assertEqual(json.loads(path.read_text()), original) self.assertEqual(output.read_text().count(f"gp_sha={original['gp_sha']}"), 2) + self.assertEqual(original['version'], '3.1.0') + self.assertEqual(original['build_version'], '42.1') + sources.record(path, root / 'missing-gp', root / 'missing-gui', output, '42.3') + self.assertEqual(json.loads(path.read_text()), original) + + def test_mismatched_product_versions_are_not_retained(self): + with tempfile.TemporaryDirectory() as temp: + root = Path(temp) + paths = [root / 'gp', root / 'gpgui'] + for repo, version in zip(paths, ['3.1.0', '3.2.0']): + initialize(repo) + write_version(repo, version) + commit(repo, 'source') + path = root / 'sources.json' + with self.assertRaisesRegex(ValueError, 'versions differ'): + sources.record(path, *paths, root / 'output', '42.1') + self.assertFalse(path.exists()) def test_corrupt_retained_sources_do_not_resolve_again(self): with tempfile.TemporaryDirectory() as temp: @@ -115,7 +134,7 @@ class SourceSelectionTests(unittest.TestCase): path = root / 'sources.json' path.write_text('{"gp_sha":"main","gpgui_sha":"main"}') with self.assertRaises(ValueError): - sources.record(path, root, root, root / 'output') + sources.record(path, root, root, root / 'output', '42.1') class PromotionTests(unittest.TestCase): @@ -196,6 +215,65 @@ class SnapshotBranchTests(unittest.TestCase): self.assertEqual(git(origin, 'branch', '--list', 'main'), '') +class PublicationWorkflowTests(unittest.TestCase): + def job(self, name): + source = (ROOT / '.github/workflows/build.yaml').read_text() + return re.search(r'(?ms)^ ' + name + r':\n.*?(?=^ [\w-]+:|\Z)', source).group(0) + + def decisions(self, name, cases): + expression = re.search(r'\$\{\{ (.*?) \}\}', self.job(name), re.DOTALL).group(1) + expression = re.sub(r'needs\.([\w-]+)\.result', r'needs["\1"].result', expression) + script = """ +const cases = JSON.parse(process.argv[1]); +const allows = new Function('needs', 'inputs', 'github', 'cancelled', + 'return (' + process.argv[2] + ')'); +console.log(JSON.stringify(cases.map(c => allows(c.needs, c.inputs, c.github, () => c.cancelled)))); +""" + return json.loads(subprocess.check_output( + ['node', '-e', script, json.dumps(cases), expression], text=True)) + + def test_macos_assets_require_both_jobs_and_a_live_run(self): + job = self.job('publish-macos-assets') + self.assertIn('needs: [build-macos, gh-release]', job) + self.assertIn('uses: ./.github/workflows/publish-macos-assets.yaml', job) + cases, expected = [], [] + for macos in ['success', 'failure', 'skipped', 'cancelled']: + for release in ['success', 'failure', 'skipped', 'cancelled']: + for cancelled in [False, True]: + cases.append({'needs': {'build-macos': {'result': macos}, + 'gh-release': {'result': release}}, + 'inputs': {}, 'github': {}, 'cancelled': cancelled}) + expected.append(not cancelled and macos == release == 'success') + self.assertEqual(self.decisions('publish-macos-assets', cases), expected) + + def test_snapshot_feeds_follow_selection_and_publication_results(self): + cases, expected_windows, expected_macos = [], [], [] + for macos in [False, True]: + for windows in [False, True]: + for override in [{}, {'channel': 'stable'}, {'build_only': True}, + {'event': 'push'}, {'cancelled': True}, {'release': 'failure'}, + {'macos_publish': 'failure'}, {'windows_feed': 'failure'}]: + inputs = dict(channel='snapshot', build_only=False, + build_macos=macos, build_windows=windows) + inputs.update({key: value for key, value in override.items() if key in inputs}) + release = override.get('release', 'success') + macos_publish = override.get('macos_publish', 'success') if macos else 'skipped' + windows_feed = override.get('windows_feed', 'success') if windows else 'skipped' + cancelled = override.get('cancelled', False) + event = override.get('event', 'workflow_dispatch') + cases.append({'needs': {'gh-release': {'result': release}, + 'publish-macos-assets': {'result': macos_publish}, + 'publish-windows-snapshot-feed': {'result': windows_feed}}, + 'inputs': inputs, 'github': {'event_name': event}, 'cancelled': cancelled}) + ready = (not cancelled and event == 'workflow_dispatch' and + inputs['channel'] == 'snapshot' and not inputs['build_only'] and + release == 'success' and (not macos or macos_publish == 'success')) + expected_windows.append(ready and windows) + expected_macos.append(ready and macos and (not windows or windows_feed == 'success')) + self.assertEqual(self.decisions('publish-windows-snapshot-feed', cases), expected_windows) + self.assertEqual(self.decisions('publish-macos-unix-snapshot-feeds', cases), expected_macos) + + class DockerMatrixTests(unittest.TestCase): def test_workflow_matrix_follows_all_architecture_choices(self): source = (ROOT / '.github/workflows/release.yaml').read_text()