Skip to content

Commit

Permalink
ci: GitHub comment publication for TestFlight alpha builds
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne <[email protected]>
  • Loading branch information
pylapp committed Aug 5, 2024
1 parent a30d9f5 commit b0a2ce9
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
69 changes: 66 additions & 3 deletions Showcase/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
# --------------------------

Expand Down Expand Up @@ -151,22 +154,30 @@ 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"
end

# 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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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(
Expand Down
53 changes: 34 additions & 19 deletions THIRD_PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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).

0 comments on commit b0a2ce9

Please sign in to comment.