From b0a2ce97c8e995a0888fa3945a074e388fb03fca Mon Sep 17 00:00:00 2001 From: Pierre-Yves Lapersonne Date: Mon, 5 Aug 2024 14:39:15 +0200 Subject: [PATCH] ci: GitHub comment publication for TestFlight alpha builds Signed-off-by: Pierre-Yves Lapersonne --- Gemfile | 4 +-- Gemfile.lock | 5 +++ Showcase/fastlane/Fastfile | 69 ++++++++++++++++++++++++++++++++++++-- THIRD_PARTY.md | 53 ++++++++++++++++++----------- 4 files changed, 107 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index 5a936cc19f..14dbd8e864 100644 --- a/Gemfile +++ b/Gemfile @@ -14,11 +14,11 @@ source "https://rubygems.org" gem 'cocoapods', '1.15.2' - gem 'fastlane', '2.221.1' gem 'fastlane-plugin-changelog', '0.16.0' gem 'fastlane-plugin-mattermost', '1.3.2' - +gem 'json', '2.7.2' +gem 'net-http', '0.4.1' gem 'xcode-install', '2.8.1' plugins_path = File.join(File.dirname(__FILE__), 'Showcase/fastlane', 'Pluginfile') diff --git a/Gemfile.lock b/Gemfile.lock index c814e0512d..49d714a43c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -238,6 +238,8 @@ GEM nanaimo (0.3.0) nap (1.1.0) naturally (2.2.1) + net-http (0.4.1) + uri netrc (0.11.0) nkf (0.2.0) optparse (0.5.0) @@ -280,6 +282,7 @@ GEM concurrent-ruby (~> 1.0) uber (0.1.0) unicode-display_width (2.5.0) + uri (0.13.0) word_wrap (1.0.0) xcode-install (2.8.1) claide (>= 0.9.1) @@ -314,6 +317,8 @@ DEPENDENCIES fastlane (= 2.221.1) fastlane-plugin-changelog (= 0.16.0) fastlane-plugin-mattermost (= 1.3.2) + json (= 2.7.2) + net-http (= 0.4.1) xcode-install (= 2.8.1) BUNDLED WITH diff --git a/Showcase/fastlane/Fastfile b/Showcase/fastlane/Fastfile index a5d0891260..919136ac2b 100644 --- a/Showcase/fastlane/Fastfile +++ b/Showcase/fastlane/Fastfile @@ -11,6 +11,9 @@ # Software description: A SwiftUI components library with code examples for Orange Unified Design System # +require 'net/http' +require 'json' + # App features configuration # -------------------------- @@ -151,7 +154,15 @@ platform :ios do # ------------------------------------------------------------ desc "BUILD & UPLOAD TO TESTFLIGHT ALPHA APP" lane :alpha do |params| - puts "👉 Alpha (commit hash = '#{params[:commitHash]}, issue number = '#{params[:issueNumber]}')" + issues_numbers = params[:issueNumber] + puts "👉 Alpha (commit hash = '#{params[:commitHash]}, issue number = '#{issues_numbers}')" + + if issues_numbers.nil? || issues_numbers.empty? + puts "❌ Error: No issues numbers have been given for alpha builds, nothing will be done" + publish_mattermost_notification("⚙️ 😰 Tried to build alpha version without mentioning issues numbers!") + raise "Bad prerequisites error - missing pipeline variable" + end + Dir.chdir "../Showcase/Resources/Assets.xcassets" do sh "rm -Rf AppIconRelease.appiconset" sh "cp -R AppIconDev.appiconset AppIconRelease.appiconset" @@ -159,14 +170,14 @@ platform :ios do # CFBundleVersion and CFBundleShortVersionString must follow rules with integers and periods, should not change them # But still possible to change CFBundleDisplayName - new_display_name = "OUDS Showcase ALPHA (#{params[:issueNumber]})" + new_display_name = "OUDS Showcase ALPHA (#{issues_numbers})" puts "ℹ️ New display name version will be: '#{new_display_name}'" set_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "CFBundleDisplayName", value: new_display_name) # Details for the GUI in the app set_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "OUDSBuildType", value: "ALPHA") set_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "OUDSBuildTag", value: "#{params[:commitHash][0,7]}".strip) - set_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "OUDSBuildDetails", value: "#{params[:issueNumber]}") + set_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "OUDSBuildDetails", value: "#{issues_numbers}") build_and_upload(isAlpha: true, upload: true) end @@ -228,6 +239,7 @@ platform :ios do update_build_number build upload(type: "alpha") + public_github_notifications_build_details else # Beta case (not production too), detailSymbol should be here commit hash detailSymbol = params[:detailSymbol] @@ -457,6 +469,57 @@ platform :ios do ) end + # Send a comment to the GitHub related GitHub issues about a new available build. + # Will find in Info.plist of demo app all the suitable needed details. + def public_github_notifications_build_details + build_version = get_app_version + build_number = get_build_number(xcodeproj: OUDS_PROJECT) + build_display_name = get_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "CFBundleDisplayName") + build_type = get_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "OUDSBuildType") + build_tag = get_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "OUDSBuildTag") + build_details = get_info_plist_value(path: "#{Dir.pwd}/../Showcase/Info.plist", key: "OUDSBuildDetails") + + build_issues_numbers = build_details.scan(/\d+/).map(&:to_i) + + build_issues_numbers.each do |issue_number| + uri = URI("https://api.github.com/repos//Orange-OpenSource/ouds-ios/issues/#{number}") + response = Net::HTTP.get(uri) + issue = JSON.parse(response) + + if issue['message'] == 'Not Found' + puts "❌ Error: Issue '#{number}' does not exist" + else + + comment_to_upload=<<-EOF +📣 New TestFlight ALPHA upload 🚀 +- Display name: '#{build_display_name}' +- Version:'#{build_version}' +- Build number: '#{build_number}' +- Build tag: '#{build_tag}' +- Build type: '#{build_type}' +- Build details (GitHub):'#{build_details}' +EOF + + uri = URI("https://api.github.com/repos/Orange-OpenSource/ouds-ios/issues/#{number}/comments") + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true + + request = Net::HTTP::Post.new(uri.path) + request['Authorization'] = "Bearer #{GITHUB_ACCESS_TOKEN}" + request['Content-Type'] = 'application/json' + request.body = { body: comment }.to_json + + response = http.request(request) + + if response.code.to_i == 201 + puts "ℹ️ Comment posted on issue '#{number}'" + else + puts "❌ Error: Failed to post comment on issue '#{number}'" + end + end + end + end + # Get version set in the Xcode project def get_app_version version = get_version_number( diff --git a/THIRD_PARTY.md b/THIRD_PARTY.md index f2f6bbbc87..5e468d9f4f 100644 --- a/THIRD_PARTY.md +++ b/THIRD_PARTY.md @@ -11,7 +11,9 @@ requirements of the relevant license of the Third Party Software they are using. ## In Project -### CocoaPods +### Ruby gems + +#### CocoaPods Version 1.15.2 @@ -20,7 +22,7 @@ Copyright 2011 Eloy Durán, Fabio Pelosin, Samuel Giddins, Marius Rackwitz, Kyle *CocoaPods* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). You may download the source code on the [following website](https://github.com/CocoaPods/CocoaPods). -### Fastlane +#### Fastlane Version 2.221.1 @@ -29,7 +31,7 @@ Copyright 2015-2022 The Fastlane Authors. *Fastlane* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). You may download the source code on the [following website](https://github.com/fastlane/fastlane). -### fastlane-plugin-changelog +#### fastlane-plugin-changelog Version 0.16.0 @@ -38,7 +40,7 @@ Copyright 2018 Pavel Procházka. *fastlane-plugin-changelog* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). You may download the source code on the [following website](https://github.com/pajapro/fastlane-plugin-changelog). -### fastlane-plugin-mattermost +#### fastlane-plugin-mattermost Version 1.3.2 @@ -47,21 +49,44 @@ Copyright 2020 cpfriend1721994. *fastlane-plugin-mattermost* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). You may download the source code on the [following website](https://github.com/cpfriend1721994/fastlane-plugin-mattermost). -### Gitleaks +#### net-http + +Version 0.4.1 + +*net-http* is distributed under the terms and conditions of the [Ruby License](https://github.com/flori/json/blob/master/LICENSE). + +#### json + +Version 2.7.2 + +*json* is distributed under the terms and conditions of the [Ruby License](https://github.com/flori/json/blob/master/LICENSE). + +#### xcode-install + +Version 2.8.1 + +Copyright (c) 2015 Boris Bügling + +*xcode-install* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). +You may download the source code on the [following website](https://github.com/xcpretty/xcode-install). + +### Other tools + +#### Gitleaks Copyright (c) 2019 Zachary Rice *gitleaks* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). You may download the source code on the [following website](https://github.com/gitleaks/gitleaks). -### Periphery +#### Periphery Copyright (c) 2019 Ian Leitch *Periphery* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). You may download the source code on the [following website](https://github.com/peripheryapp/periphery). -### SwiftFormat +#### SwiftFormat Version 0.54.0 @@ -70,21 +95,11 @@ Copyright 2016 Nick Lockwood. *SwiftFormat* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). You may download the source code on the [following website](https://github.com/nicklockwood/SwiftFormat). -### SwiftLint +#### SwiftLint Version 0.55.1 Copyright 2020 Realm Inc. *SwiftLint* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). -You may download the source code on the [following website](https://github.com/realm/SwiftLint). - -### xcode-install - -Version 2.8.1 - -Copyright (c) 2015 Boris Bügling - -*xcode-install* is distributed under the terms and conditions of the [MIT License](http://opensource.org/licenses/MIT). -You may download the source code on the [following website](https://github.com/xcpretty/xcode-install). - +You may download the source code on the [following website](https://github.com/realm/SwiftLint). \ No newline at end of file