Skip to content
Merged
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
37 changes: 26 additions & 11 deletions lib/mix/tasks/git_ops.release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ defmodule Mix.Tasks.GitOps.Release do
reserved.

* `--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.
"""

alias GitOps.Changelog
Expand Down Expand Up @@ -128,11 +130,18 @@ defmodule Mix.Tasks.GitOps.Release do

create_and_display_changes(current_version, new_version, changelog_changes, opts)

unless opts[:dry_run] do
confirm_and_tag(repo, changelog_file, prefixed_new_version)
end
cond do
opts[:dry_run] ->
:ok

:ok
opts[:yes] ->
tag(repo, changelog_file, prefixed_new_version)
:ok

true ->
confirm_and_tag(repo, changelog_file, prefixed_new_version)
:ok
end
end

defp get_commit_messages(repo, prefix, tags, opts) do
Expand Down Expand Up @@ -186,6 +195,14 @@ defmodule Mix.Tasks.GitOps.Release do
end
end

defp tag(repo, changelog_file, new_version) do
Git.add!(repo, "#{changelog_file}")
Git.commit!(repo, ["-am", "chore: release version #{new_version}"])
Git.tag!(repo, ["-a", new_version, "-m", "release #{new_version}"])

Mix.shell().info("Don't forget to push with tags:\n\n git push --follow-tags")
end

defp confirm_and_tag(repo, changelog_file, new_version) do
message = """
Shall we commit and tag?
Expand All @@ -194,11 +211,7 @@ defmodule Mix.Tasks.GitOps.Release do
"""

if Mix.shell().yes?(message) do
Git.add!(repo, "#{changelog_file}")
Git.commit!(repo, ["-am", "chore: release version #{new_version}"])
Git.tag!(repo, ["-a", new_version, "-m", "release #{new_version}"])

Mix.shell().info("Don't forget to push with tags:\n\n git push --follow-tags")
tag(repo, changelog_file, new_version)
else
Mix.shell().info("""
If you want to do it on your own, make sure you tag the release with:
Expand Down Expand Up @@ -257,15 +270,17 @@ defmodule Mix.Tasks.GitOps.Release do
no_major: :boolean,
pre_release: :string,
rc: :boolean,
dry_run: :boolean
dry_run: :boolean,
yes: :boolean
],
aliases: [
i: :initial,
p: :pre_release,
b: :build,
f: :force_patch,
n: :no_major,
d: :dry_run
d: :dry_run,
y: :yes
]
)

Expand Down