Skip to content

Commit 3592909

Browse files
committed
Check for current version tags when looking for outstanding commits on a branch
1 parent e1c54ff commit 3592909

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

lib/fastlane/plugin/ddg_apple_automation/helper/git_helper.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ def self.untagged_commit_sha(release_branch, platform)
7474
end
7575

7676
def self.release_branch_state(release_branch, platform)
77-
latest_tag = `git tag --sort=-creatordate | grep '+#{platform}' | head -n 1`.chomp
77+
marketing_version = extract_version_from_branch_name(release_branch)
78+
if marketing_version.to_s.empty?
79+
UI.user_error!("Unable to extract version from '#{release_branch}' branch name.")
80+
return
81+
end
82+
83+
latest_tag = `git tag --sort=-creatordate | grep '+#{platform}' | grep '#{marketing_version}' | head -n 1`.chomp
7884
latest_tag_sha = commit_sha_for_tag(latest_tag)
7985
release_branch_sha = `git rev-parse "origin/#{release_branch}"`.chomp
8086

spec/git_helper_spec.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,20 +478,22 @@ def validate_semver(version)
478478
end
479479

480480
describe "#assert_branch_has_changes" do
481-
subject { Fastlane::Helper::GitHelper.assert_branch_has_changes("release_branch", platform) }
481+
subject { Fastlane::Helper::GitHelper.assert_branch_has_changes(release_branch, platform) }
482482

483+
let(:release_branch) { "release/ios/1.0.0" }
483484
let(:platform) { "ios" }
484-
let(:version) { "1.0.0+#{platform}" }
485+
let(:semver) { "1.0.0" }
486+
let(:version) { "#{semver}+#{platform}" }
485487

486488
before do
487489
allow(Fastlane::UI).to receive(:important)
488490
end
489491

490492
context "when the release branch has no changes since the latest tag" do
491493
it "returns false and shows a message" do
492-
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git tag --sort=-creatordate | grep '+#{platform}' | head -n 1").and_return("#{version}\n")
494+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git tag --sort=-creatordate | grep '+#{platform}' | grep '#{semver}' | head -n 1").and_return("#{version}\n")
493495
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git rev-parse \"#{version}\"^{}").and_return("abc123\n")
494-
allow(Fastlane::Helper::GitHelper).to receive(:`).with('git rev-parse "origin/release_branch"').and_return("abc123\n")
496+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git rev-parse \"origin/#{release_branch}\"").and_return("abc123\n")
495497

496498
expect(subject).to be_falsey
497499
expect(Fastlane::UI).to have_received(:important).with("Release branch's HEAD is already tagged. Skipping automatic release.")
@@ -500,20 +502,20 @@ def validate_semver(version)
500502

501503
context "when the release branch has changes since the latest tag" do
502504
it "returns true" do
503-
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git tag --sort=-creatordate | grep '+#{platform}' | head -n 1").and_return("#{version}\n")
505+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git tag --sort=-creatordate | grep '+#{platform}' | grep '#{semver}' | head -n 1").and_return("#{version}\n")
504506
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git rev-parse \"#{version}\"^{}").and_return("abc123\n")
505-
allow(Fastlane::Helper::GitHelper).to receive(:`).with('git rev-parse "origin/release_branch"').and_return("def456\n")
506-
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git diff --name-only \"#{version}\"..\"origin/release_branch\"").and_return("app/file1.rb\napp/file2.rb\n")
507+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git rev-parse \"origin/#{release_branch}\"").and_return("def456\n")
508+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git diff --name-only \"#{version}\"..\"origin/#{release_branch}\"").and_return("app/file1.rb\napp/file2.rb\n")
507509
expect(subject).to be_truthy
508510
end
509511
end
510512

511513
context "when changes are only in scripts or workflows" do
512514
it "returns false" do
513-
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git tag --sort=-creatordate | grep '+#{platform}' | head -n 1").and_return("#{version}\n")
515+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git tag --sort=-creatordate | grep '+#{platform}' | grep '#{semver}' | head -n 1").and_return("#{version}\n")
514516
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git rev-parse \"#{version}\"^{}").and_return("abc123\n")
515-
allow(Fastlane::Helper::GitHelper).to receive(:`).with('git rev-parse "origin/release_branch"').and_return("def456\n")
516-
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git diff --name-only \"#{version}\"..\"origin/release_branch\"").and_return(".github/workflows/workflow.yml\nscripts/deploy.sh\nfastlane/Fastfile\n")
517+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git rev-parse \"origin/#{release_branch}\"").and_return("def456\n")
518+
allow(Fastlane::Helper::GitHelper).to receive(:`).with("git diff --name-only \"#{version}\"..\"origin/#{release_branch}\"").and_return(".github/workflows/workflow.yml\nscripts/deploy.sh\nfastlane/Fastfile\n")
517519
expect(subject).to be_falsey
518520
end
519521
end

0 commit comments

Comments
 (0)