From 1c00eedb0adabe14e3b6a85e1f6abba3d7f6258e Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:04:49 +0100 Subject: [PATCH 01/12] ci(release): open release PRs with generated notes and start the next dev version --- .github/workflows/publish.yml | 28 +++++- .github/workflows/release.yml | 182 ++++++++++++++++++++++++++++++++++ cliff.toml | 52 ++++++++++ 3 files changed, 261 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/release.yml create mode 100644 cliff.toml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 38c57d279..7bc52034b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -20,8 +20,12 @@ on: - both - timenet - timenet-connectors + ref: + description: Release tag to build, for example v0.12.0. Leave empty to build the branch above. + required: false + type: string -run-name: Publish ${{ inputs.package }} to ${{ inputs.target }} +run-name: Publish ${{ inputs.package }} ${{ inputs.ref }} to ${{ inputs.target }} env: BRANCH_NAME: ${{ github.head_ref || github.ref_name }} @@ -49,8 +53,30 @@ jobs: fi - name: Checkout uses: actions/checkout@v5 + with: + ref: ${{ inputs.ref || github.ref }} + fetch-depth: 0 + - name: Guard the release tag + if: inputs.ref != '' + env: + REF: ${{ inputs.ref }} + run: | + if ! [[ "$REF" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || ! git merge-base --is-ancestor HEAD origin/main; then + echo "::error title=Invalid ref::Build only a vX.Y.Z tag on main, not '$REF'." + exit 1 + fi - name: Set up uv uses: astral-sh/setup-uv@v7 + - name: Guard PyPI to release versions + if: inputs.target == 'PyPI' + run: | + for package in timenet timenet-connectors; do + version=$(uv version --package "$package" --short) + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error title=Development version::$package is at $version. Publish a release tag instead." + exit 1 + fi + done - name: Build # build_dists.py records the commit inside each package, so a build can name its code. run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..db9a42d06 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,182 @@ +name: Release + +# Releases both packages in lockstep, in three steps: +# 1. Run this workflow on main. It opens a release PR that sets the version and shows the notes. +# 2. Merge the release PR. This tags vX.Y.Z, creates the GitHub release, starts publish.yml for +# the tag (which waits for approval in the pypi environment), and opens a PR that moves main +# to the next development version, X.(Y+1).0.dev0. +# 3. Approve the publish run, then merge the development-version PR. +# +# Needs a GitHub App with contents and pull-requests write access, installed on this repository, +# with its id in the RELEASE_APP_ID variable and its key in the RELEASE_APP_PRIVATE_KEY secret. +# PRs opened with GITHUB_TOKEN are blocked by the repository settings and would not run CI. + +on: + workflow_dispatch: + inputs: + version: + description: Version to release, for example 0.12.0. Leave empty to compute it from the commits. + required: false + type: string + pull_request: + types: [closed] + branches: [main] + +permissions: + contents: read + +env: + GIT_CLIFF: git-cliff==2.14.2 + +jobs: + prepare: + if: github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + - name: Guard to main + if: github.ref != 'refs/heads/main' + run: | + echo "::error title=Invalid branch::Start a release from main." + exit 1 + - id: app-token + uses: actions/create-github-app-token@v2 + with: + app-id: ${{ vars.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + token: ${{ steps.app-token.outputs.token }} + - uses: astral-sh/setup-uv@v8.2.0 + - name: Choose the version + id: version + env: + REQUESTED: ${{ inputs.version }} + run: | + version=${REQUESTED:-$(uvx "$GIT_CLIFF" --bumped-version)} + version=${version#v} + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error title=Invalid version::'$version' is not X.Y.Z." + exit 1 + fi + if git rev-parse -q --verify "refs/tags/v$version" >/dev/null; then + echo "::error title=Version exists::Tag v$version already exists." + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + - name: Set the version and write the notes + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + for package in timenet timenet-connectors; do + uv version --package "$package" "$VERSION" --frozen + done + # Connectors needs the timenet release that ships with it. + sed -i -E "s/\"timenet\[build\]>=[^\"]*\"/\"timenet[build]>=$VERSION\"/" packages/timenet-connectors/pyproject.toml + grep -q "\"timenet\[build\]>=$VERSION\"" packages/timenet-connectors/pyproject.toml + uv lock + uvx "$GIT_CLIFF" --unreleased --tag "v$VERSION" --strip header --output "$RUNNER_TEMP/notes.md" + - name: Open the release PR + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + VERSION: ${{ steps.version.outputs.version }} + run: | + branch="release/v$VERSION" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git switch -c "$branch" + git commit -am "chore(release): $VERSION" + git push origin "$branch" + { + echo "Merging this PR tags v$VERSION, creates the GitHub release with the notes below, and" + echo "starts the PyPI publish run for approval. To change the notes, edit them in the" + echo "GitHub release after it is created." + echo + echo "---" + echo + cat "$RUNNER_TEMP/notes.md" + } > "$RUNNER_TEMP/body.md" + gh pr create --base main --head "$branch" --title "chore(release): $VERSION" --body-file "$RUNNER_TEMP/body.md" + + release: + if: >- + github.event_name == 'pull_request' + && github.event.pull_request.merged == true + && github.event.pull_request.head.repo.full_name == github.repository + && startsWith(github.event.pull_request.head.ref, 'release/v') + runs-on: ubuntu-latest + permissions: + contents: write + actions: write + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@v5 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + fetch-depth: 0 + - uses: astral-sh/setup-uv@v8.2.0 + - name: Read the version + id: version + env: + HEAD_REF: ${{ github.event.pull_request.head.ref }} + run: | + version=$(uv version --package timenet --short) + connectors=$(uv version --package timenet-connectors --short) + if [ "$version" != "$connectors" ] || [ "release/v$version" != "$HEAD_REF" ]; then + echo "::error title=Version mismatch::timenet $version, connectors $connectors, branch $HEAD_REF." + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + - name: Tag and create the GitHub release + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ steps.version.outputs.version }} + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git tag -a "v$VERSION" -m "TimeNet $VERSION" + uvx "$GIT_CLIFF" --latest --strip header --output "$RUNNER_TEMP/notes.md" + git push origin "v$VERSION" + gh release create "v$VERSION" --verify-tag --title "TimeNet $VERSION" --notes-file "$RUNNER_TEMP/notes.md" + - name: Start the PyPI publish run + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ steps.version.outputs.version }} + run: gh workflow run publish.yml --ref main -f target=PyPI -f package=both -f ref="v$VERSION" + + next-development-version: + needs: release + runs-on: ubuntu-latest + steps: + - id: app-token + uses: actions/create-github-app-token@v2 + with: + app-id: ${{ vars.RELEASE_APP_ID }} + private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + - uses: actions/checkout@v5 + with: + ref: ${{ github.event.pull_request.merge_commit_sha }} + token: ${{ steps.app-token.outputs.token }} + - uses: astral-sh/setup-uv@v8.2.0 + - name: Open the development version PR + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + run: | + for package in timenet timenet-connectors; do + uv version --package "$package" --bump minor --bump dev=0 --frozen + done + uv lock + next=$(uv version --package timenet --short) + branch="chore/start-${next%.dev0}-development" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git switch -c "$branch" + git commit -am "chore: start ${next%.dev0} development" + git push origin "$branch" + gh pr create --base main --head "$branch" --title "chore: start ${next%.dev0} development" \ + --body "Moves both packages to $next, so builds from main are not mistaken for the release." diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 000000000..a3df25099 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,52 @@ +# Release notes for TimeNet, generated from the Conventional Commit subjects that squash merges +# leave on main. Used by .github/workflows/release.yml. Preview the next release locally with: +# uvx git-cliff==2.14.2 --unreleased --bump --strip header + +[changelog] +header = "" +body = """ +{%- macro entry(commit) -%} +- {% if commit.breaking %}**Breaking:** {% endif %}\ +{% if commit.scope %}**{{ commit.scope }}:** {% endif %}\ +{{ commit.message | split(pat="\n") | first | trim | upper_first }} +{%- endmacro -%} +{% for group, commits in commits | group_by(attribute="group") %} +### {{ group | striptags | trim }} +{% for commit in commits | filter(attribute="breaking", value=true) %} +{{ self::entry(commit=commit) }} +{%- endfor %} +{%- for commit in commits %}{% if not commit.breaking %} +{{ self::entry(commit=commit) }} +{%- endif %}{% endfor %} +{% endfor %} +""" +footer = "" +trim = true + +[git] +conventional_commits = true +filter_unconventional = false +split_commits = false +# Only plain release tags count. This skips the registry-dev/... and backup/... tags. +tag_pattern = "^v[0-9]+\\.[0-9]+\\.[0-9]+$" +topo_order = false +sort_commits = "newest" +protect_breaking_commits = true +filter_commits = false +commit_parsers = [ + { message = "^Merge branch", skip = true }, + { message = "^chore\\(release\\)", skip = true }, + { message = "^chore: start .* development", skip = true }, + { message = "^feat[(!:]", group = "Features" }, + { message = "^fix[(!:]", group = "Bug fixes" }, + { message = "^perf[(!:]", group = "Performance" }, + { message = "^refactor[(!:]", group = "Refactoring" }, + { message = "^docs[(!:]", group = "Documentation" }, + { message = "^(build|ci|chore|test|style)[(!:]", group = "Maintenance" }, + { message = ".*", group = "Other" }, +] + +[bump] +# Pre-1.0: a breaking change bumps the minor version, a feature bumps the minor version too. +features_always_bump_minor = true +breaking_always_bump_major = false From 482abf8c6396a2ed1aefef129984707f05e3e43a Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 09:10:09 +0100 Subject: [PATCH 02/12] ci(release): make release steps re-runnable and publish only release tags to PyPI --- .github/workflows/publish.yml | 13 +++++++++-- .github/workflows/release.yml | 41 ++++++++++++++++++++++++++--------- cliff.toml | 1 - 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7bc52034b..8aff77951 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -54,7 +54,8 @@ jobs: - name: Checkout uses: actions/checkout@v5 with: - ref: ${{ inputs.ref || github.ref }} + # A tag, or the exact commit the run was started on, not the branch tip at approval time. + ref: ${{ inputs.ref || github.sha }} fetch-depth: 0 - name: Guard the release tag if: inputs.ref != '' @@ -69,7 +70,13 @@ jobs: uses: astral-sh/setup-uv@v7 - name: Guard PyPI to release versions if: inputs.target == 'PyPI' + env: + REF: ${{ inputs.ref }} run: | + if [ -z "$REF" ]; then + echo "::error title=No release tag::Publish to PyPI from a vX.Y.Z tag. Set the ref input." + exit 1 + fi for package in timenet timenet-connectors; do version=$(uv version --package "$package" --short) if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then @@ -95,6 +102,8 @@ jobs: set -euo pipefail shopt -s nullglob timenet_whl=(dist/timenet-*.whl) + # The checked-out commit: the release tag's commit, or GITHUB_SHA without a ref. + expected_sha=$(git rev-parse HEAD) smoke() { local module="$1" dist="$2"; shift 2 local args=() artifact @@ -106,7 +115,7 @@ jobs: from timenet.manifest import GitSource from timenet.provenance import PackageSnapshot commit = PackageSnapshot.read('$dist').source - expected = GitSource(sha='$GITHUB_SHA', contains_local_changes=False) + expected = GitSource(sha='$expected_sha', contains_local_changes=False) assert commit == expected, f'$dist records {commit}, expected {expected}' print('commit ok:', commit)" echo "::endgroup::" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index db9a42d06..19d23ca8e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,6 +6,9 @@ name: Release # the tag (which waits for approval in the pypi environment), and opens a PR that moves main # to the next development version, X.(Y+1).0.dev0. # 3. Approve the publish run, then merge the development-version PR. +# The version is fixed when the release PR opens. If main gets changes that need a bigger bump +# before you merge it, close the release PR and run this workflow again. +# Every job can be re-run: steps that already happened are skipped. # # Needs a GitHub App with contents and pull-requests write access, installed on this repository, # with its id in the RELEASE_APP_ID variable and its key in the RELEASE_APP_PRIVATE_KEY secret. @@ -88,7 +91,7 @@ jobs: git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git switch -c "$branch" git commit -am "chore(release): $VERSION" - git push origin "$branch" + git push --force origin "$branch" { echo "Merging this PR tags v$VERSION, creates the GitHub release with the notes below, and" echo "starts the PyPI publish run for approval. To change the notes, edit them in the" @@ -98,7 +101,11 @@ jobs: echo cat "$RUNNER_TEMP/notes.md" } > "$RUNNER_TEMP/body.md" - gh pr create --base main --head "$branch" --title "chore(release): $VERSION" --body-file "$RUNNER_TEMP/body.md" + if [ -n "$(gh pr list --head "$branch" --state open --json number --jq '.[].number')" ]; then + gh pr edit "$branch" --body-file "$RUNNER_TEMP/body.md" + else + gh pr create --base main --head "$branch" --title "chore(release): $VERSION" --body-file "$RUNNER_TEMP/body.md" + fi release: if: >- @@ -137,10 +144,21 @@ jobs: run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git tag -a "v$VERSION" -m "TimeNet $VERSION" - uvx "$GIT_CLIFF" --latest --strip header --output "$RUNNER_TEMP/notes.md" - git push origin "v$VERSION" - gh release create "v$VERSION" --verify-tag --title "TimeNet $VERSION" --notes-file "$RUNNER_TEMP/notes.md" + tag="v$VERSION" + if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then + # A re-run: the tag is already pushed. It must point at this release. + if [ "$(git rev-parse "$tag^{commit}")" != "$(git rev-parse HEAD)" ]; then + echo "::error title=Tag mismatch::$tag exists on another commit." + exit 1 + fi + else + git tag -a "$tag" -m "TimeNet $VERSION" + git push origin "$tag" + fi + if ! gh release view "$tag" >/dev/null 2>&1; then + uvx "$GIT_CLIFF" --latest --strip header --output "$RUNNER_TEMP/notes.md" + gh release create "$tag" --verify-tag --title "TimeNet $VERSION" --notes-file "$RUNNER_TEMP/notes.md" + fi - name: Start the PyPI publish run env: GH_TOKEN: ${{ github.token }} @@ -166,17 +184,20 @@ jobs: - name: Open the development version PR env: GH_TOKEN: ${{ steps.app-token.outputs.token }} + RELEASED: ${{ needs.release.outputs.version }} run: | for package in timenet timenet-connectors; do uv version --package "$package" --bump minor --bump dev=0 --frozen done uv lock next=$(uv version --package timenet --short) - branch="chore/start-${next%.dev0}-development" + branch="chore/start-development-after-v$RELEASED" git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git switch -c "$branch" git commit -am "chore: start ${next%.dev0} development" - git push origin "$branch" - gh pr create --base main --head "$branch" --title "chore: start ${next%.dev0} development" \ - --body "Moves both packages to $next, so builds from main are not mistaken for the release." + git push --force origin "$branch" + if [ -z "$(gh pr list --head "$branch" --state open --json number --jq '.[].number')" ]; then + gh pr create --base main --head "$branch" --title "chore: start ${next%.dev0} development" \ + --body "Moves both packages to $next, so builds from main are not mistaken for the $RELEASED release." + fi diff --git a/cliff.toml b/cliff.toml index a3df25099..9865c913c 100644 --- a/cliff.toml +++ b/cliff.toml @@ -34,7 +34,6 @@ sort_commits = "newest" protect_breaking_commits = true filter_commits = false commit_parsers = [ - { message = "^Merge branch", skip = true }, { message = "^chore\\(release\\)", skip = true }, { message = "^chore: start .* development", skip = true }, { message = "^feat[(!:]", group = "Features" }, From e0bdbbe53570c7df31a81b1b07c080e36da43f45 Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 10:48:25 +0100 Subject: [PATCH 03/12] ci(release): limit releases to admins and maintainers and publish to TestPyPI first --- .github/workflows/release.yml | 40 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 19d23ca8e..829f61b60 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,13 +2,16 @@ name: Release # Releases both packages in lockstep, in three steps: # 1. Run this workflow on main. It opens a release PR that sets the version and shows the notes. -# 2. Merge the release PR. This tags vX.Y.Z, creates the GitHub release, starts publish.yml for -# the tag (which waits for approval in the pypi environment), and opens a PR that moves main -# to the next development version, X.(Y+1).0.dev0. -# 3. Approve the publish run, then merge the development-version PR. +# 2. Merge the release PR. This tags vX.Y.Z, creates the GitHub release, starts a TestPyPI and +# a PyPI run of publish.yml for the tag (each waits for approval in the pypi environment), and +# opens a PR that moves main to the next development version, X.(Y+1).0.dev0. +# 3. Approve the TestPyPI run and check the result, approve the PyPI run, then merge the +# development-version PR. # The version is fixed when the release PR opens. If main gets changes that need a bigger bump # before you merge it, close the release PR and run this workflow again. # Every job can be re-run: steps that already happened are skipped. +# Only admins and maintainers can start a release, merge the release PR, or re-run a job. If +# someone else merges the release PR, nothing is tagged until an admin or maintainer re-runs it. # # Needs a GitHub App with contents and pull-requests write access, installed on this repository, # with its id in the RELEASE_APP_ID variable and its key in the RELEASE_APP_PRIVATE_KEY secret. @@ -32,7 +35,28 @@ env: GIT_CLIFF: git-cliff==2.14.2 jobs: + authorize: + if: >- + github.event_name == 'workflow_dispatch' + || (github.event.pull_request.merged == true + && github.event.pull_request.head.repo.full_name == github.repository + && startsWith(github.event.pull_request.head.ref, 'release/v')) + runs-on: ubuntu-latest + steps: + - name: Allow only admins and maintainers + env: + GH_TOKEN: ${{ github.token }} + # The user who started the run, merged the release PR, or re-ran a job. + ACTOR: ${{ github.triggering_actor }} + run: | + role=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$ACTOR/permission" --jq .role_name) + if [ "$role" != admin ] && [ "$role" != maintain ]; then + echo "::error title=Not allowed::$ACTOR has the $role role. Only admins and maintainers can release." + exit 1 + fi + prepare: + needs: authorize if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest steps: @@ -108,6 +132,7 @@ jobs: fi release: + needs: authorize if: >- github.event_name == 'pull_request' && github.event.pull_request.merged == true @@ -159,11 +184,14 @@ jobs: uvx "$GIT_CLIFF" --latest --strip header --output "$RUNNER_TEMP/notes.md" gh release create "$tag" --verify-tag --title "TimeNet $VERSION" --notes-file "$RUNNER_TEMP/notes.md" fi - - name: Start the PyPI publish run + - name: Start the TestPyPI and PyPI publish runs env: GH_TOKEN: ${{ github.token }} VERSION: ${{ steps.version.outputs.version }} - run: gh workflow run publish.yml --ref main -f target=PyPI -f package=both -f ref="v$VERSION" + run: | + for target in TestPyPI PyPI; do + gh workflow run publish.yml --ref main -f target="$target" -f package=both -f ref="v$VERSION" + done next-development-version: needs: release From fe380d8d38bba9978ca0a0a1d76d65e5ba2bab06 Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:40:20 +0100 Subject: [PATCH 04/12] ci(release): pin gh to the repository the workflow runs in --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 829f61b60..aa1617011 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,7 @@ permissions: env: GIT_CLIFF: git-cliff==2.14.2 + GH_REPO: ${{ github.repository }} jobs: authorize: From 19ca8789070c3d6946ac328f421690f5668e89d6 Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:47:50 +0100 Subject: [PATCH 05/12] ci(release): mention the TestPyPI run in the release PR body --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index aa1617011..3910d9421 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -119,8 +119,8 @@ jobs: git push --force origin "$branch" { echo "Merging this PR tags v$VERSION, creates the GitHub release with the notes below, and" - echo "starts the PyPI publish run for approval. To change the notes, edit them in the" - echo "GitHub release after it is created." + echo "starts the TestPyPI and PyPI publish runs for approval. To change the notes, edit" + echo "them in the GitHub release after it is created." echo echo "---" echo From cf02c97bc7ff8349de585bba26e2b626840985eb Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:49:42 +0100 Subject: [PATCH 06/12] ci(release): link PRs and show PyPI badges in the release notes --- cliff.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cliff.toml b/cliff.toml index 9865c913c..1b84486ee 100644 --- a/cliff.toml +++ b/cliff.toml @@ -10,6 +10,10 @@ body = """ {% if commit.scope %}**{{ commit.scope }}:** {% endif %}\ {{ commit.message | split(pat="\n") | first | trim | upper_first }} {%- endmacro -%} +{% if version %}{% set v = version | trim_start_matches(pat="v") %} +[![timenet {{ v }}](https://img.shields.io/badge/timenet-{{ v }}-blue?logo=pypi&logoColor=white)](https://pypi.org/project/timenet/{{ v }}/) \ +[![timenet-connectors {{ v }}](https://img.shields.io/badge/timenet--connectors-{{ v }}-blue?logo=pypi&logoColor=white)](https://pypi.org/project/timenet-connectors/{{ v }}/) +{% endif %} {% for group, commits in commits | group_by(attribute="group") %} ### {{ group | striptags | trim }} {% for commit in commits | filter(attribute="breaking", value=true) %} @@ -33,6 +37,10 @@ topo_order = false sort_commits = "newest" protect_breaking_commits = true filter_commits = false +# Link PR numbers explicitly, so they also work outside this repository's GitHub pages. +commit_preprocessors = [ + { pattern = '\(#([0-9]+)\)', replace = "([#${1}](https://github.com/OpenTSLM/TimeNet/pull/${1}))" }, +] commit_parsers = [ { message = "^chore\\(release\\)", skip = true }, { message = "^chore: start .* development", skip = true }, From a2369ad3a60537a5a844dbf18f2f7200c0885e37 Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:10:58 +0100 Subject: [PATCH 07/12] ci(release): version and release timenet and timenet-connectors independently --- .github/workflows/publish.yml | 26 ++-- .github/workflows/release.yml | 237 +++++++++++++++++++++++----------- cliff.toml | 16 ++- 3 files changed, 187 insertions(+), 92 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8aff77951..57fc07568 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -21,7 +21,7 @@ on: - timenet - timenet-connectors ref: - description: Release tag to build, for example v0.12.0. Leave empty to build the branch above. + description: Release tag to build, for example timenet-v0.12.0. Leave empty to build the branch above. required: false type: string @@ -62,25 +62,31 @@ jobs: env: REF: ${{ inputs.ref }} run: | - if ! [[ "$REF" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || ! git merge-base --is-ancestor HEAD origin/main; then - echo "::error title=Invalid ref::Build only a vX.Y.Z tag on main, not '$REF'." + if ! [[ "$REF" =~ ^(timenet|timenet-connectors)-v[0-9]+\.[0-9]+\.[0-9]+$ ]] || ! git merge-base --is-ancestor HEAD origin/main; then + echo "::error title=Invalid ref::Build only a -vX.Y.Z tag on main, not '$REF'." exit 1 fi - name: Set up uv uses: astral-sh/setup-uv@v7 - - name: Guard PyPI to release versions - if: inputs.target == 'PyPI' + - name: Guard the release versions env: REF: ${{ inputs.ref }} + TARGET: ${{ inputs.target }} + PACKAGE: ${{ inputs.package }} run: | if [ -z "$REF" ]; then - echo "::error title=No release tag::Publish to PyPI from a vX.Y.Z tag. Set the ref input." - exit 1 + if [ "$TARGET" = PyPI ]; then + echo "::error title=No release tag::Publish to PyPI from a -vX.Y.Z tag. Set the ref input." + exit 1 + fi + exit 0 fi - for package in timenet timenet-connectors; do + if [ "$PACKAGE" = both ]; then packages="timenet timenet-connectors"; else packages=$PACKAGE; fi + for package in $packages; do version=$(uv version --package "$package" --short) - if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "::error title=Development version::$package is at $version. Publish a release tag instead." + tag="$package-v$version" + if [ "$(git rev-parse -q --verify "refs/tags/$tag^{commit}")" != "$(git rev-parse HEAD)" ]; then + echo "::error title=Not released::$package is at $version, but $tag does not point at this commit. Release it first." exit 1 fi done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3910d9421..9a09bca04 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,12 +1,18 @@ name: Release -# Releases both packages in lockstep, in three steps: -# 1. Run this workflow on main. It opens a release PR that sets the version and shows the notes. -# 2. Merge the release PR. This tags vX.Y.Z, creates the GitHub release, starts a TestPyPI and -# a PyPI run of publish.yml for the tag (each waits for approval in the pypi environment), and -# opens a PR that moves main to the next development version, X.(Y+1).0.dev0. +# Releases timenet, timenet-connectors, or both. Each package has its own version and its own tag, +# -vX.Y.Z, and its notes list the commits that touched its folder under packages/. +# 1. Run this workflow on main and pick the package. It opens a release PR that sets the version +# and shows the notes. +# 2. Merge the release PR. For every package whose version the PR changed, this tags +# -vX.Y.Z and creates a GitHub release. It starts a TestPyPI and a PyPI run of +# publish.yml (each waits for approval in the pypi environment), and opens a PR that moves the +# released packages to their next development version, X.(Y+1).0.dev0. # 3. Approve the TestPyPI run and check the result, approve the PyPI run, then merge the # development-version PR. +# Releasing both raises the timenet floor of timenet-connectors to the new timenet version. +# Releasing one package alone keeps the floor. The release PR warns when the other package has +# changes that the release leaves out. # The version is fixed when the release PR opens. If main gets changes that need a bigger bump # before you merge it, close the release PR and run this workflow again. # Every job can be re-run: steps that already happened are skipped. @@ -20,6 +26,15 @@ name: Release on: workflow_dispatch: inputs: + package: + description: Package to release + required: true + default: both + type: choice + options: + - both + - timenet + - timenet-connectors version: description: Version to release, for example 0.12.0. Leave empty to compute it from the commits. required: false @@ -41,7 +56,7 @@ jobs: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository - && startsWith(github.event.pull_request.head.ref, 'release/v')) + && startsWith(github.event.pull_request.head.ref, 'release/timenet')) runs-on: ubuntu-latest steps: - name: Allow only admins and maintainers @@ -78,58 +93,97 @@ jobs: fetch-depth: 0 token: ${{ steps.app-token.outputs.token }} - uses: astral-sh/setup-uv@v8.2.0 - - name: Choose the version - id: version + - name: Set the versions and write the notes + id: versions env: + PACKAGE: ${{ inputs.package }} REQUESTED: ${{ inputs.version }} run: | - version=${REQUESTED:-$(uvx "$GIT_CLIFF" --bumped-version)} - version=${version#v} - if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "::error title=Invalid version::'$version' is not X.Y.Z." - exit 1 - fi - if git rev-parse -q --verify "refs/tags/v$version" >/dev/null; then - echo "::error title=Version exists::Tag v$version already exists." - exit 1 - fi - echo "version=$version" >> "$GITHUB_OUTPUT" - - name: Set the version and write the notes - env: - VERSION: ${{ steps.version.outputs.version }} - run: | - for package in timenet timenet-connectors; do - uv version --package "$package" "$VERSION" --frozen + # The legacy vX.Y.Z tags count as the last release of both packages. + cliff() { + local package=$1; shift + uvx "$GIT_CLIFF" --include-path "packages/$package/**" \ + --tag-pattern "^($package-)?v[0-9]+\.[0-9]+\.[0-9]+$" "$@" + } + if [ "$PACKAGE" = both ]; then packages="timenet timenet-connectors"; else packages=$PACKAGE; fi + titles=() tags=() + : > "$RUNNER_TEMP/notes.md" + for package in $packages; do + version=${REQUESTED:-$(cliff "$package" --bumped-version)} + version=${version##*v} + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error title=Invalid version::'$version' is not X.Y.Z." + exit 1 + fi + for tag in "$package-v$version" "v$version"; do + if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then + echo "::error title=Version exists::Tag $tag already exists. Is $package unchanged since then?" + exit 1 + fi + done + uv version --package "$package" "$version" --frozen + { + echo "## $package $version" + echo + cliff "$package" --unreleased --tag "$package-v$version" --strip header + echo + } >> "$RUNNER_TEMP/notes.md" + titles+=("$package $version") + tags+=("$package-v$version") done - # Connectors needs the timenet release that ships with it. - sed -i -E "s/\"timenet\[build\]>=[^\"]*\"/\"timenet[build]>=$VERSION\"/" packages/timenet-connectors/pyproject.toml - grep -q "\"timenet\[build\]>=$VERSION\"" packages/timenet-connectors/pyproject.toml + connectors=packages/timenet-connectors/pyproject.toml + if [ "$PACKAGE" = both ]; then + # Connectors needs the timenet release that ships with it. + timenet=$(uv version --package timenet --short) + sed -i -E "s/\"timenet\[build\]>=[^\"]*\"/\"timenet[build]>=$timenet\"/" "$connectors" + grep -q "\"timenet\[build\]>=$timenet\"" "$connectors" + else + # Warn when the other package has changes this release leaves out. Skip the commits + # cliff.toml skips too: release and development-version commits. + if [ "$PACKAGE" = timenet ]; then other=timenet-connectors; else other=timenet; fi + last=$(git describe --tags --abbrev=0 --match "$other-v*" --match 'v*') + unreleased=$(git log --format=%s "$last..HEAD" -- "packages/$other" \ + | grep -cvE '^chore(\(release\)|: start .* development)' || true) + if [ "$unreleased" -gt 0 ]; then + floor=$(grep -o '"timenet\[build\]>=[^"]*"' "$connectors") + { + echo "> [!WARNING]" + echo "> $other has $unreleased commits since $last that this release leaves out, and" + echo "> timenet-connectors keeps $floor. If those commits go with the $PACKAGE changes," + echo "> release both instead." + echo + } >> "$RUNNER_TEMP/notes.md" + fi + fi uv lock - uvx "$GIT_CLIFF" --unreleased --tag "v$VERSION" --strip header --output "$RUNNER_TEMP/notes.md" + title="chore(release): $(IFS=,; echo "${titles[*]}" | sed 's/,/, /g')" + branch="release/$(IFS=-; echo "${tags[*]}")" + echo "title=$title" >> "$GITHUB_OUTPUT" + echo "branch=$branch" >> "$GITHUB_OUTPUT" - name: Open the release PR env: GH_TOKEN: ${{ steps.app-token.outputs.token }} - VERSION: ${{ steps.version.outputs.version }} + TITLE: ${{ steps.versions.outputs.title }} + BRANCH: ${{ steps.versions.outputs.branch }} run: | - branch="release/v$VERSION" git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git switch -c "$branch" - git commit -am "chore(release): $VERSION" - git push --force origin "$branch" + git switch -c "$BRANCH" + git commit -am "$TITLE" + git push --force origin "$BRANCH" { - echo "Merging this PR tags v$VERSION, creates the GitHub release with the notes below, and" - echo "starts the TestPyPI and PyPI publish runs for approval. To change the notes, edit" + echo "Merging this PR tags each package below, creates its GitHub release with these notes," + echo "and starts the TestPyPI and PyPI publish runs for approval. To change the notes, edit" echo "them in the GitHub release after it is created." echo echo "---" echo cat "$RUNNER_TEMP/notes.md" } > "$RUNNER_TEMP/body.md" - if [ -n "$(gh pr list --head "$branch" --state open --json number --jq '.[].number')" ]; then - gh pr edit "$branch" --body-file "$RUNNER_TEMP/body.md" + if [ -n "$(gh pr list --head "$BRANCH" --state open --json number --jq '.[].number')" ]; then + gh pr edit "$BRANCH" --body-file "$RUNNER_TEMP/body.md" else - gh pr create --base main --head "$branch" --title "chore(release): $VERSION" --body-file "$RUNNER_TEMP/body.md" + gh pr create --base main --head "$BRANCH" --title "$TITLE" --body-file "$RUNNER_TEMP/body.md" fi release: @@ -138,60 +192,88 @@ jobs: github.event_name == 'pull_request' && github.event.pull_request.merged == true && github.event.pull_request.head.repo.full_name == github.repository - && startsWith(github.event.pull_request.head.ref, 'release/v') + && startsWith(github.event.pull_request.head.ref, 'release/timenet') runs-on: ubuntu-latest permissions: contents: write actions: write outputs: - version: ${{ steps.version.outputs.version }} + released: ${{ steps.released.outputs.released }} steps: - uses: actions/checkout@v5 with: ref: ${{ github.event.pull_request.merge_commit_sha }} fetch-depth: 0 - uses: astral-sh/setup-uv@v8.2.0 - - name: Read the version - id: version - env: - HEAD_REF: ${{ github.event.pull_request.head.ref }} + - name: Find the packages this PR released + id: released run: | - version=$(uv version --package timenet --short) - connectors=$(uv version --package timenet-connectors --short) - if [ "$version" != "$connectors" ] || [ "release/v$version" != "$HEAD_REF" ]; then - echo "::error title=Version mismatch::timenet $version, connectors $connectors, branch $HEAD_REF." + released=() + for package in timenet timenet-connectors; do + version=$(uv version --package "$package" --short) + before=$(git show "HEAD^:packages/$package/pyproject.toml" | sed -n -E 's/^version = "(.*)"$/\1/p') + if [ "$version" = "$before" ]; then continue; fi + if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error title=Invalid version::$package is at $version, not X.Y.Z." + exit 1 + fi + released+=("$package=$version") + done + if [ ${#released[@]} -eq 0 ]; then + echo "::error title=Nothing to release::This PR changed no package version." exit 1 fi - echo "version=$version" >> "$GITHUB_OUTPUT" - - name: Tag and create the GitHub release + echo "released=${released[*]}" >> "$GITHUB_OUTPUT" + - name: Tag and create the GitHub releases env: GH_TOKEN: ${{ github.token }} - VERSION: ${{ steps.version.outputs.version }} + RELEASED: ${{ steps.released.outputs.released }} run: | + cliff() { + local package=$1; shift + uvx "$GIT_CLIFF" --include-path "packages/$package/**" \ + --tag-pattern "^($package-)?v[0-9]+\.[0-9]+\.[0-9]+$" "$@" + } git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - tag="v$VERSION" - if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then - # A re-run: the tag is already pushed. It must point at this release. - if [ "$(git rev-parse "$tag^{commit}")" != "$(git rev-parse HEAD)" ]; then - echo "::error title=Tag mismatch::$tag exists on another commit." - exit 1 + for entry in $RELEASED; do + package=${entry%=*} version=${entry#*=} + tag="$package-v$version" + if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then + # A re-run: the tag is already pushed. It must point at this release. + if [ "$(git rev-parse "$tag^{commit}")" != "$(git rev-parse HEAD)" ]; then + echo "::error title=Tag mismatch::$tag exists on another commit." + exit 1 + fi + else + git tag -a "$tag" -m "$package $version" + git push origin "$tag" fi - else - git tag -a "$tag" -m "TimeNet $VERSION" - git push origin "$tag" - fi - if ! gh release view "$tag" >/dev/null 2>&1; then - uvx "$GIT_CLIFF" --latest --strip header --output "$RUNNER_TEMP/notes.md" - gh release create "$tag" --verify-tag --title "TimeNet $VERSION" --notes-file "$RUNNER_TEMP/notes.md" - fi + if ! gh release view "$tag" >/dev/null 2>&1; then + cliff "$package" --latest --strip header --output "$RUNNER_TEMP/notes.md" + gh release create "$tag" --verify-tag --title "$package $version" --notes-file "$RUNNER_TEMP/notes.md" + fi + done - name: Start the TestPyPI and PyPI publish runs env: GH_TOKEN: ${{ github.token }} - VERSION: ${{ steps.version.outputs.version }} + RELEASED: ${{ steps.released.outputs.released }} run: | + read -r -a released <<< "$RELEASED" + first=${released[0]} + package=${first%=*} + if [ ${#released[@]} -eq 2 ]; then package=both; fi + # Both tags of a release point at the same commit, so either one builds both packages. + ref="${first%=*}-v${first#*=}" for target in TestPyPI PyPI; do - gh workflow run publish.yml --ref main -f target="$target" -f package=both -f ref="v$VERSION" + # A re-run: skip a publish run this job already started. Its name comes from publish.yml's run-name. + name="Publish $package $ref to $target" + if gh run list --workflow publish.yml --event workflow_dispatch --limit 100 --json displayTitle \ + --jq '.[].displayTitle' | grep -qxF "$name"; then + echo "Skipping '$name': it was already started." + continue + fi + gh workflow run publish.yml --ref main -f target="$target" -f package="$package" -f ref="$ref" done next-development-version: @@ -213,20 +295,25 @@ jobs: - name: Open the development version PR env: GH_TOKEN: ${{ steps.app-token.outputs.token }} - RELEASED: ${{ needs.release.outputs.version }} + RELEASED: ${{ needs.release.outputs.released }} + HEAD_REF: ${{ github.event.pull_request.head.ref }} run: | - for package in timenet timenet-connectors; do + names=() + for entry in $RELEASED; do + package=${entry%=*} uv version --package "$package" --bump minor --bump dev=0 --frozen + next=$(uv version --package "$package" --short) + names+=("$package ${next%.dev0}") done uv lock - next=$(uv version --package timenet --short) - branch="chore/start-development-after-v$RELEASED" + title="chore: start $(IFS=,; echo "${names[*]}" | sed 's/,/ and /g') development" + branch="chore/start-development-after-${HEAD_REF#release/}" git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git switch -c "$branch" - git commit -am "chore: start ${next%.dev0} development" + git commit -am "$title" git push --force origin "$branch" if [ -z "$(gh pr list --head "$branch" --state open --json number --jq '.[].number')" ]; then - gh pr create --base main --head "$branch" --title "chore: start ${next%.dev0} development" \ - --body "Moves both packages to $next, so builds from main are not mistaken for the $RELEASED release." + gh pr create --base main --head "$branch" --title "$title" \ + --body "Moves the released packages to their next development version ($RELEASED released), so builds from main are not mistaken for a release." fi diff --git a/cliff.toml b/cliff.toml index 1b84486ee..eb357ff1f 100644 --- a/cliff.toml +++ b/cliff.toml @@ -1,6 +1,8 @@ # Release notes for TimeNet, generated from the Conventional Commit subjects that squash merges -# leave on main. Used by .github/workflows/release.yml. Preview the next release locally with: -# uvx git-cliff==2.14.2 --unreleased --bump --strip header +# leave on main. Used by .github/workflows/release.yml, once per package. Preview the next timenet +# release locally with (use timenet-connectors for the other package): +# uvx git-cliff==2.14.2 --include-path 'packages/timenet/**' \ +# --tag-pattern '^(timenet-)?v[0-9]+\.[0-9]+\.[0-9]+$' --unreleased --bump --strip header [changelog] header = "" @@ -10,9 +12,8 @@ body = """ {% if commit.scope %}**{{ commit.scope }}:** {% endif %}\ {{ commit.message | split(pat="\n") | first | trim | upper_first }} {%- endmacro -%} -{% if version %}{% set v = version | trim_start_matches(pat="v") %} -[![timenet {{ v }}](https://img.shields.io/badge/timenet-{{ v }}-blue?logo=pypi&logoColor=white)](https://pypi.org/project/timenet/{{ v }}/) \ -[![timenet-connectors {{ v }}](https://img.shields.io/badge/timenet--connectors-{{ v }}-blue?logo=pypi&logoColor=white)](https://pypi.org/project/timenet-connectors/{{ v }}/) +{% if version and version is containing("-v") %}{% set package = version | split(pat="-v") | first %}{% set v = version | split(pat="-v") | last %} +[![{{ package }} {{ v }}](https://img.shields.io/badge/{{ package | replace(from="-", to="--") }}-{{ v }}-blue?logo=pypi&logoColor=white)](https://pypi.org/project/{{ package }}/{{ v }}/) {% endif %} {% for group, commits in commits | group_by(attribute="group") %} ### {{ group | striptags | trim }} @@ -31,8 +32,9 @@ trim = true conventional_commits = true filter_unconventional = false split_commits = false -# Only plain release tags count. This skips the registry-dev/... and backup/... tags. -tag_pattern = "^v[0-9]+\\.[0-9]+\\.[0-9]+$" +# Only release tags count. This skips the registry-dev/... and backup/... tags. release.yml narrows +# it to one package with --tag-pattern; the legacy vX.Y.Z tags count for both packages. +tag_pattern = "^((timenet|timenet-connectors)-)?v[0-9]+\\.[0-9]+\\.[0-9]+$" topo_order = false sort_commits = "newest" protect_breaking_commits = true From d8e9435e38e3202724fcb4659bf9f13a88899709 Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:22:02 +0100 Subject: [PATCH 08/12] ci(release): name the timenet version variable after what it holds --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9a09bca04..87deea734 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -134,9 +134,9 @@ jobs: connectors=packages/timenet-connectors/pyproject.toml if [ "$PACKAGE" = both ]; then # Connectors needs the timenet release that ships with it. - timenet=$(uv version --package timenet --short) - sed -i -E "s/\"timenet\[build\]>=[^\"]*\"/\"timenet[build]>=$timenet\"/" "$connectors" - grep -q "\"timenet\[build\]>=$timenet\"" "$connectors" + timenet_version=$(uv version --package timenet --short) + sed -i -E "s/\"timenet\[build\]>=[^\"]*\"/\"timenet[build]>=$timenet_version\"/" "$connectors" + grep -q "\"timenet\[build\]>=$timenet_version\"" "$connectors" else # Warn when the other package has changes this release leaves out. Skip the commits # cliff.toml skips too: release and development-version commits. From 7bc69dc809c7c81917a8ace3fdc521a3cbcc2c5e Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:01:25 +0100 Subject: [PATCH 09/12] ci(release): list added, changed and removed connectors in the timenet-connectors notes --- .github/scripts/connector_notes.py | 175 +++++++++++++++++++++++++++++ .github/workflows/release.yml | 19 +++- 2 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/connector_notes.py diff --git a/.github/scripts/connector_notes.py b/.github/scripts/connector_notes.py new file mode 100644 index 000000000..83493c3fd --- /dev/null +++ b/.github/scripts/connector_notes.py @@ -0,0 +1,175 @@ +# /// script +# requires-python = ">=3.11" +# /// +"""Print the release notes of timenet-connectors between two refs. + +The notes list the connectors that were added, changed or removed, and the changes to the shared +connector code (the "framework"). Core changes that only touched connector files on the way are +left out; the timenet notes list them. + +- A connector is a ``datasets///`` folder with a ``dataset.yaml`` card, the rule that + ``scripts/gen_dataset_docs.py`` uses. Connectors are matched by the card's ``dataset_id``, so a + moved folder that keeps its id is changed, and a new id is one removal and one addition. +- An added connector cites the PR that added it, a removed one the PR that removed it. A changed + connector cites its connector PRs, and is left out when it has none. +- The framework section lists the connector PRs outside ``datasets/``, breaking ones first. +- A connector PR is a ``feat``, a ``fix`` or a breaking change that did not touch + ``packages/timenet``. A core PR edits connectors on the way, and the timenet notes list it. + +Called by .github/workflows/release.yml. Run it the way the workflow does:: + + uv run --no-project .github/scripts/connector_notes.py v0.11.0 HEAD \ + --release timenet-connectors-v0.12.0 +""" + +import argparse +import re +import shutil +import subprocess # ruff: ignore[suspicious-subprocess-import] - fixed argument vectors, never a shell string + + +PACKAGE = "packages/timenet-connectors" +DATASETS = f"{PACKAGE}/src/timenet_connectors/datasets" +PR_URL = "https://github.com/OpenTSLM/TimeNet/pull/" +# A squash-merged PR title: type(scope)!: description (#123). +SUBJECT = re.compile(r"^(?P\w+)(?:\((?P[^)]*)\))?(?P!)?: (?P.+?)(?: \(#(?P\d+)\))?$") +# The commits cliff.toml skips: release and development-version commits. +SKIP = re.compile(r"^chore(\(release\)|: start .* development)") + + +def git(*args: str) -> str: + """Run git and return its output. + + Returns: + The standard output. + """ + command = [shutil.which("git") or "git", *args] + return subprocess.run(command, check=True, capture_output=True, text=True).stdout # ruff: ignore[subprocess-without-shell-equals-true] + + +def commits(base: str, head: str, *paths: str) -> list[tuple[str, str]]: + """List the commits between ``base`` and ``head`` that touched ``paths``, oldest first. + + Returns: + ``(short hash, subject)`` pairs, without release and development-version commits. + """ + lines = git("log", "--reverse", "--format=%h %s", f"{base}..{head}", "--", *paths).splitlines() + pairs = [line.split(" ", 1) for line in lines] + return [(sha, subject) for sha, subject in pairs if not SKIP.match(subject)] + + +def notable(subject: str) -> bool: + """Return whether a commit is a feature, a fix or a breaking change.""" + match = SUBJECT.match(subject) + return bool(match) and (match["type"] in {"feat", "fix"} or bool(match["bang"])) + + +def link(sha: str, subject: str) -> str: + """Link the PR of a commit, or name the commit when it has no PR number. + + Returns: + A markdown link, or the short hash. + """ + number = re.search(r"\(#(\d+)\)$", subject) + return f"[#{number[1]}]({PR_URL}{number[1]})" if number else sha + + +def connectors(ref: str) -> dict[str, tuple[str, str]]: + """Map each dataset id at ``ref`` to its folder and display name. + + Returns: + ``{dataset_id: (folder, name)}``. + """ + found = {} + for card in git("ls-tree", "-r", "--name-only", ref, "--", DATASETS).splitlines(): + if not re.fullmatch(re.escape(DATASETS) + r"/[^/]+/[^/]+/dataset\.yaml", card): + continue + text = git("show", f"{ref}:{card}") + folder = card.rsplit("/", 1)[0] + dataset_id = re.search(r"^dataset_id:\s*(\S+)", text, re.M) + name = re.search(r"^name:\s*(.+)$", text, re.M) + key = dataset_id[1] if dataset_id else "/".join(folder.split("/")[-2:]) + found[key] = (folder, name[1].strip() if name else key) + return found + + +def connector_sections(base: str, head: str, core: set[str]) -> tuple[dict[str, list[str]], set[str]]: + """List the connectors that were added, changed or removed. + + Returns: + The entries of each section, and the commits that added a connector. + """ + old, new = connectors(base), connectors(head) + sections: dict[str, list[str]] = {"Added connectors": [], "Changed connectors": [], "Removed connectors": []} + added: set[str] = set() + for dataset_id in sorted(old.keys() | new.keys()): + folders = sorted({entry[0] for entry in (old.get(dataset_id), new.get(dataset_id)) if entry}) + touched = commits(base, head, *folders) + if dataset_id not in old: + section, cited = "Added connectors", touched[:1] + added.update(sha for sha, _ in cited) + elif dataset_id not in new: + section, cited = "Removed connectors", touched[-1:] + else: + section, cited = "Changed connectors", [c for c in touched if c[0] not in core and notable(c[1])] + if cited: + name = (new.get(dataset_id) or old[dataset_id])[1] + links = ", ".join(dict.fromkeys(link(*c) for c in cited)) + sections[section].append(f"- {name} (`{dataset_id}`): {links}") + return sections, added + + +def framework_entries(base: str, head: str, skip: set[str]) -> list[str]: + """List the connector PRs outside ``datasets/``, breaking ones first. + + Returns: + The entries, without the commits in ``skip``. + """ + entries = [] + for sha, subject in commits(base, head, PACKAGE, f":(exclude){DATASETS}"): + match = SUBJECT.match(subject) + if match and sha not in skip and notable(subject): + breaking = "**Breaking:** " if match["bang"] else "" + scope = f"**{match['scope']}:** " if match["scope"] else "" + text = match["text"][:1].upper() + match["text"][1:] + entries.append((not match["bang"], f"- {breaking}{scope}{text} ({link(sha, subject)})")) + return [entry for _, entry in sorted(entries, key=lambda pair: pair[0])] + + +def notes(base: str, head: str) -> str: + """Render the notes as markdown. + + Returns: + The markdown, or an empty string when nothing in the package changed. + """ + core = {sha for sha, _ in commits(base, head, "packages/timenet")} + sections, added = connector_sections(base, head, core) + sections["Connector framework"] = framework_entries(base, head, core | added) + out = [] + for title, entries in sections.items(): + if entries: + out += [f"### {title}", "", *entries, ""] + return "\n".join(out) + + +def badge(release: str) -> str: + """Render the PyPI badge of a ``-vX.Y.Z`` tag, like the one cliff.toml writes. + + Returns: + The markdown badge and a blank line. + """ + package, version = release.rsplit("-v", 1) + label = package.replace("-", "--") + image = f"https://img.shields.io/badge/{label}-{version}-blue?logo=pypi&logoColor=white" + return f"[![{package} {version}]({image})](https://pypi.org/project/{package}/{version}/)\n\n" + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) + parser.add_argument("base", help="the last release tag") + parser.add_argument("head", help="the commit to release") + parser.add_argument( + "--release", help="the release tag, for example timenet-connectors-v0.12.0, to add a PyPI badge" + ) + args = parser.parse_args() + print((badge(args.release) if args.release else "") + notes(args.base, args.head), end="") diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 87deea734..f0ef133ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,9 @@ name: Release # Releases timenet, timenet-connectors, or both. Each package has its own version and its own tag, -# -vX.Y.Z, and its notes list the commits that touched its folder under packages/. +# -vX.Y.Z. The timenet notes list the commits that touched packages/timenet. The +# timenet-connectors notes list the connectors added, changed or removed, and the changes to the +# shared connector code (.github/scripts/connector_notes.py). # 1. Run this workflow on main and pick the package. It opens a release PR that sets the version # and shows the notes. # 2. Merge the release PR. For every package whose version the PR changed, this tags @@ -125,7 +127,12 @@ jobs: { echo "## $package $version" echo - cliff "$package" --unreleased --tag "$package-v$version" --strip header + if [ "$package" = timenet-connectors ]; then + last=$(git describe --tags --abbrev=0 --match "$package-v*" --match 'v*') + uv run --no-project .github/scripts/connector_notes.py "$last" HEAD --release "$package-v$version" + else + cliff "$package" --unreleased --tag "$package-v$version" --strip header + fi echo } >> "$RUNNER_TEMP/notes.md" titles+=("$package $version") @@ -250,7 +257,13 @@ jobs: git push origin "$tag" fi if ! gh release view "$tag" >/dev/null 2>&1; then - cliff "$package" --latest --strip header --output "$RUNNER_TEMP/notes.md" + if [ "$package" = timenet-connectors ]; then + # The new tag is on HEAD, so the last release is the newest tag before it. + last=$(git describe --tags --abbrev=0 --match "$package-v*" --match 'v*' HEAD^) + uv run --no-project .github/scripts/connector_notes.py "$last" HEAD --release "$tag" > "$RUNNER_TEMP/notes.md" + else + cliff "$package" --latest --strip header --output "$RUNNER_TEMP/notes.md" + fi gh release create "$tag" --verify-tag --title "$package $version" --notes-file "$RUNNER_TEMP/notes.md" fi done From 1841a6c9033b5a4adcc131f54cb41a2db802d298 Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:25:51 +0100 Subject: [PATCH 10/12] ci(release): read the connector history with GitPython --- .github/scripts/connector_notes.py | 37 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/scripts/connector_notes.py b/.github/scripts/connector_notes.py index 83493c3fd..3a8954916 100644 --- a/.github/scripts/connector_notes.py +++ b/.github/scripts/connector_notes.py @@ -1,5 +1,9 @@ # /// script # requires-python = ">=3.11" +# dependencies = ["GitPython>=3.1"] +# +# [tool.ty.rules] +# unresolved-import = "ignore" # /// """Print the release notes of timenet-connectors between two refs. @@ -24,8 +28,8 @@ import argparse import re -import shutil -import subprocess # ruff: ignore[suspicious-subprocess-import] - fixed argument vectors, never a shell string + +from git import Repo PACKAGE = "packages/timenet-connectors" @@ -37,14 +41,13 @@ SKIP = re.compile(r"^chore(\(release\)|: start .* development)") -def git(*args: str) -> str: - """Run git and return its output. +def repo() -> Repo: + """Open the repository around the current directory. Returns: - The standard output. + The repository. """ - command = [shutil.which("git") or "git", *args] - return subprocess.run(command, check=True, capture_output=True, text=True).stdout # ruff: ignore[subprocess-without-shell-equals-true] + return Repo(search_parent_directories=True) def commits(base: str, head: str, *paths: str) -> list[tuple[str, str]]: @@ -53,8 +56,8 @@ def commits(base: str, head: str, *paths: str) -> list[tuple[str, str]]: Returns: ``(short hash, subject)`` pairs, without release and development-version commits. """ - lines = git("log", "--reverse", "--format=%h %s", f"{base}..{head}", "--", *paths).splitlines() - pairs = [line.split(" ", 1) for line in lines] + found = repo().iter_commits(f"{base}..{head}", paths=list(paths), reverse=True) + pairs = [(commit.hexsha[:9], str(commit.summary)) for commit in found] return [(sha, subject) for sha, subject in pairs if not SKIP.match(subject)] @@ -81,15 +84,19 @@ def connectors(ref: str) -> dict[str, tuple[str, str]]: ``{dataset_id: (folder, name)}``. """ found = {} - for card in git("ls-tree", "-r", "--name-only", ref, "--", DATASETS).splitlines(): - if not re.fullmatch(re.escape(DATASETS) + r"/[^/]+/[^/]+/dataset\.yaml", card): + try: + datasets = repo().commit(ref).tree / DATASETS + except KeyError: + return found + for folder in (folder for org in datasets.trees for folder in org.trees): + try: + text = (folder / "dataset.yaml").data_stream.read().decode() + except KeyError: continue - text = git("show", f"{ref}:{card}") - folder = card.rsplit("/", 1)[0] dataset_id = re.search(r"^dataset_id:\s*(\S+)", text, re.M) name = re.search(r"^name:\s*(.+)$", text, re.M) - key = dataset_id[1] if dataset_id else "/".join(folder.split("/")[-2:]) - found[key] = (folder, name[1].strip() if name else key) + key = dataset_id[1] if dataset_id else "/".join(folder.path.split("/")[-2:]) + found[key] = (folder.path, name[1].strip() if name else key) return found From 4cf6c2e2103c0d2805a7b2a8b048abc6d5aa6a8a Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:36:05 +0100 Subject: [PATCH 11/12] ci(release): start the PyPI run only after TestPyPI took the release --- .github/workflows/publish.yml | 19 +++++++++++++++++++ .github/workflows/release.yml | 35 +++++++++++++++++------------------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 57fc07568..754116508 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,6 +43,8 @@ jobs: # tokens are stored as repo secrets. id-token: write contents: read + # Start the PyPI run after a TestPyPI run of a release tag. + actions: write steps: - name: Guard PyPI to main run: | @@ -141,6 +143,23 @@ jobs: else uv publish fi + - name: Start the PyPI run + # A TestPyPI run of a release tag starts the PyPI run of the same tag, which waits for + # approval. So PyPI can only be approved after TestPyPI took the same files. + if: inputs.target == 'TestPyPI' && inputs.ref != '' + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + PACKAGE: ${{ inputs.package }} + REF: ${{ inputs.ref }} + run: | + name="Publish $PACKAGE $REF to PyPI" + if gh run list --workflow publish.yml --event workflow_dispatch --limit 100 --json displayTitle \ + --jq '.[].displayTitle' | grep -qxF "$name"; then + echo "Skipping '$name': it was already started." + exit 0 + fi + gh workflow run publish.yml --ref main -f target=PyPI -f package="$PACKAGE" -f ref="$REF" - name: Summary if: success() run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0ef133ef..192b6427d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,11 +7,11 @@ name: Release # 1. Run this workflow on main and pick the package. It opens a release PR that sets the version # and shows the notes. # 2. Merge the release PR. For every package whose version the PR changed, this tags -# -vX.Y.Z and creates a GitHub release. It starts a TestPyPI and a PyPI run of -# publish.yml (each waits for approval in the pypi environment), and opens a PR that moves the -# released packages to their next development version, X.(Y+1).0.dev0. -# 3. Approve the TestPyPI run and check the result, approve the PyPI run, then merge the -# development-version PR. +# -vX.Y.Z and creates a GitHub release. It starts a TestPyPI run of publish.yml, +# which waits for approval in the pypi environment, and opens a PR that moves the released +# packages to their next development version, X.(Y+1).0.dev0. +# 3. Approve the TestPyPI run. Once it has uploaded, it starts the PyPI run, which waits for +# approval too. Check TestPyPI, approve the PyPI run, then merge the development-version PR. # Releasing both raises the timenet floor of timenet-connectors to the new timenet version. # Releasing one package alone keeps the floor. The release PR warns when the other package has # changes that the release leaves out. @@ -180,8 +180,8 @@ jobs: git push --force origin "$BRANCH" { echo "Merging this PR tags each package below, creates its GitHub release with these notes," - echo "and starts the TestPyPI and PyPI publish runs for approval. To change the notes, edit" - echo "them in the GitHub release after it is created." + echo "and starts the TestPyPI publish run for approval. A successful TestPyPI run starts the" + echo "PyPI run. To change the notes, edit them in the GitHub release after it is created." echo echo "---" echo @@ -267,7 +267,7 @@ jobs: gh release create "$tag" --verify-tag --title "$package $version" --notes-file "$RUNNER_TEMP/notes.md" fi done - - name: Start the TestPyPI and PyPI publish runs + - name: Start the TestPyPI publish run env: GH_TOKEN: ${{ github.token }} RELEASED: ${{ steps.released.outputs.released }} @@ -278,16 +278,15 @@ jobs: if [ ${#released[@]} -eq 2 ]; then package=both; fi # Both tags of a release point at the same commit, so either one builds both packages. ref="${first%=*}-v${first#*=}" - for target in TestPyPI PyPI; do - # A re-run: skip a publish run this job already started. Its name comes from publish.yml's run-name. - name="Publish $package $ref to $target" - if gh run list --workflow publish.yml --event workflow_dispatch --limit 100 --json displayTitle \ - --jq '.[].displayTitle' | grep -qxF "$name"; then - echo "Skipping '$name': it was already started." - continue - fi - gh workflow run publish.yml --ref main -f target="$target" -f package="$package" -f ref="$ref" - done + # A re-run: skip the publish run if this job already started it. Its name comes from + # publish.yml's run-name. A successful TestPyPI run starts the PyPI run. + name="Publish $package $ref to TestPyPI" + if gh run list --workflow publish.yml --event workflow_dispatch --limit 100 --json displayTitle \ + --jq '.[].displayTitle' | grep -qxF "$name"; then + echo "Skipping '$name': it was already started." + exit 0 + fi + gh workflow run publish.yml --ref main -f target=TestPyPI -f package="$package" -f ref="$ref" next-development-version: needs: release From 22fca2e82349b0b3247db670dd7582eb50fa0382 Mon Sep 17 00:00:00 2001 From: masquare <11543761+masquare@users.noreply.github.com> Date: Wed, 11 Nov 2026 13:48:06 +0100 Subject: [PATCH 12/12] ci(release): build and test the release files once and attach them to the GitHub release --- .github/workflows/publish.yml | 97 +++++++++++------------------------ .github/workflows/release.yml | 61 ++++++++++++++++++++-- 2 files changed, 86 insertions(+), 72 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 754116508..15377a5b3 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,5 +1,9 @@ name: Publish to PyPI +# Uploads the wheel and the sdist that release.yml built and attached to the GitHub release of a +# -vX.Y.Z tag. It does not build. release.yml starts the TestPyPI run, and a successful +# TestPyPI run starts the PyPI run of the same tag. + on: workflow_dispatch: inputs: @@ -21,8 +25,8 @@ on: - timenet - timenet-connectors ref: - description: Release tag to build, for example timenet-v0.12.0. Leave empty to build the branch above. - required: false + description: Release tag to publish, for example timenet-v0.12.0 + required: true type: string run-name: Publish ${{ inputs.package }} ${{ inputs.ref }} to ${{ inputs.target }} @@ -43,47 +47,41 @@ jobs: # tokens are stored as repo secrets. id-token: write contents: read - # Start the PyPI run after a TestPyPI run of a release tag. + # Start the PyPI run after a TestPyPI run. actions: write steps: - - name: Guard PyPI to main + - name: Guard to main run: | echo "Branch: $BRANCH_NAME" - if [ "${{ inputs.target }}" = "PyPI" ] && [ "$BRANCH_NAME" != "main" ]; then - echo "::error title=Invalid branch::PyPI releases must come from main." + if [ "$BRANCH_NAME" != "main" ]; then + echo "::error title=Invalid branch::Run publish.yml from main." exit 1 fi - name: Checkout uses: actions/checkout@v5 with: - # A tag, or the exact commit the run was started on, not the branch tip at approval time. - ref: ${{ inputs.ref || github.sha }} + ref: ${{ inputs.ref }} fetch-depth: 0 - name: Guard the release tag - if: inputs.ref != '' env: REF: ${{ inputs.ref }} run: | if ! [[ "$REF" =~ ^(timenet|timenet-connectors)-v[0-9]+\.[0-9]+\.[0-9]+$ ]] || ! git merge-base --is-ancestor HEAD origin/main; then - echo "::error title=Invalid ref::Build only a -vX.Y.Z tag on main, not '$REF'." + echo "::error title=Invalid ref::Publish only a -vX.Y.Z tag on main, not '$REF'." exit 1 fi - name: Set up uv uses: astral-sh/setup-uv@v7 - - name: Guard the release versions + - name: Download the release files + # Each published package needs its own tag on this commit, and the files its GitHub + # release holds: one wheel and one sdist at the tagged version, nothing else. env: - REF: ${{ inputs.ref }} - TARGET: ${{ inputs.target }} + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} PACKAGE: ${{ inputs.package }} run: | - if [ -z "$REF" ]; then - if [ "$TARGET" = PyPI ]; then - echo "::error title=No release tag::Publish to PyPI from a -vX.Y.Z tag. Set the ref input." - exit 1 - fi - exit 0 - fi if [ "$PACKAGE" = both ]; then packages="timenet timenet-connectors"; else packages=$PACKAGE; fi + expected=() for package in $packages; do version=$(uv version --package "$package" --short) tag="$package-v$version" @@ -91,62 +89,25 @@ jobs: echo "::error title=Not released::$package is at $version, but $tag does not point at this commit. Release it first." exit 1 fi + gh release download "$tag" --dir dist + expected+=("${package//-/_}-$version-py3-none-any.whl" "${package//-/_}-$version.tar.gz") done - - name: Build - # build_dists.py records the commit inside each package, so a build can name its code. - run: | - if [ "${{ inputs.package }}" = "both" ]; then - uv run scripts/build_dists.py --all-packages - else - uv run scripts/build_dists.py --package "${{ inputs.package }}" + if [ "$(ls dist | sort)" != "$(printf '%s\n' "${expected[@]}" | sort)" ]; then + echo "::error title=Unexpected files::The releases hold $(ls dist | xargs), expected ${expected[*]}." + exit 1 fi - - name: Smoke test built artifacts - # Import each built wheel and sdist in an isolated environment to catch missing files or - # broken metadata before uploading. Each artifact must also report this commit, clean, as - # the code it was built from. timenet-connectors depends on timenet, so hand it the - # wheel we just built when it is present (a `both` run); otherwise timenet resolves from the - # default index, which requires it to be published already. - run: | - set -euo pipefail - shopt -s nullglob - timenet_whl=(dist/timenet-*.whl) - # The checked-out commit: the release tag's commit, or GITHUB_SHA without a ref. - expected_sha=$(git rev-parse HEAD) - smoke() { - local module="$1" dist="$2"; shift 2 - local args=() artifact - for artifact in "$@"; do args+=(--with "$artifact"); done - echo "::group::import $module" - uv run --isolated --no-project "${args[@]}" \ - python -c "import $module; print('smoke ok:', $module.__name__)" - uv run --isolated --no-project "${args[@]}" python -c " - from timenet.manifest import GitSource - from timenet.provenance import PackageSnapshot - commit = PackageSnapshot.read('$dist').source - expected = GitSource(sha='$expected_sha', contains_local_changes=False) - assert commit == expected, f'$dist records {commit}, expected {expected}' - print('commit ok:', commit)" - echo "::endgroup::" - } - for artifact in dist/*; do - case "$artifact" in - dist/timenet-*.whl | dist/timenet-*.tar.gz) - smoke timenet timenet "$artifact" ;; - dist/timenet_connectors-*.whl | dist/timenet_connectors-*.tar.gz) - smoke timenet_connectors timenet-connectors ${timenet_whl[@]+"${timenet_whl[@]}"} "$artifact" ;; - esac - done + ls -l dist - name: Publish run: | if [ "${{ inputs.target }}" = "TestPyPI" ]; then - uv publish --publish-url https://test.pypi.org/legacy/ + uv publish --publish-url https://test.pypi.org/legacy/ dist/* else - uv publish + uv publish dist/* fi - name: Start the PyPI run - # A TestPyPI run of a release tag starts the PyPI run of the same tag, which waits for - # approval. So PyPI can only be approved after TestPyPI took the same files. - if: inputs.target == 'TestPyPI' && inputs.ref != '' + # A TestPyPI run starts the PyPI run of the same tag, which waits for approval. So PyPI + # can only be approved after TestPyPI took the same files. + if: inputs.target == 'TestPyPI' env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 192b6427d..c81b142fa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,10 +6,11 @@ name: Release # shared connector code (.github/scripts/connector_notes.py). # 1. Run this workflow on main and pick the package. It opens a release PR that sets the version # and shows the notes. -# 2. Merge the release PR. For every package whose version the PR changed, this tags -# -vX.Y.Z and creates a GitHub release. It starts a TestPyPI run of publish.yml, -# which waits for approval in the pypi environment, and opens a PR that moves the released -# packages to their next development version, X.(Y+1).0.dev0. +# 2. Merge the release PR. For every package whose version the PR changed, this builds and +# smoke-tests the wheel and the sdist, tags -vX.Y.Z, and creates a GitHub release +# with the two files attached. It starts a TestPyPI run of publish.yml, which waits for +# approval in the pypi environment, and opens a PR that moves the released packages to their +# next development version, X.(Y+1).0.dev0. # 3. Approve the TestPyPI run. Once it has uploaded, it starts the PyPI run, which waits for # approval too. Check TestPyPI, approve the PyPI run, then merge the development-version PR. # Releasing both raises the timenet floor of timenet-connectors to the new timenet version. @@ -231,6 +232,50 @@ jobs: exit 1 fi echo "released=${released[*]}" >> "$GITHUB_OUTPUT" + - name: Build + # build_dists.py records the commit inside each package, so a build can name its code. + env: + RELEASED: ${{ steps.released.outputs.released }} + run: | + for entry in $RELEASED; do + uv run scripts/build_dists.py --package "${entry%=*}" + done + - name: Smoke test built artifacts + # Import each built wheel and sdist in an isolated environment to catch missing files or + # broken metadata before uploading. Each artifact must also report this commit, clean, as + # the code it was built from. timenet-connectors depends on timenet, so hand it the + # wheel we just built when it is present (a `both` run); otherwise timenet resolves from the + # default index, which requires it to be published already. + run: | + set -euo pipefail + shopt -s nullglob + timenet_whl=(dist/timenet-*.whl) + # The merge commit that the tags point at. + expected_sha=$(git rev-parse HEAD) + smoke() { + local module="$1" dist="$2"; shift 2 + local args=() artifact + for artifact in "$@"; do args+=(--with "$artifact"); done + echo "::group::import $module" + uv run --isolated --no-project "${args[@]}" \ + python -c "import $module; print('smoke ok:', $module.__name__)" + uv run --isolated --no-project "${args[@]}" python -c " + from timenet.manifest import GitSource + from timenet.provenance import PackageSnapshot + commit = PackageSnapshot.read('$dist').source + expected = GitSource(sha='$expected_sha', contains_local_changes=False) + assert commit == expected, f'$dist records {commit}, expected {expected}' + print('commit ok:', commit)" + echo "::endgroup::" + } + for artifact in dist/*; do + case "$artifact" in + dist/timenet-*.whl | dist/timenet-*.tar.gz) + smoke timenet timenet "$artifact" ;; + dist/timenet_connectors-*.whl | dist/timenet_connectors-*.tar.gz) + smoke timenet_connectors timenet-connectors ${timenet_whl[@]+"${timenet_whl[@]}"} "$artifact" ;; + esac + done - name: Tag and create the GitHub releases env: GH_TOKEN: ${{ github.token }} @@ -266,6 +311,14 @@ jobs: fi gh release create "$tag" --verify-tag --title "$package $version" --notes-file "$RUNNER_TEMP/notes.md" fi + # Attach the wheel and the sdist. A re-run uploads only the files that are missing, so + # the files a publish run may already have taken stay as they are. + attached=$(gh release view "$tag" --json assets --jq '.assets[].name') + for file in "dist/${package//-/_}-$version"-*.whl "dist/${package//-/_}-$version".tar.gz; do + if ! grep -qxF "$(basename "$file")" <<< "$attached"; then + gh release upload "$tag" "$file" + fi + done done - name: Start the TestPyPI publish run env: