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

Allow build suffixes for Android builds #721

Merged
merged 14 commits into from
Jan 17, 2025
4 changes: 2 additions & 2 deletions app/controllers/config/release_platforms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def config_params
]
],
release_candidate_workflow_attributes: [
:id, :identifier, :artifact_name_pattern
:id, :identifier, :artifact_name_pattern, :build_suffix
],
production_release_attributes: [
:id,
Expand All @@ -79,7 +79,7 @@ def config_params
]
],
internal_workflow_attributes: [
:id, :identifier, :_destroy, :artifact_name_pattern
:id, :identifier, :_destroy, :artifact_name_pattern, :build_suffix
]
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/libs/workflow_processors/workflow_run_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def re_enqueue
attr_reader :workflow_run
delegate :in_progress?, :successful?, :failed?, :error?, :halted?, :artifacts_url, :started_at, :finished_at, to: :runner
delegate :github_integration?, :bitrise_integration?, :bitbucket_integration?, to: :integration
delegate :build_artifact_name_pattern, to: :workflow_run
delegate :artifact_name_pattern, to: :workflow_run

def update_status!
if successful?
Expand All @@ -50,7 +50,7 @@ def update_status!

memoize def runner
return GITHUB.new(external_workflow_run) if github_integration?
return BITRISE.new(workflow_run.ci_cd_provider, external_workflow_run, build_artifact_name_pattern) if bitrise_integration?
return BITRISE.new(workflow_run.ci_cd_provider, external_workflow_run, artifact_name_pattern) if bitrise_integration?
BITBUCKET.new(external_workflow_run) if bitbucket_integration?
end

Expand Down
8 changes: 4 additions & 4 deletions app/models/app_store_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def retrigger!
end

def prepare_for_release!
result = provider.prepare_release(build_number, version_name, staged_rollout?, notes, true)
result = provider.prepare_release(build_number, release_version, staged_rollout?, notes, true)

unless result.ok?
case result.error.reason
Expand All @@ -172,7 +172,7 @@ def prepare_for_release!
return
end

unless result.value!.valid?(build_number, version_name, staged_rollout?)
unless result.value!.valid?(build_number, release_version, staged_rollout?)
fail!(reason: :invalid_release)
return
end
Expand All @@ -182,7 +182,7 @@ def prepare_for_release!
end

def submit!
result = provider.submit_release(build_number, version_name)
result = provider.submit_release(build_number, release_version)

unless result.ok?
return update(failure_reason: result.error.reason) if result.error.reason.in? RETRYABLE_FAILURE_REASONS
Expand Down Expand Up @@ -221,7 +221,7 @@ def update_external_release
end

def remove_from_review!
result = provider.remove_from_review(build_number, version_name)
result = provider.remove_from_review(build_number, release_version)

if result.ok?
update_store_info!(result.value!)
Expand Down
19 changes: 15 additions & 4 deletions app/models/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Build < ApplicationRecord
include Passportable
# include Sandboxable

BUILD_SUFFIX_SEPARATOR = "-"

belongs_to :release_platform_run
belongs_to :commit
belongs_to :workflow_run
Expand All @@ -37,19 +39,23 @@ class Build < ApplicationRecord
scope :ready, -> { where.not(generated_at: nil) }

delegate :android?, :ios?, :ci_cd_provider, :train, to: :release_platform_run
delegate :artifacts_url, :build_artifact_name_pattern, :kind, to: :workflow_run
delegate :artifacts_url, :artifact_name_pattern, :build_suffix, :kind, to: :workflow_run
delegate :notify!, to: :train

before_create :set_version_name
before_create :set_sequence_number

def build_version = version_name

def metadata = nil

def display_name
"#{version_name} (#{build_number})"
end

# the release version is the version without any suffix that could be present
def release_version
version_name&.split(BUILD_SUFFIX_SEPARATOR)&.first
end

def has_artifact?
artifact.present?
end
Expand Down Expand Up @@ -101,8 +107,13 @@ def set_sequence_number
self.sequence_number = release_platform_run.next_build_sequence_number
end

# the build's version name is the current release (platform run) version with an optional suffix
def set_version_name
self.version_name = [release_platform_run.release_version, build_suffix].compact.join(BUILD_SUFFIX_SEPARATOR)
end

def get_build_artifact
ci_cd_provider.get_artifact(artifacts_url, build_artifact_name_pattern, external_workflow_run_id: workflow_run.external_id)
ci_cd_provider.get_artifact(artifacts_url, artifact_name_pattern, external_workflow_run_id: workflow_run.external_id)
rescue Installations::Error => ex
raise ex unless ex.reason == :artifact_not_found
elog(ex)
Expand Down
2 changes: 1 addition & 1 deletion app/models/build_artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save_file!(artifact_stream)
end

def gen_filename(ext)
"#{app.slug}-#{build.build_version}-build#{ext}"
"#{app.slug}-#{build.version_name}-build#{ext}"
end

def get_filename
Expand Down
11 changes: 8 additions & 3 deletions app/models/config/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# id :bigint not null, primary key
# artifact_name_pattern :string
# build_suffix :string
# identifier :string
# kind :string
# name :string
Expand All @@ -18,13 +19,17 @@ class Config::Workflow < ApplicationRecord

enum :kind, {internal: "internal", release_candidate: "release_candidate"}
validates :identifier, :name, presence: true
validates :build_suffix, absence: true, if: :ios?

delegate :ios?, to: :release_platform_config

