From 55bc991b69b7c5cb3c0047d79e7f2df047b1dfce Mon Sep 17 00:00:00 2001 From: Zach Nelson Date: Thu, 19 Nov 2026 14:09:48 -0600 Subject: [PATCH] Version CoreZen, starting at 0.1.0, with a changelog --- .github/workflows/objective-c-xcode.yml | 5 + .github/workflows/release.yml | 40 +++++++ CHANGELOG.md | 11 ++ CoreZen.xcodeproj/project.pbxproj | 6 +- CoreZen/CoreZen.h | 6 +- README.md | 8 ++ Scripts/check_version.py | 133 ++++++++++++++++++++++++ 7 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 CHANGELOG.md create mode 100755 Scripts/check_version.py diff --git a/.github/workflows/objective-c-xcode.yml b/.github/workflows/objective-c-xcode.yml index 6716718..539c2d4 100644 --- a/.github/workflows/objective-c-xcode.yml +++ b/.github/workflows/objective-c-xcode.yml @@ -30,6 +30,11 @@ jobs: brew install clang-format Scripts/format.sh --check + # The project's version and CHANGELOG.md's newest version should match + - name: Check Version + run: | + Scripts/check_version.py + - name: Prepare Keychain For Signing env: SECRET_MACOS_CERTIFICATE_B64: ${{ secrets.MACOS_CERTIFICATE }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0635e52 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,40 @@ +name: Release + +# When a version tag like v0.1.0 is pushed, publish a GitHub release for it, with +# that version's CHANGELOG.md entry as its notes. The tag has to be on main, +# whose commits CI has built and tested, and has to name the version that the +# project and CHANGELOG.md give. +on: + push: + tags: [ "v*" ] + +permissions: + contents: write + +jobs: + release: + name: Publish a release for a version tag + runs-on: ubuntu-latest + + steps: + # All of the history, to see whether main contains the tag + - name: Checkout + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Check Tag + run: | + if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then + echo "::error::$GITHUB_REF_NAME isn't on main. Tag a commit from main instead." + exit 1 + fi + Scripts/check_version.py --tag "$GITHUB_REF_NAME" + + - name: Create Release + env: + GH_TOKEN: ${{ github.token }} + run: | + Scripts/check_version.py --notes > notes.md + gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag \ + --title "CoreZen ${GITHUB_REF_NAME#v}" --notes-file notes.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5634173 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +Notable changes to CoreZen, newest first. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the versions follow [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Until 1.0.0, a version that breaks the API raises the middle number, and any other version raises the last. + +To note a change, add a line under Unreleased, in a group such as Added, Changed or Fixed. The README says how to release a version. + +## Unreleased + +## 0.1.0 - 2026-11-19 + +The first tagged version, with the persistence layer, media playback and frame rendering, and utilities that the README describes. Changes made before it are in the git history. diff --git a/CoreZen.xcodeproj/project.pbxproj b/CoreZen.xcodeproj/project.pbxproj index 536a92e..65d0370 100644 --- a/CoreZen.xcodeproj/project.pbxproj +++ b/CoreZen.xcodeproj/project.pbxproj @@ -1470,7 +1470,7 @@ "$(PROJECT_DIR)/Dependencies/lib", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 0.1.0; PRODUCT_BUNDLE_IDENTIFIER = com.zdnelson.CoreZen; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1514,7 +1514,7 @@ "$(PROJECT_DIR)/Dependencies/lib", ); MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 0.1.0; PRODUCT_BUNDLE_IDENTIFIER = com.zdnelson.CoreZen; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1537,7 +1537,6 @@ ); GENERATE_INFOPLIST_FILE = YES; MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.zdnelson.CoreZenTests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1560,7 +1559,6 @@ ); GENERATE_INFOPLIST_FILE = YES; MACOSX_DEPLOYMENT_TARGET = 14.0; - MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = com.zdnelson.CoreZenTests; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/CoreZen/CoreZen.h b/CoreZen/CoreZen.h index f02ae28..054c230 100644 --- a/CoreZen/CoreZen.h +++ b/CoreZen/CoreZen.h @@ -7,10 +7,12 @@ #import -//! Project version number for CoreZen. +// CoreZen's version, such as 0.1.0, is its bundle's CFBundleShortVersionString. +// These two come from Xcode's build number for the framework instead, which +// stays 1 (CURRENT_PROJECT_VERSION). + FOUNDATION_EXPORT double CoreZenVersionNumber; -//! Project version string for CoreZen. FOUNDATION_EXPORT const unsigned char CoreZenVersionString[]; // In this header, you should import all the public headers of your framework using statements like #import diff --git a/README.md b/README.md index 2d7fa36..b0f925f 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,14 @@ CoreZen logs to the unified log, under the subsystem `com.zdnelson.CoreZen`, in log stream --level info --predicate 'subsystem == "com.zdnelson.CoreZen"' ``` +### Versions + +CoreZen follows [Semantic Versioning](https://semver.org). Each release is a git tag such as `v0.1.0`, with a [GitHub release](https://github.com/znelson/CoreZen/releases) whose notes come from [`CHANGELOG.md`](https://github.com/znelson/CoreZen/blob/main/CHANGELOG.md). Until 1.0.0, a release that breaks the API raises the middle number (0.1.0 to 0.2.0), and any other release raises the last (0.1.0 to 0.1.1). At run time, the framework bundle's `CFBundleShortVersionString` is its version. + +To release a version: +1. In a pull request, rename CHANGELOG.md's Unreleased section to the version and date, such as `## 0.2.0 - 2026-12-01`, and add an empty Unreleased section above it. Set the CoreZen target's Version in Xcode (`MARKETING_VERSION`) to the same number. CI runs `Scripts/check_version.py`, which checks that the two match. +2. Once it's merged, tag the merge commit on main and push the tag: `git tag v0.2.0 && git push origin v0.2.0`. The Release workflow checks the tag against both, then publishes the GitHub release. + ## What's In CoreZen.framework? `CoreZen` has three parts: a persistence layer for a domain model stored in SQLite, media playback and frame rendering built on mpv and FFmpeg, and smaller AppKit and Foundation helpers. The public headers say which values can be `nil`. diff --git a/Scripts/check_version.py b/Scripts/check_version.py new file mode 100755 index 0000000..5d1225b --- /dev/null +++ b/Scripts/check_version.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +""" +Check that CoreZen's version is the same everywhere it's written down. + +The version is the CoreZen target's MARKETING_VERSION in CoreZen.xcodeproj, +which the framework reports as its CFBundleShortVersionString. CHANGELOG.md has a +section for each released version, newest first, below an Unreleased section for +changes since. A release is the commit tagged with its version, like v0.1.0. + +Usage: + ./check_version.py # Check the project's version is CHANGELOG.md's newest + ./check_version.py --tag v0.1.0 # Also check a release tag names that version + ./check_version.py --notes # Print that version's CHANGELOG.md entry, after checking + +CI runs it for every change, and with --tag when a version tag is pushed. It needs +only Python 3, including the one that comes with Xcode. +""" + +import argparse +import datetime +import os +import re +import sys + +ROOT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +CHANGELOG_PATH = os.path.join(ROOT_PATH, 'CHANGELOG.md') +PROJECT_PATH = os.path.join(ROOT_PATH, 'CoreZen.xcodeproj', 'project.pbxproj') + +UNRELEASED_HEADING = 'Unreleased' +# A released version's heading, like "0.1.0 - 2026-11-19". Semantic Versioning +# doesn't allow leading zeros. +VERSION_HEADING = re.compile(r'(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*) - (\d{4}-\d{2}-\d{2})') +MARKETING_VERSION = re.compile(r'^\s*MARKETING_VERSION = "?([^";]*)"?;', re.MULTILINE) + + +## +def fail(message): + print(f'check_version.py: {message}', file=sys.stderr) + sys.exit(1) + + +## +def read(path): + try: + with open(path, encoding='utf-8') as f: + return f.read() + except FileNotFoundError: + fail(f'{os.path.relpath(path, ROOT_PATH)} is missing') + + +## +def changelog_sections(text): + """CHANGELOG.md's "## " sections, in order, as (heading, body) pairs.""" + sections = [] + for line in text.splitlines(): + if line.startswith('## '): + sections.append((line[3:].strip(), [])) + elif sections: + sections[-1][1].append(line) + return [(heading, '\n'.join(body).strip()) for heading, body in sections] + + +## +def released_versions(sections): + """ + The released versions in CHANGELOG.md, newest first, as (version, entry) pairs. + Fails unless the first section is Unreleased and every other one is a version + with a date and an entry, each older than the one above it. + """ + if not sections or sections[0][0] != UNRELEASED_HEADING: + fail(f'CHANGELOG.md should start with a "## {UNRELEASED_HEADING}" section, for changes not yet released') + + versions = [] + newer = None + for heading, entry in sections[1:]: + match = VERSION_HEADING.fullmatch(heading) + if not match: + fail(f'CHANGELOG.md has a heading "## {heading}", but a version\'s should look like "## 1.2.3 - 2026-01-31"') + number = tuple(int(part) for part in match.group(1, 2, 3)) + version = '.'.join(match.group(1, 2, 3)) + try: + date = datetime.date.fromisoformat(match.group(4)) + except ValueError: + fail(f'CHANGELOG.md\'s heading "## {heading}" has a date that doesn\'t exist') + if not entry: + fail(f'CHANGELOG.md has no entry for {version}') + if newer: + newer_version, newer_number, newer_date = newer + if number >= newer_number: + fail(f'CHANGELOG.md lists {version} below {newer_version}; versions should go newest first') + if date > newer_date: + fail(f'CHANGELOG.md dates {version} after {newer_version}, which is listed above it') + versions.append((version, entry)) + newer = (version, number, date) + + if not versions: + fail('CHANGELOG.md has no released versions') + return versions + + +## +def project_versions(text): + """Every MARKETING_VERSION in the Xcode project, without repeats.""" + return sorted(set(MARKETING_VERSION.findall(text))) + + +## +def main(): + parser = argparse.ArgumentParser(description='Check that CoreZen\'s version is the same everywhere') + parser.add_argument('--tag', help='a release tag that should name the version, like v0.1.0') + parser.add_argument('--notes', action='store_true', help='print the version\'s CHANGELOG.md entry') + args = parser.parse_args() + + version, entry = released_versions(changelog_sections(read(CHANGELOG_PATH)))[0] + + found = project_versions(read(PROJECT_PATH)) + if not found: + fail('CoreZen.xcodeproj sets no MARKETING_VERSION') + if found != [version]: + fail(f'CoreZen.xcodeproj\'s MARKETING_VERSION is {", ".join(found)}, ' + f'but CHANGELOG.md\'s newest version is {version}') + + if args.tag is not None and args.tag != f'v{version}': + fail(f'the tag is {args.tag}, but {version}\'s tag should be v{version}') + + if args.notes: + print(entry) + else: + print(f'CoreZen {version}: CoreZen.xcodeproj and CHANGELOG.md agree') + + +if __name__ == '__main__': + main()