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

Support proper trunk flow #675

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def changelog_from

def apply_help_text
return if change_queue_commits.blank?
"#{change_queue_commits_count} commit(s) in the queue. These will be automatically applied in #{time_in_words(build_queue&.scheduled_at)} or after #{build_queue&.build_queue_size} commits."
if release.train.trunk?
"#{change_queue_commits_count} commit(s) in the queue."
else
"#{change_queue_commits_count} commit(s) in the queue. These will be automatically applied in #{time_in_words(build_queue&.scheduled_at)} or after #{build_queue&.build_queue_size} commits."
end
end
end
19 changes: 16 additions & 3 deletions app/controllers/integration_listeners/bitbucket_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,29 @@ def events
private

def handle_push
result = Action.process_push_webhook(train, push_params)
result =
if train.trunk?
Action.process_commit_webhook(train, push_params)
elsif train.product_v2?
Action.process_push_webhook(train, push_params)
else
WebhookHandlers::Push.process(train, push_params)
end

response = result.ok? ? result.value! : Response.new(:unprocessable_entity, "Error processing push, error: #{result.error}")

Rails.logger.debug response.body
head response.status
end

def handle_pull_request
result = Action.process_pull_request_webhook(train, pull_request_params)
response = result.ok? ? result.value! : Response.new(:unprocessable_entity, "Error processing pull request")
response =
if train.product_v2?
result = Action.process_pull_request_webhook(train, pull_request_params)
result.ok? ? result.value! : Response.new(:unprocessable_entity, "Error processing pull request")
else
WebhookHandlers::PullRequest.process(train, pull_request_params)
end

Rails.logger.debug response.body
head response.status
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/integration_listeners/github_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def handle_ping

def handle_push
response =
if train.product_v2?
if train.trunk?
result = Action.process_commit_webhook(train, push_params)
result.ok? ? result.value! : Response.new(:unprocessable_entity, "Error processing commit")
elsif train.product_v2?
result = Action.process_push_webhook(train, push_params)
result.ok? ? result.value! : Response.new(:unprocessable_entity, "Error processing push")
else
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/integration_listeners/gitlab_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def handle_ping

def handle_push
response =
if train.product_v2?
if train.trunk?
result = Action.process_commit_webhook(train, push_params)
result.ok? ? result.value! : Response.new(:unprocessable_entity, "Error processing push")
elsif train.product_v2?
result = Action.process_push_webhook(train, push_params)
result.ok? ? result.value! : Response.new(:unprocessable_entity, "Error processing push")
else
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/trains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class TrainsController < SignedInApplicationController

def new
@train = @app.trains.new
@train.build_queue_wait_time_value = 0
@train.build_queue_size = 0
end

def edit
Expand All @@ -29,7 +31,6 @@ def rules

def create
@train = @app.trains.new(parsed_train_params)

if @train.save
new_train_redirect
else
Expand Down
25 changes: 23 additions & 2 deletions app/javascript/controllers/branching_selector_controller.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
import {Controller} from "@hotwired/stimulus";

