vector-im/element-x-ios/issues/13 - Towncrier setup for PR builds

This commit is contained in:
Stefan Ceriu
2022-05-09 16:27:40 +03:00
committed by Stefan Ceriu
parent 73910409da
commit db1114d381
10 changed files with 235 additions and 24 deletions
+29 -15
View File
@@ -1,4 +1,5 @@
require 'yaml'
require_relative 'changelog'
lane :alpha do
@@ -24,7 +25,9 @@ lane :alpha do
adhoc: true
)
update_app_icon()
version = ENV["GITHUB_PR_NUMBER"]
update_app_icon(caption_text: "PR #{version}")
build_ios_app(
clean: true,
@@ -39,18 +42,10 @@ lane :alpha do
upload_to_diawi()
export_version_changes(version: version)
end
private_lane :config_xcodegen_alpha do
target_file_path = "../ElementX/SupportingFiles/target.yml"
data = YAML.load_file target_file_path
data["targets"]["ElementX"]["settings"]["base"]["PRODUCT_NAME"] = "ElementX PR"
data["targets"]["ElementX"]["settings"]["base"]["PRODUCT_BUNDLE_IDENTIFIER"] = "io.element.elementx.pr"
File.open(target_file_path, 'w') { |f| YAML.dump(data, f) }
end
lane :build_and_publish_on_github do
ios_adhoc()
@@ -102,6 +97,26 @@ lane :tests do
end
private_lane :export_version_changes do |options|
Dir.chdir("..") do
Changelog.update_topmost_section(version: options[:version], additional_entries: {})
changelog = Changelog.extract_first_section
# Pushing them directly into the $GITHUB_ENV results in errors
# https://trstringer.com/github-actions-multiline-strings/
# String substitution and here documents failed too
sh("echo '#{changelog}' >> version_changes.md")
end
end
private_lane :config_xcodegen_alpha do
target_file_path = "../ElementX/SupportingFiles/target.yml"
data = YAML.load_file target_file_path
data["targets"]["ElementX"]["settings"]["base"]["PRODUCT_NAME"] = "ElementX PR"
data["targets"]["ElementX"]["settings"]["base"]["PRODUCT_BUNDLE_IDENTIFIER"] = "io.element.elementx.pr"
File.open(target_file_path, 'w') { |f| YAML.dump(data, f) }
end
desc "Upload IPA to Diawi"
private_lane :upload_to_diawi do
api_token = ENV["DIAWI_API_TOKEN"]
@@ -153,10 +168,9 @@ private_lane :release_to_github do
)
end
private_lane :update_app_icon do
pr_number = ENV["GITHUB_PR_NUMBER"]
UI.user_error!("Invalid GitHub PR number.") unless !pr_number.to_s.empty?
caption_text="PR ##{pr_number}"
private_lane :update_app_icon do |options|
caption_text = options[:caption_text]
UI.user_error!("Invalid caption text.") unless !caption_text.to_s.empty?
Dir.glob("../ElementX/Resources/Assets.xcassets/AppIcon.appiconset/**/*.png") do |file_name|
# Change the icons color
+8
View File
@@ -53,6 +53,14 @@ For _fastlane_ installation instructions, see [Installing _fastlane_](https://do
### export_release_notes
```sh
[bundle exec] fastlane export_release_notes
```
----
This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run.
+63
View File
@@ -0,0 +1,63 @@
# Copyright 2020 New Vector Ltd - All Rights Reserved
# Unauthorized copying of this file, via any medium is strictly prohibited
# Proprietary and confidential
# frozen_string_literal: true
require "tempfile"
require "fileutils"
require "date"
# Helper methods to handle updates of the Changelog file
#
module Changelog
CHANGES_SEPARATOR_REGEX = /^\#\#\ Changes/.freeze
FILE = "CHANGES.md"
# Update the topmost section of the changelog to put version+date in title + add entry for dependency updates
#
# @param [String] version The version that we are releasing to use in the new title of the first section
# @param [Hash<String, Array<String>>] additional_entries
# List of lines/entries to add under the each subsection of the first section
# The keys of the hash are the name of the subsections, without trailing`:`, e.g. "Improvements".
# The values are the list of lines to add to that subsection
# (the ` * ` bullet point will be added automatically for each line)
#
def self.update_topmost_section(version:, additional_entries:)
# Create temporary towncrier changelog entries for additional entries
# Use a low index to make them appear first
# Those additional entries are basically dependency updates
entry_count = 0
additional_entries.each do |subsection, entries|
entries.each do |entry|
file = "changelog.d/x-nolink-#{entry_count}.#{subsection}"
File.write(file, "#{entry}")
Git.add!(files: file)
Git.commit!(message: "changelog.d: #{entry}", add_all: true)
entry_count += 1
end
end
# Let towncrier update the change
system("towncrier", "build", "--version", "#{version}", "--yes")
end
# Returns the first section of the Changelog, corresponding to the changes in the latest version
#
def self.extract_first_section
lines = []
File.open(FILE, "r") do |file|
section_index = 0
file.each_line do |line|
is_separator_line = (line.chomp =~ CHANGES_SEPARATOR_REGEX)
section_index += 1 if is_separator_line
break if section_index >= 2
lines.append(line) if section_index == 1
end
end
lines[0..-2].join # Remove last line (title of section 2)
end
end