Skip to content
Closed
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
13 changes: 11 additions & 2 deletions lib/git_ops/version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ defmodule GitOps.Version do

def determine_new_version(current_version, prefix, commits, opts) do
parsed = parse!(prefix, prefix <> current_version)

rc? = opts[:rc]

build = opts[:build]

new_version = new_version(commits, parsed, rc?, opts)

if versions_equal?(new_version, parsed) && build == parsed.build do
raise """
message = """
No changes should result in a new release version.

Options:
Expand All @@ -38,6 +37,8 @@ defmodule GitOps.Version do
* You can add build metadata using `--build` that will signify that something was
unique about this build.
"""

maybe_raise(message, opts)
end

unprefixed =
Expand Down Expand Up @@ -139,4 +140,12 @@ defmodule GitOps.Version do
raise ArgumentError, "Expected: #{text} to be parseable as a version, but it was not."
end
end

defp maybe_raise(msg, opts) do
if Keyword.fetch(opts, :ci) == {:ok, true} do
IO.puts(msg)
else
raise msg
end
end
end
5 changes: 4 additions & 1 deletion lib/mix/tasks/git_ops.release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ defmodule Mix.Tasks.GitOps.Release do
* `--dry-run` - Allow users to run release process and view changes without committing and tagging

* `--yes` - Don't prompt for confirmation, just perform release. Useful for your CI run.

* `--ci` - Do not raise an exception when there is no version to bump. Useful for CI pipelines.
"""

alias GitOps.Changelog
Expand Down Expand Up @@ -289,7 +291,8 @@ defmodule Mix.Tasks.GitOps.Release do
pre_release: :string,
rc: :boolean,
dry_run: :boolean,
yes: :boolean
yes: :boolean,
ci: :boolean
],
aliases: [
i: :initial,
Expand Down
21 changes: 21 additions & 0 deletions test/version_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule GitOps.Test.VersionTest do
use ExUnit.Case
import ExUnit.CaptureIO

alias GitOps.Version

Expand Down Expand Up @@ -64,6 +65,26 @@ defmodule GitOps.Test.VersionTest do
end
end

test "attempting to release when no commit would yield a new version number with the --ci option is not an error" do
message = """
No changes should result in a new release version.

Options:

* If no fixes or features were added, then perhaps you don't need to release.
* If a fix or feature commit was not correctly annotated, you could alter your git
history to fix it and run this command again, or create an empty commit via
`git commit --allow-empty` that contains an appropriate message.
* If you don't care and want a new version, you can use `--force-patch` which
will update the patch version regardless.
* You can add build metadata using `--build` that will signify that something was
unique about this build.

"""

assert capture_io(fn -> new_version("0.1.1", [chore()], ci: true) end) == message
end

test "if changing the build metadata, a non-version change is not an error" do
new_version("0.1.1+10", [chore()], build: "11")
end
Expand Down