def as_json(options = {})
{
id: identifier,
name: name,
artifact_name_pattern: artifact_name_pattern,
kind: kind
name:,
artifact_name_pattern:,
kind:,
build_suffix:
}
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/play_store_rollout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def halt_release!
with_lock do
return unless may_halt?

result = provider.halt_release(submission_channel_id, build_number, version_name, last_rollout_percentage, retry_on_review_fail: true)
result = provider.halt_release(submission_channel_id, build_number, release_version, last_rollout_percentage, retry_on_review_fail: true)
if result.ok?
halt!
else
Expand Down Expand Up @@ -158,7 +158,7 @@ def fail!(error, review_failure: false)
end

def rollout(value, retry_on_review_fail: false)
provider.rollout_release(submission_channel_id, build_number, version_name, value, nil, retry_on_review_fail:)
provider.rollout_release(submission_channel_id, build_number, release_version, value, nil, retry_on_review_fail:)
end

def on_start!
Expand Down
3 changes: 2 additions & 1 deletion app/models/play_store_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def retrigger!

def prepare_for_release!
# return mock_prepare_for_release_for_play_store! if sandbox_mode?
result = provider.create_draft_release(submission_channel_id, build_number, version_name, notes, retry_on_review_fail: internal_channel?)
result = provider.create_draft_release(submission_channel_id, build_number, release_version, notes, retry_on_review_fail: internal_channel?)

if result.ok?
finish_prepare!
update_external_status
Expand Down
2 changes: 1 addition & 1 deletion app/models/production_release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def tester_notes? = false
def release_notes? = true

def version_bump_required?
return false if release_platform_run.release_version.to_semverish > build.version_name.to_semverish
return false if release_platform_run.release_version.to_semverish > build.release_version.to_semverish
return true if finished?
return true if active?
return true if store_submission.post_review?
Expand Down
6 changes: 3 additions & 3 deletions app/models/store_rollout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class StoreRollout < ApplicationRecord
enum :status, STATES

delegate :parent_release, :build, :external_link, to: :store_submission
delegate :version_name, :build_number, to: :build
delegate :release_version, :build_number, to: :build
delegate :train, :platform, to: :release_platform_run
delegate :notify!, to: :train
delegate :stale?, :actionable?, to: :parent_release
Expand All @@ -60,7 +60,7 @@ def reached_last_stage? = next_rollout_percentage.nil?

def release_info
{
build_version: version_name,
build_version: release_version,
build_number:,
updated_at:,
platform:,
Expand Down Expand Up @@ -142,7 +142,7 @@ def update_stage(stage, finish_rollout: false)
def stamp_data
{
current_stage: stage,
version: version_name,
version: release_version,
build_number: build_number,
rollout_percentage: last_rollout_percentage_fmt
}
Expand Down
4 changes: 2 additions & 2 deletions app/models/store_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StoreSubmission < ApplicationRecord

delegate :release_metadata, :train, :release, :app, :platform, to: :release_platform_run
delegate :notify!, to: :train
delegate :version_name, :build_number, to: :build
delegate :release_version, :build_number, to: :build
delegate :actionable?, to: :parent_release

scope :sequential, -> { reorder("store_submissions.sequence_number ASC") }
Expand Down Expand Up @@ -185,7 +185,7 @@ def set_rejected_at!

def stamp_data(failure_message: nil)
{
version: version_name,
version: release_version,
build_number: build_number,
failure_reason: (get_failure_message(failure_message) if failure_reason.present?)
}
Expand Down
15 changes: 6 additions & 9 deletions app/models/workflow_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class WorkflowRun < ApplicationRecord
belongs_to :commit
has_one :build, dependent: :destroy

delegate :organization, :app, :ci_cd_provider, :train, :release_version, :release_branch, :release, :platform, to: :release_platform_run
delegate :organization, :app, :ci_cd_provider, :train, :release_branch, :release, :platform, to: :release_platform_run
delegate :notify!, to: :train
delegate :commit_hash, to: :commit
delegate :build_suffix, :artifact_name_pattern, to: :conf

STAMPABLE_REASONS = %w[
triggered
Expand Down Expand Up @@ -118,7 +119,7 @@ def self.create_and_trigger!(workflow_config, triggering_release, commit, releas
release_platform_run:,
commit:,
kind: workflow_config.kind)
workflow_run.create_build!(version_name: workflow_run.release_version, release_platform_run:, commit:)
workflow_run.create_build!(release_platform_run:, commit:)
workflow_run.initiate!
end

Expand Down Expand Up @@ -159,10 +160,6 @@ def cancel_external_workflow!
ci_cd_provider.cancel_workflow_run!(external_id)
end

def build_artifact_name_pattern
workflow_config["artifact_name_pattern"]
end

def find_build
store_provider.find_build(build.build_number)
end
Expand Down Expand Up @@ -212,11 +209,11 @@ def trigger_external_run!
end

def update_build_number!
build.update!(build_number: app.bump_build_number!(release_version:))
build.update!(build_number: app.bump_build_number!(release_version: build.release_version))
end

def workflow_inputs
data = {version_code: build.build_number, build_version: release_version}
data = {version_code: build.build_number, build_version: build.version_name}
data[:build_notes] = triggering_release.tester_notes if organization.build_notes_in_workflow?
data
end
Expand Down Expand Up @@ -287,7 +284,7 @@ def stamp_data
commit_url: commit.url,
ref: external_number,
url: external_url,
version_name: release_version,
version_name: release_platform_run.release_version,
build_number: build&.build_number
}
end
Expand Down
Loading
Loading