Repository navigation
Version the package from VERSION and bump it on merge to main #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| name: Version bump | ||
|
|
||
| # Raises VERSION on main each time a change enters it. It creates no tags: tags belong to the release. | ||
| # Contributors work on forks, so the bump cannot happen in the pull request. It happens after the merge. | ||
| # | ||
| # A run works on the tip of main, not on the commit that started it, and GitHub keeps only the newest run that is | ||
| # waiting. Merges that land close together can therefore share one version. | ||
| # | ||
| # The reference is the highest VERSION that main has held before its tip, not the content of VERSION at the tip, so a | ||
| # stale VERSION cannot move the version backwards or repeat one. | ||
| # Only main's own history counts (first parent), not the commits inside a pull request. | ||
| # | ||
| # VERSION at the tip is above that -> a maintainer set it (for example 1.1.0). It stays as it is. | ||
| # otherwise -> the patch number of the highest one goes up by one (1.0.9 -> 1.0.10), in a | ||
| # commit pushed to main. | ||
| # | ||
| # A minor or major step is a pull request by a maintainer that sets VERSION to the new version. | ||
| # | ||
| # The bump commit goes straight to main, which needs a token that may bypass the rule that asks for pull requests. | ||
| # Add a repository secret VERSION_BUMP_TOKEN (a GitHub App token or a PAT with contents:write) and let it bypass. | ||
| # With the default GITHUB_TOKEN the push is refused while main is protected. | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| concurrency: | ||
| group: version-bump | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this job should run only in this repo, not in the forks so probably needs something like if: github.repository == 'mlcommons/chakra'
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. otherwise forks syncing will become merges isntead of fast forwards i think |
||
| bump: | ||
| # [skip ci] already stops the bump commit from starting this workflow again. The actor check is a second guard. | ||
| if: github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, '[skip ci]') | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Warn when the bump token is missing | ||
| env: | ||
| HAS_TOKEN: ${{ secrets.VERSION_BUMP_TOKEN != '' }} | ||
| run: | | ||
| if [ "$HAS_TOKEN" != "true" ]; then | ||
| echo "::warning::VERSION_BUMP_TOKEN is not set. The push to main fails while main is protected." | ||
| fi | ||
|
|
||
| # The tip of main, not the commit that started this run: a merge may have landed since. | ||
| # The whole history, because the versions main has held are read from it. | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: main | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.VERSION_BUMP_TOKEN || github.token }} | ||
|
|
||
| - name: Bump VERSION above the highest one main has held, unless a maintainer raised it | ||
| run: | | ||
| set -euo pipefail | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| for attempt in 1 2 3; do | ||
| git fetch -q origin main | ||
| git reset -q --hard origin/main | ||
|
|
||
| current=$(tr -d '[:space:]' < VERSION) | ||
| # Every value VERSION had on main before the tip: the first-parent commits that changed it. | ||
| held=() | ||
| if git rev-parse -q --verify HEAD^ > /dev/null; then | ||
| while read -r commit; do | ||
| held+=("$(git show "$commit:VERSION" 2>/dev/null | tr -d '[:space:]')") | ||
| done < <(git rev-list --first-parent HEAD^ -- VERSION) | ||
| fi | ||
| decision=$(python3 - "$current" "${held[@]}" <<'PY' | ||
| import re, sys | ||
|
|
||
| current, *held = sys.argv[1:] | ||
| number = r"(0|[1-9]\d*)" | ||
| version = rf"{number}\.{number}\.{number}" | ||
| if not re.fullmatch(version, current): | ||
| sys.exit(f"VERSION must look like X.Y.Z, got {current!r}") | ||
|
|
||
|
|
||
| def key(text): | ||
| return tuple(map(int, text.split("."))) | ||
|
|
||
|
|
||
| # A value that main held before, even a bad one that was fixed later, counts only if it is a version. | ||
| previous = [value for value in held if re.fullmatch(version, value)] | ||
| if not previous or key(current) > key(max(previous, key=key)): | ||
| print("keep", current) | ||
| else: | ||
| highest = max(previous, key=key) | ||
| if key(current) < key(highest): | ||
| print(f"::warning::VERSION {current} is below {highest}, which main held before, counting from {highest}", file=sys.stderr) | ||
| major, minor, patch = key(highest) | ||
| print("bump", f"{major}.{minor}.{patch + 1}") | ||
| PY | ||
| ) || { echo "::error::Could not work out the next version."; exit 1; } | ||
| action=${decision%% *} | ||
| new=${decision#* } | ||
| if [ -z "$new" ] || [ "$new" = "$decision" ]; then | ||
| echo "::error::Unexpected result: '$decision'" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "$action" = keep ]; then | ||
| echo "VERSION $new is above every version main held before: it stays as it is" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "VERSION $current -> $new" | ||
| echo "$new" > VERSION | ||
| git add VERSION | ||
| git commit -q -m "chore: bump version to $new [skip ci]" | ||
| # A rejected push means main moved, so start again from its new tip. | ||
| if git push origin HEAD:main; then | ||
| exit 0 | ||
| fi | ||
| echo "push rejected, main moved (attempt $attempt), trying again" | ||
| done | ||
| echo "::error::Could not push the version bump after 3 attempts." | ||
| exit 1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.0.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta" | |
| [project] | ||
| name = "mlc-chakra" | ||
| requires-python = ">=3.11,<3.15" | ||
| version = "1.0.0" | ||
| dynamic = ["version"] | ||
| readme = "README.md" | ||
| license = {file = "LICENSE.md"} | ||
| authors = [ | ||
|
|
@@ -27,7 +27,11 @@ Homepage = "https://github.com/mlcommons/chakra" | |
| Documentation = "https://github.com/mlcommons/chakra/README.md" | ||
| Repository = "https://github.com/mlcommons/chakra.git" | ||
|
|
||
| [tool.setuptools.dynamic] | ||
| version = {file = "VERSION"} | ||
|
|
||
| [tool.setuptools.package-dir] | ||
| "chakra" = "src/chakra_pkg" | ||
| "chakra.schema.protobuf" = "schema/protobuf" | ||
| "chakra.src.converter" = "src/converter" | ||
| "chakra.src.generator" = "src/generator" | ||
|
|
@@ -106,10 +110,16 @@ dev = [ | |
|
|
||
| [tool.uv] | ||
| default-groups = ["dev"] | ||
| # Rebuild the package, and so the generated *_pb2.py files, when a .proto file changes. The default keys miss it. | ||
| # chakra is a real package (it holds __version__), and the default editable finder cannot resolve chakra.src.* under it. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This "chakra is a real package" phrasing is strange. |
||
| # strict links the files into a tree that has the same layout as the wheel. | ||
| config-settings = { editable_mode = "strict" } | ||
| # Rebuild the package, and so the generated *_pb2.py files, when a .proto file changes, and so that a new module is | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these will probably require a careful rebasing after the proto PR#282. |
||
| # linked into the strict editable tree. The default keys miss both. | ||
| cache-keys = [ | ||
| { file = "pyproject.toml" }, | ||
| { file = "setup.py" }, | ||
| { file = "setup.cfg" }, | ||
| { file = "schema/protobuf/*.proto" }, | ||
| { file = "src/**/*.py" }, | ||
| { file = "VERSION" }, | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| """Chakra execution trace tools.""" | ||
|
|
||
| from importlib.metadata import PackageNotFoundError, version | ||
|
|
||
| try: | ||
| __version__ = version("mlc-chakra") | ||
| except PackageNotFoundError: | ||
| __version__ = "0+unknown" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 lines could be replaced by "The bump commit goes straight to main, so uses VERSION_BUMP_TOKEN to bypass the rule asking for pull requests.". Most of their content right now is the LLM giving guidelines about how to set up the bump workflow and should not end up as code comment.