const STRATEGIES = {
trunk: "trunk",
almost_trunk: "almost_trunk",
release_backmerge: "release_backmerge",
parallel_working: "parallel_working"
}
export default class extends Controller {
static targets = ["branchingStrategy", "almostTrunk", "releaseBackMerge", "parallelBranches", "backmerge"]
static targets = ["branchingStrategy", "almostTrunk", "trunk", "releaseBackMerge", "parallelBranches", "backmerge", "buildQueueToggle"]
static outlets = ["domain--build-queue-help", "domain--release-schedule-help"]

initialize() {
this.showCorrectInputs()
}

change() {
this.showCorrectInputs()

if (this.hasDomainBuildQueueHelpOutlet) {
this.domainBuildQueueHelpOutlet.branchingStrategyValue = this.branchingStrategyTarget.value
}
}

showCorrectInputs() {
this.__resetFields()
const selectedBranchingStrategy = this.branchingStrategyTarget.value

if (selectedBranchingStrategy === STRATEGIES.almost_trunk) {

if (selectedBranchingStrategy === STRATEGIES.trunk) {
this.disableBuildQueueToggle()
this.__hideBackmergeConfig()
} else if (selectedBranchingStrategy === STRATEGIES.almost_trunk) {
this.almostTrunkTarget.hidden = false
this.enableBuildQueueToggle()
this.__showBackmergeConfig()
} else if (selectedBranchingStrategy === STRATEGIES.release_backmerge) {
this.releaseBackMergeTarget.hidden = false
this.enableBuildQueueToggle()
this.__hideBackmergeConfig()
} else if (selectedBranchingStrategy === STRATEGIES.parallel_working) {
this.parallelBranchesTarget.hidden = false
this.enableBuildQueueToggle()
this.__hideBackmergeConfig()
}
}
Expand All @@ -45,4 +58,12 @@ export default class extends Controller {
__showBackmergeConfig() {
this.backmergeTarget.hidden = false
}

disableBuildQueueToggle() {
this.buildQueueToggleTarget.disabled = true
}

enableBuildQueueToggle() {
this.buildQueueToggleTarget.disabled = false;
}
}
23 changes: 21 additions & 2 deletions app/javascript/controllers/domain/build_queue_help_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ const BASE_HELP_TEXT = "Changes will be applied to the release every "
const ERR_HELP_TEXT = "You must set a valid build queue config when it is enabled"

export default class extends Controller {
static targets = ["checkbox", "size", "waitTimeValue", "waitTimeUnit", "output", "errOutput"];
static targets = ["checkbox", "size", "waitTimeValue", "waitTimeUnit", "output", "errOutput"]
static values = {
branchingStrategy: String
}

initialize() {
this.change();
}

branchingStrategyValueChanged() {
this.change();
}

change() {
this.__resetContents()

Expand All @@ -29,7 +36,13 @@ export default class extends Controller {
const waitTimeUnit = this.waitTimeUnitTarget.value
const waitTimeValue = this.waitTimeValueTarget.value

this.outputTarget.textContent = `${BASE_HELP_TEXT}${waitTimeValue} ${waitTimeUnit} OR ${size} commits`
if (this.branchingStrategyValue === "trunk") {
this.outputTarget.textContent = "Changes will be applied manually"
this.__changeInputStates(true)
} else {
this.outputTarget.textContent = `${BASE_HELP_TEXT}${waitTimeValue} ${waitTimeUnit} OR ${size} commits`
this.__changeInputStates(false)
}
}

__resetContents() {
Expand All @@ -40,4 +53,10 @@ export default class extends Controller {
__isEmptyConfig() {
return this.sizeTarget.value === "" || this.waitTimeUnitTarget.value === "" || this.waitTimeValueTarget.value === ""
}

__changeInputStates(enabled) {
this.sizeTarget.disabled = enabled
this.waitTimeValueTarget.disabled = enabled
this.waitTimeUnitTarget.disabled = enabled
}
}
10 changes: 10 additions & 0 deletions app/jobs/create_version_tag_job.rb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this is entirely dead code.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateVersionTagJob < ApplicationJob
queue_as :default

def perform(commit_hash, version, working_branch, vcs_provider)
Triggers::Trunk.call(commit_hash, version, working_branch, vcs_provider)
rescue Installations::Github::Error => e
Rails.logger.error("Failed to create version tag: #{e.message}")
raise
end
end
11 changes: 11 additions & 0 deletions app/jobs/release_platform_runs/trigger_workflow_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module ReleasePlatformRuns
class TriggerWorkflowJob < ApplicationJob
queue_as :high

def perform(platform_run_id, commit_id)
platform_run = ReleasePlatformRun.find(platform_run_id)
commit = Commit.find(commit_id)
Coordinators::CreateBetaRelease.trigger_workflows(platform_run, commit)
end
end
end
9 changes: 9 additions & 0 deletions app/jobs/webhooks/commit_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Webhooks::CommitJob < ApplicationJob
queue_as :high

def perform(train_run_id, head_commit, rest_commits)
release = Release.find(train_run_id)
return unless release.committable?
Signal.commit_has_landed!(release, head_commit)
end
end
8 changes: 8 additions & 0 deletions app/libs/coordinators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def self.commits_have_landed!(release, head_commit, rest_commits)
Coordinators::ProcessCommits.call(release, head_commit, rest_commits)
end

def self.commit_has_landed!(release, head_commit)
Coordinators::ProcessCommit.call(release, head_commit)
end

def self.build_queue_can_be_applied!(build_queue)
Coordinators::ApplyBuildQueue.call(build_queue)
end
Expand Down Expand Up @@ -89,6 +93,10 @@ def self.process_push_webhook(train, push_params)
Res.new { Coordinators::Webhooks::Push.process(train, push_params) }
end

def self.process_commit_webhook(train, commit_params)
Res.new { Coordinators::Webhooks::Commit.process(train, commit_params) }
end

def self.process_pull_request_webhook(train, pull_request_params)
Res.new { Coordinators::Webhooks::PullRequest.process(train, pull_request_params) }
end
Expand Down
32 changes: 31 additions & 1 deletion app/libs/coordinators/create_beta_release.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
class Coordinators::CreateBetaRelease
def self.call(release_platform_run, commit)
new(release_platform_run, commit).call

if release_platform_run.release.release_platform_runs.all? { |run| run.beta_releases.exists?(commit: commit) } &&
release_platform_run.train.trunk?

tag_name = "v#{release_platform_run.release_version}"
release_platform_run.train.create_tag!(tag_name, commit.commit_hash)

release_platform_run.release.release_platform_runs.each do |run|
run.update!(tag_name: tag_name)
ReleasePlatformRuns::TriggerWorkflowJob.perform_later(run.id, commit.id)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: the same issue applies here, as internal releases, but I'm also not certain what the need of triggering workflow job is here? The workflow run is normally triggered here anyway.

Could you help me understand the reasoning behind this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrong approach was used when this was implemented. This has now been changed and it no longer handles the logic for creating and updating tags

end

def initialize(release_platform_run, commit)
Expand All @@ -18,12 +30,30 @@ def call
release_platform_run.update_last_commit!(commit)
release_platform_run.bump_version!
release_platform_run.correct_version!

beta_release = release_platform_run.beta_releases.create!(config:, previous:, commit:)
WorkflowRun.create_and_trigger!(rc_workflow_config, beta_release, commit, release_platform_run)

unless release_platform_run.train.trunk?
WorkflowRun.create_and_trigger!(rc_workflow_config, beta_release, commit, release_platform_run)
end

beta_release.previous&.workflow_run&.cancel_workflow!
end
end

def self.trigger_workflows(release_platform_run, commit)
return if release_platform_run.tag_name.blank?
return unless release_platform_run.train.trunk?

beta_release = release_platform_run.beta_releases.find_by(commit: commit)
WorkflowRun.create_and_trigger!(
release_platform_run.conf.release_candidate_workflow,
beta_release,
commit,
release_platform_run
)
end

private

def previous
Expand Down
24 changes: 24 additions & 0 deletions app/libs/coordinators/create_internal_release.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
class Coordinators::CreateInternalRelease
def self.call(release_platform_run, commit)
new(release_platform_run, commit).call

if release_platform_run.release.release_platform_runs.all? { |run| run.internal_releases.exists?(commit: commit) } &&
release_platform_run.train.trunk?

tag_name = "v#{release_platform_run.release_version}"
release_platform_run.train.create_tag!(tag_name, commit.commit_hash)

release_platform_run.release.release_platform_runs.each do |run|
run.update!(tag_name: tag_name)
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: I think this creation & updating of tag should happen during the application of the commit, not here. This is about creating internal releases and its details. The tagging is about the commit, not about the builds.

end

def initialize(release_platform_run, commit)
Expand All @@ -21,6 +32,19 @@ def call
end
end

def self.trigger_workflows(release_platform_run, commit)
return if release_platform_run.tag_name.blank?
return unless release_platform_run.train.trunk?

internal_release = release_platform_run.internal_releases.find_by(commit: commit)
WorkflowRun.create_and_trigger!(
release_platform_run.conf.pick_internal_workflow,
internal_release,
commit,
release_platform_run
)
end

private

def previous
Expand Down
Loading