Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [main]
release:
types: [published]
workflow_dispatch:

concurrency:
group: docker-${{ github.ref }}
Expand All @@ -21,6 +22,14 @@ jobs:
attestations: write

steps:
- name: Require a release tag for manual dispatch
if: github.event_name == 'workflow_dispatch'
run: |
if [[ ! "$GITHUB_REF" =~ ^refs/tags/v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "::error::Dispatch publishing at a vX.Y.Z tag, not a branch."
exit 1
fi

- uses: actions/checkout@v4

- name: Set up QEMU
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Publish to PyPI
on:
release:
types: [published]
workflow_dispatch:

jobs:
publish:
Expand All @@ -14,6 +15,14 @@ jobs:
contents: read

steps:
- name: Require a release tag for manual dispatch
if: github.event_name == 'workflow_dispatch'
run: |
if [[ ! "$GITHUB_REF" =~ ^refs/tags/v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
echo "::error::Dispatch publishing at a vX.Y.Z tag, not a branch."
exit 1
fi

- uses: actions/checkout@v4

- name: Install uv
Expand All @@ -33,6 +42,8 @@ jobs:

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true

- name: Install mcp-publisher
run: |
Expand Down
132 changes: 132 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: Release

on:
workflow_dispatch:
inputs:
bump:
description: Version bump
type: choice
required: true
default: patch
options: [patch, minor, major]

permissions:
contents: read

concurrency:
group: release
cancel-in-progress: false

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
actions: read
outputs:
tag: ${{ steps.version.outputs.tag }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}

steps:
- name: Require main branch
if: github.ref != 'refs/heads/main'
run: |
echo "::error::Releases must run from the main branch."
exit 1

- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Require successful CI for this commit
run: |
ci=$(gh run list --workflow ci.yml --branch main --commit "$GITHUB_SHA" \
--event push --limit 1 --json status,conclusion,url --jq '.[0] // {}')
if [[ "$(jq -r '.status' <<< "$ci")" != completed || \
"$(jq -r '.conclusion' <<< "$ci")" != success ]]; then
echo "::error::CI must pass for $GITHUB_SHA before releasing. $(jq -r '.url // empty' <<< "$ci")"
exit 1
fi

- name: Compute next version
id: version
env:
BUMP: ${{ inputs.bump }}
run: |
python3 - <<'PY'
import os
import re
import subprocess

def git(*args):
return subprocess.check_output(["git", *args], text=True).strip()

pattern = r"v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)"
versions = [
tuple(map(int, match.groups()))
for tag in git("tag", "--list").splitlines()
if (match := re.fullmatch(pattern, tag))
]
major, minor, patch = max(versions, default=(0, 0, 0))
latest = f"v{major}.{minor}.{patch}" if versions else ""
if latest:
sha = os.environ["GITHUB_SHA"]
if git("rev-parse", f"{latest}^{{commit}}") == sha:
raise SystemExit("::error::This commit is already released. Retry the failed publishing run instead.")
if subprocess.run(["git", "merge-base", "--is-ancestor", latest, sha]).returncode:
raise SystemExit("::error::The release commit must include the latest stable tag.")

match os.environ["BUMP"]:
case "major":
version = (major + 1, 0, 0)
case "minor":
version = (major, minor + 1, 0)
case "patch":
version = (major, minor, patch + 1)
case _:
raise SystemExit("::error::Expected a patch, minor, or major bump.")

tag = "v" + ".".join(map(str, version))
with open(os.environ["GITHUB_OUTPUT"], "a") as output:
output.write(f"tag={tag}\nlatest={latest}\n")
print(f"Next release: {tag}")
PY

- name: Create GitHub Release
env:
TAG: ${{ steps.version.outputs.tag }}
LATEST: ${{ steps.version.outputs.latest }}
run: |
args=(--target "$GITHUB_SHA" --title "$TAG" --generate-notes)
if [[ -n "$LATEST" ]]; then
args+=(--notes-start-tag "$LATEST")
fi
gh release create "$TAG" "${args[@]}"
echo "Created [$TAG]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/$TAG) at \`$GITHUB_SHA\`." >> "$GITHUB_STEP_SUMMARY"

dispatch:
name: Dispatch ${{ matrix.workflow }}
needs: release
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
strategy:
fail-fast: false
matrix:
workflow: [publish.yml, docker.yml]
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
TAG: ${{ needs.release.outputs.tag }}
WORKFLOW: ${{ matrix.workflow }}

steps:
# GITHUB_TOKEN-created releases do not trigger release-event workflows.
- name: Start publishing at the release tag
run: |
gh workflow run "$WORKFLOW" --ref "$TAG"
echo "Dispatched [$WORKFLOW]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/workflows/$WORKFLOW?query=branch%3A$TAG) at \`$TAG\`. Check that workflow's run for publishing completion." >> "$GITHUB_STEP_SUMMARY"
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,31 @@ uv run cronometer-api-mcp

The CLI auto-loads `.env` on startup (dev convenience only). Real environment variables always win over `.env`, so production deployments and MCP client `env` blocks are unaffected.

### Releases

Open **Actions → Release → Run workflow**, select **main**, and choose **patch**
(default), **minor**, or **major**. CI must have passed for the selected commit;
if it is still running, wait for it to finish before starting the release.

The workflow increments the highest stable `vX.Y.Z` tag, tags the selected commit,
and creates a GitHub Release with generated notes. Prerelease tags are ignored.
For example, `v0.2.7` becomes `v0.2.8` for a patch or `v0.3.0` for a minor release.
Release runs are serialized, and an already-released commit cannot be released again.

The release workflow then dispatches **Publish to PyPI** (including the MCP Registry)
and **Build Docker image** at the new tag. Check their separate runs for publishing
completion; a successful Release run only confirms they were dispatched. Version
fields in `pyproject.toml` and `server.json` are set from the tag during publishing.

This uses the built-in `GITHUB_TOKEN` and existing OIDC publishing configuration;
no PAT or GitHub App is needed. Explicit dispatch is necessary because releases
created with `GITHUB_TOKEN` do not trigger `release: published` workflows.

If dispatch or publishing fails, rerun the failed jobs in that workflow run rather
than starting a new release. Existing PyPI uploads are skipped on retry so an MCP
Registry failure can be retried. Manually published GitHub Releases also continue
to trigger publishing.

## How It Works

This server communicates with `mobile.cronometer.com` -- the same REST API used by the Cronometer Android/Flutter app. The API was reverse-engineered through:
Expand Down
Loading