Skip to content

Commit

Permalink
Add config to manage release tags and allow tag suffix for a train (#573
Browse files Browse the repository at this point in the history
)
  • Loading branch information
nid90 authored Oct 20, 2023
1 parent 1da2702 commit f238029
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 7 deletions.
8 changes: 6 additions & 2 deletions app/controllers/trains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def train_params
:compact_build_notes,
:tag_all_store_releases,
:tag_platform_releases,
:notifications_enabled
:notifications_enabled,
:tag_releases,
:tag_suffix
)
end

Expand Down Expand Up @@ -150,7 +152,9 @@ def train_update_params
:compact_build_notes,
:tag_all_store_releases,
:tag_platform_releases,
:notifications_enabled
:notifications_enabled,
:tag_releases,
:tag_suffix
)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {Controller} from "@hotwired/stimulus";
export default class extends Controller {
static values = {
version: String,
versionSuffixCurrent: String
versionSuffixCurrent: String,
prefix: String
}

static targets = [
Expand All @@ -21,9 +22,9 @@ export default class extends Controller {

__set(suffix) {
if (suffix !== "") {
this.helpTextTarget.innerHTML = this.versionValue + "-" + suffix;
this.helpTextTarget.innerHTML = this.prefixValue + this.versionValue + "-" + suffix;
} else {
this.helpTextTarget.innerHTML = this.versionValue;
this.helpTextTarget.innerHTML = this.prefixValue + this.versionValue;
}
}
}
5 changes: 4 additions & 1 deletion app/models/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def release_branch
# recursively attempt to create a release until a unique one gets created
# it *can* get expensive in the worst-case scenario, so ideally invoke this in a bg job
def create_release!(input_tag_name = base_tag_name)
return unless train.tag_releases?
return if tag_name.present?
train.create_release!(release_branch, input_tag_name)
update!(tag_name: input_tag_name)
Expand Down Expand Up @@ -332,7 +333,9 @@ def ongoing?
private

def base_tag_name
"v#{release_version}"
tag = "v#{release_version}"
tag += "-" + train.tag_suffix if train.tag_suffix.present?
tag
end

def create_platform_runs
Expand Down
2 changes: 2 additions & 0 deletions app/models/train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# status :string not null
# tag_all_store_releases :boolean default(FALSE)
# tag_platform_releases :boolean default(FALSE)
# tag_releases :boolean default(TRUE)
# tag_suffix :string
# version_current :string
# version_seeded_with :string
# working_branch :string
Expand Down
1 change: 1 addition & 0 deletions app/views/trains/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<%= render partial: "backmerge_config_form", locals: { form: } %>
<%= render partial: "manual_release_form", locals: { form: } %>
<%= render partial: "compact_build_notes_form", locals: { form: } %>
<%= render partial: "release_tag_form", locals: { form: } %>
<% if @app.cross_platform? %>
<%= render partial: "store_tags_form", locals: { form: } %>
<% end %>
Expand Down
48 changes: 48 additions & 0 deletions app/views/trains/_release_tag_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<article data-controller="reveal">
<div class="text-xl text-slate-600 font-medium mt-2 mb-1">Tag Your Releases</div>
<div class="text-sm mt-1 mb-6">
By default, a tag is created at the end of the release with the final version of the release.<br/>
You can turn of creation of tag. Or, you can add an optional suffix to your tags.
</div>
<section data-controller="toggle-switch"
data-toggle-switch-on-label-value="Release Tag enabled"
data-toggle-switch-off-label-value="Release Tag disabled">
<div class="flex items-center">
<div class="form-switch">
<%= form.check_box :tag_releases,
{ id: "tag_releases-switch",
class: "sr-only",
data: { action: "toggle-switch#change reveal#toggle",
toggle_switch_target: "checkbox" } },
"true", "false" %>
<label class="bg-slate-400" for="tag_releases-switch">
<span class="bg-white shadow-sm" aria-hidden="true"></span>
<span class="sr-only">Switch label</span>
</label>
</div>

<div class="text-sm text-slate-600 ml-2" data-toggle-switch-target="output"></div>
</div>

<section class="mt-6" data-reveal
<%= "hidden" unless @train.tag_releases? %> data-controller="help-text">
<div data-controller="domain--release-suffix-help"
data-domain--release-suffix-help-version-value="<%= @train.version_current || @train.version_seeded_with %>"
data-domain--release-suffix-help-version-suffix-current-value="<%= @train.tag_suffix %>"
data-domain--release-suffix-help-prefix-value="v">
<%= form.label :tag_suffix, class: "block text-sm font-medium mb-1" %>
<%= form.text_field :tag_suffix,
class: "form-input w-full",
placeholder: "Eg: nightly",
autocomplete: "off",
data: { domain__release_suffix_help_target: "input",
action: "domain--release-suffix-help#set" } %>
<div class="text-sm mt-1">
This is appended to the <strong>tag name</strong> of the release, as follows:&nbsp;
<span class="font-mono" data-domain--release-suffix-help-target="helpText"></span>
</div>
</div>
</section>
</section>
<div class="border-t border-dashed border-slate-200 pb-8 mt-8"></div>
</article>
10 changes: 10 additions & 0 deletions db/migrate/20231020054546_add_config_to_tag_release_to_train.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddConfigToTagReleaseToTrain < ActiveRecord::Migration[7.0]
def change
safety_assured do
change_table :trains, bulk: true do |t|
t.column :tag_releases, :boolean, default: true
t.column :tag_suffix, :string
end
end
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions spec/factories/trains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
manual_release { false }
tag_platform_releases { false }
tag_all_store_releases { false }
tag_releases { true }
tag_suffix { nil }

trait :draft do
status { "draft" }
Expand Down
50 changes: 50 additions & 0 deletions spec/models/release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,56 @@
expect(release.tag_name).to eq("v1.2.3-#{commit.short_sha}-#{now}")
end
end

context "when tag suffix" do
let(:suffix) { "nightly" }
let(:train) { create(:train, :active, tag_suffix: suffix) }

it "saves a new tag with the base name + suffix" do
allow_any_instance_of(GithubIntegration).to receive(:create_release!)
commit = create(:commit, :without_trigger, release:)
create(:step_run, release_platform_run:, commit:)

release.create_release!
expect(release.tag_name).to eq("v1.2.3-#{suffix}")
end

it "saves base name + suffix + last commit sha" do
raise_times(GithubIntegration, Installations::Errors::TaggedReleaseAlreadyExists, :create_release!, 1)
commit = create(:commit, :without_trigger, release:)
create(:step_run, release_platform_run:, commit:)

release.create_release!
expect(release.tag_name).to eq("v1.2.3-#{suffix}-#{commit.short_sha}")
end

it "saves base name + suffix + last commit sha + time" do
raise_times(GithubIntegration, Installations::Errors::TaggedReleaseAlreadyExists, :create_release!, 2)

freeze_time do
now = Time.now.to_i
commit = create(:commit, :without_trigger, release:)
create(:step_run, release_platform_run:, commit:)

release.create_release!
expect(release.tag_name).to eq("v1.2.3-#{suffix}-#{commit.short_sha}-#{now}")
end
end
end

context "when release tag disabled" do
let(:train) { create(:train, :active, tag_releases: false) }

it "does not create tag" do
allow_any_instance_of(GithubIntegration).to receive(:create_release!)
commit = create(:commit, :without_trigger, release:)
create(:step_run, release_platform_run:, commit:)

release.create_release!
expect_any_instance_of(GithubIntegration).not_to receive(:create_release!)
expect(release.tag_name).to be_nil
end
end
end

describe "#stop!" do
Expand Down

0 comments on commit f238029

Please sign in to comment.