Skip to content

Replace mix tag with mix_version - #24

Merged
KTSCode merged 4 commits into
mainfrom
todo/replace_tag_with_mix_version
Apr 17, 2026
Merged

Replace mix tag with mix_version#24
KTSCode merged 4 commits into
mainfrom
todo/replace_tag_with_mix_version

Conversation

@KTSCode

@KTSCode KTSCode commented Apr 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add mix_version ~> 2.4 dependency with versioning config in mix.exs
  • Extract changelog management from mix tag into new Mix.Tasks.Changelog.Finalize task (mix changelog.finalize --patch/--minor/--major)
  • Replace mix tag with a tag_release/1 alias that runs safety checks, then calls changelog.finalize and version in sequence, then pushes atomically
  • Delete lib/mix/tasks/tag.ex and its test file; replace with lib/mix/tasks/changelog/finalize.ex and test/mix/tasks/changelog/finalize_test.exs

Test plan

  • 18 tests cover parse_bump_flag/1, bump_version/2, unreleased_entries/1, finalize_changelog/3
  • All 243 tests pass (mix quality --quick)
  • Full quality suite passes including dialyzer
Implementation Plan

Replace DIY mix tag with mix_version

Context

The custom Mix.Tasks.Tag handles version bumping, changelog finalization, and git operations
in ~320 lines. mix_version handles version bump + commit + tag out of the box. By extracting
changelog management into its own task and delegating version work to mix_version, we reduce
custom code and align with community tooling.

Trade-off

This splits the single release commit into two: one for the changelog, one for the version bump.
The git history goes from:

Release v0.6.0  (modifies mix.exs + CHANGELOG.md)

to:

v0.6.0                    (modifies mix.exs, tagged v0.6.0)
Finalize changelog 0.6.0  (modifies CHANGELOG.md)

Steps

1. Add mix_version dependency

In mix.exs deps:

{:mix_version, "~> 2.4", only: [:dev, :test], runtime: false}

Add :versioning to project/0:

versioning: [
  tag_prefix: "v",
  commit_msg: "v%s",
  annotate: true,
  annotation: "Release %s"
]

2. Create lib/mix/tasks/changelog/finalize.ex

Extract from the existing tag.ex:

  • unreleased_entries/1 -- validates [Unreleased] section has entries
  • finalize_changelog/3 -- moves entries under a versioned heading
  • confirm_release/3 -- shows entries and prompts y/N

3. Replace function alias in mix.exs

Update aliases/0 with tag_release/1 that runs safety checks, then changelog.finalize, version, and pushes.

4. Delete lib/mix/tasks/tag.ex

5. Move safety checks to tag_release/1

6. Update tests

  • Keep tests for unreleased_entries/1 and finalize_changelog/3 (move to new module)
  • Remove tests for bump_version/2, update_version_in_mix/2, parse_component/1

Delegates version bumping and git tagging to mix_version. Extracts
changelog finalization into Mix.Tasks.Changelog.Finalize. The mix tag
alias now runs safety checks, then calls changelog.finalize and
version in sequence before pushing atomically.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 77f5594d3d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/mix/tasks/changelog/finalize.ex Outdated
Comment on lines +34 to +37
cond do
"--major" in args -> {:ok, :major}
"--minor" in args -> {:ok, :minor}
"--patch" in args -> {:ok, :patch}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject ambiguous bump args before changelog commit

parse_bump_flag/1 accepts any argv that merely contains one recognized bump flag and silently picks the first match, so inputs like mix tag --major --patch (or --patch plus an unsupported extra arg) still let changelog.finalize write and commit CHANGELOG.md. The next step in tag_release/1 (Mix.Task.run("version", args)) then uses mix_version’s stricter option parsing and can halt on invalid/mutually-exclusive flags, leaving a partial release state with a committed changelog but no version bump/tag. Validate that argv is exactly one allowed bump selector before committing.

Useful? React with 👍 / 👎.

KTSCode added 3 commits April 16, 2026 17:22
Allow exactly one of --major, --minor, --patch. Multiple or unknown
flags now return {:error, :invalid_flag} before changelog is committed.
@KTSCode
KTSCode merged commit e04c3d1 into main Apr 17, 2026
@KTSCode
KTSCode deleted the todo/replace_tag_with_mix_version branch April 17, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant