From f23802908d8487a80aad398c60f42c5353a10806 Mon Sep 17 00:00:00 2001 From: Nivedita Priyadarshini Date: Fri, 20 Oct 2023 21:10:05 +0530 Subject: [PATCH] Add config to manage release tags and allow tag suffix for a train (#573) --- app/controllers/trains_controller.rb | 8 ++- .../domain/release_suffix_help_controller.js | 7 +-- app/models/release.rb | 5 +- app/models/train.rb | 2 + app/views/trains/_form.html.erb | 1 + app/views/trains/_release_tag_form.html.erb | 48 ++++++++++++++++++ ...4546_add_config_to_tag_release_to_train.rb | 10 ++++ db/schema.rb | 4 +- spec/factories/trains.rb | 2 + spec/models/release_spec.rb | 50 +++++++++++++++++++ 10 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 app/views/trains/_release_tag_form.html.erb create mode 100644 db/migrate/20231020054546_add_config_to_tag_release_to_train.rb diff --git a/app/controllers/trains_controller.rb b/app/controllers/trains_controller.rb index 1dd32dc84..b5441c4a1 100644 --- a/app/controllers/trains_controller.rb +++ b/app/controllers/trains_controller.rb @@ -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 @@ -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 diff --git a/app/javascript/controllers/domain/release_suffix_help_controller.js b/app/javascript/controllers/domain/release_suffix_help_controller.js index 9cb08de3f..6d6abaac6 100644 --- a/app/javascript/controllers/domain/release_suffix_help_controller.js +++ b/app/javascript/controllers/domain/release_suffix_help_controller.js @@ -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 = [ @@ -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; } } } diff --git a/app/models/release.rb b/app/models/release.rb index f82d1b55b..58b1e5912 100644 --- a/app/models/release.rb +++ b/app/models/release.rb @@ -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) @@ -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 diff --git a/app/models/train.rb b/app/models/train.rb index 4a8dea74b..7077432d1 100644 --- a/app/models/train.rb +++ b/app/models/train.rb @@ -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 diff --git a/app/views/trains/_form.html.erb b/app/views/trains/_form.html.erb index 57ad741d3..09364ae66 100644 --- a/app/views/trains/_form.html.erb +++ b/app/views/trains/_form.html.erb @@ -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 %> diff --git a/app/views/trains/_release_tag_form.html.erb b/app/views/trains/_release_tag_form.html.erb new file mode 100644 index 000000000..41047d6cf --- /dev/null +++ b/app/views/trains/_release_tag_form.html.erb @@ -0,0 +1,48 @@ +
+
Tag Your Releases
+
+ By default, a tag is created at the end of the release with the final version of the release.
+ You can turn of creation of tag. Or, you can add an optional suffix to your tags. +
+
+
+
+ <%= 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" %> + +
+ +
+
+ +
data-controller="help-text"> +
+ <%= 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" } %> +
+ This is appended to the tag name of the release, as follows:  + +
+
+
+
+
+
diff --git a/db/migrate/20231020054546_add_config_to_tag_release_to_train.rb b/db/migrate/20231020054546_add_config_to_tag_release_to_train.rb new file mode 100644 index 000000000..f30431d12 --- /dev/null +++ b/db/migrate/20231020054546_add_config_to_tag_release_to_train.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 14527bbb0..e2538b33d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_10_13_071746) do +ActiveRecord::Schema[7.0].define(version: 2023_10_20_054546) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "pgcrypto" @@ -522,6 +522,8 @@ t.boolean "tag_platform_releases", default: false t.boolean "tag_all_store_releases", default: false t.boolean "compact_build_notes", default: false + t.boolean "tag_releases", default: true + t.string "tag_suffix" t.index ["app_id"], name: "index_trains_on_app_id" end diff --git a/spec/factories/trains.rb b/spec/factories/trains.rb index bdf539d0e..d755855c9 100644 --- a/spec/factories/trains.rb +++ b/spec/factories/trains.rb @@ -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" } diff --git a/spec/models/release_spec.rb b/spec/models/release_spec.rb index d858cfcdd..921c5e6aa 100644 --- a/spec/models/release_spec.rb +++ b/spec/models/release_spec.rb @@ -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