Skip to content
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

feat: allow exclusion of scopes from analyze_commits #16

Merged
merged 1 commit into from
Dec 10, 2019
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ notes = conventional_changelog(format: 'slack', title: 'Android Alpha')
- analyzes subject of every single commit and increases version number if there is a need (check conventional commit rules)
- if next version number is higher then last version number it will recommend you to release this version

Options:

- `ignore_scopes: ['android','windows']`: allows you to ignore any commits which include a given scope, like this one: `feat(android): add functionality not relevant to the release we are producing`

Example usage:

```
isReleasable = analyze_commits(match: 'ios/beta*')
```
Expand Down
15 changes: 15 additions & 0 deletions lib/fastlane/plugin/semantic_release/actions/analyze_commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ def self.run(params)
releases: releases
)

unless commit[:scope].nil?
# if this commit has a scope, then we need to inspect to see if that is one of the scopes we're trying to exclude
scope = commit[:scope]
scopes_to_ignore = params[:ignore_scopes]
# if it is, we'll skip this commit when bumping versions
next if scopes_to_ignore.include?(scope) #=> true
end

if commit[:release] == "major" || commit[:is_breaking_change]
next_major += 1
next_minor = 0
Expand Down Expand Up @@ -154,6 +162,13 @@ def self.available_options
key: :tag_version_match,
description: "To parse version number from tag name",
default_value: '\d+\.\d+\.\d+'
),
FastlaneCore::ConfigItem.new(
key: :ignore_scopes,
description: "To ignore certain scopes when calculating releases",
default_value: [],
type: Array,
optional: true
)
]
end
Expand Down
95 changes: 67 additions & 28 deletions spec/analyze_commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
before do
end

def execute_lane_test
Fastlane::FastFile.new.parse("lane :test do analyze_commits( match: 'v*') end").runner.execute(:test)
def test_analyze_commits(commits)
# for simplicity, these two actions are grouped together because they need to be run for every test,
# but require different commits to be passed each time. So we can't use the "before :each" for this
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)
end

def execute_lane_test(params)
Fastlane::FastFile.new.parse("lane :test do analyze_commits( #{params} ) end").runner.execute(:test)
end

it "should increment fix and return true" do
commits = [
"docs: ...|",
"fix: ...|"
]
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)
test_analyze_commits(commits)

expect(execute_lane_test).to eq(true)
expect(execute_lane_test(match: 'v*')).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.0.9")
end

Expand All @@ -27,10 +33,9 @@ def execute_lane_test
"feat: ...|",
"fix: ...|"
]
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)
test_analyze_commits(commits)

expect(execute_lane_test).to eq(true)
expect(execute_lane_test(match: 'v*')).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.1.1")
end

Expand All @@ -40,24 +45,61 @@ def execute_lane_test
"feat: ...|",
"fix: ...|BREAKING CHANGE: Test"
]
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)
test_analyze_commits(commits)

expect(execute_lane_test).to eq(true)
expect(execute_lane_test(match: 'v*')).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("2.0.0")
end

it "should correctly parse scopes" do
describe "scopes" do
commits = [
"docs(scope): ...|",
"feat(test): ...|",
"fix(test): ...|"
"fix(scope): ...|",
"feat(ios): ...|",
"fix(ios): ...|",
"feat(android): ...|",
"fix(android): ...|"
]
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)

expect(execute_lane_test).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.1.1")
describe "parsing of scopes" do
it "should correctly parse and output scopes" do
test_analyze_commits(commits)

expect(execute_lane_test(match: 'v*')).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.2.1")
end
end

describe "filtering by scopes" do
it "should accommodate an empty ignore_scopes array" do
test_analyze_commits(commits)

expect(execute_lane_test(match: 'v*', ignore_scopes: [])).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.2.1")
end

it "should skip a single scopes if it has been added to ignore_scopes" do
test_analyze_commits(commits)

expect(execute_lane_test(match: 'v*', ignore_scopes: ['android'])).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.1.1")
end

it "should skip multiple scopes if they have been added to ignore_scopes" do
test_analyze_commits(commits)

expect(execute_lane_test(match: 'v*', ignore_scopes: ['android', 'ios'])).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.0.9")
end

it "should not pass analysis checks if all commits are caught by excluded scopes" do
commits = [
"fix(ios): ...|"
]
test_analyze_commits(commits)

expect(execute_lane_test(match: 'v*', ignore_scopes: ['ios'])).to eq(false)
end
end
end

it "should return false since there is no change that would increase version" do
Expand All @@ -66,10 +108,9 @@ def execute_lane_test
"chore: ...|",
"refactor: ...|"
]
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)
test_analyze_commits(commits)

expect(execute_lane_test).to eq(false)
expect(execute_lane_test(match: 'v*')).to eq(false)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.0.8")
end

Expand All @@ -78,10 +119,9 @@ def execute_lane_test
"Merge ...|",
"Custom ...|"
]
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)
test_analyze_commits(commits)

expect(execute_lane_test).to eq(false)
expect(execute_lane_test(match: 'v*')).to eq(false)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.0.8")
end

Expand All @@ -96,10 +136,9 @@ def execute_lane_test
"chore: add alpha deploy triggered by alpha branch|",
"fix: fix navigation after user logs in|"
]
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_last_tag).and_return('v1.0.8-1-g71ce4d8')
allow(Fastlane::Actions::AnalyzeCommitsAction).to receive(:get_commits_from_hash).and_return(commits)
test_analyze_commits(commits)

expect(execute_lane_test).to eq(true)
expect(execute_lane_test(match: 'v*')).to eq(true)
expect(Fastlane::Actions.lane_context[Fastlane::Actions::SharedValues::RELEASE_NEXT_VERSION]).to eq("1.0.10")
end

Expand Down