8000 [PM-15905] feat: Restructure build info output by vvolkgang Β· Pull Request #1193 Β· bitwarden/ios Β· GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[PM-15905] feat: Restructure build info output #1193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ env:
_BUILD_MODE: ${{ inputs.build-mode || 'Device' }}
_XCODE_VERSION: ${{ inputs.xcode-version }}
_COMPILER_FLAGS: ${{ inputs.compiler-flags }}
_GITHUB_ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}

jobs:
build:
Expand Down Expand Up @@ -359,7 +360,7 @@ jobs:

- name: Update CI build info
run: |
./Scripts/update_app_ci_build_info.sh ${{ github.run_id }} ${{ github.run_number }} ${{ github.run_attempt }} "${{ env._COMPILER_FLAGS }}"
./Scripts/update_app_ci_build_info.sh $GITHUB_REPOSITORY $GITHUB_REF_NAME $GITHUB_SHA $GITHUB_RUN_ID $GITHUB_RUN_ATTEMPT "$_COMPILER_FLAGS"

- name: Build iOS app
run: |
Expand Down Expand Up @@ -414,7 +415,7 @@ jobs:
$GITHUB_REPOSITORY/$GITHUB_REF_NAME @ $GITHUB_SHA
Xcode ${{ env._XCODE_VERSION }}
Compiler Flags: ${{ inputs.compiler-flags }}
$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
$_GITHUB_ACTION_RUN_URL"

fastlane upload_build \
api_key_path:"$HOME/secrets/appstoreconnect-fastlane.json" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
///
enum CIBuildInfo {
/// Dictionary containing the info generated by the CI process.
static let info: [String: String] = [:]
static let info: KeyValuePairs<String, String> = [:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ€” I guess we do actually want these in a consistent order each time, huh.

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// MARK: - AboutProcessor

import Foundation

/// The processor used to manage state and handle actions for the `AboutView`.
///
final class AboutProcessor: StateProcessor<AboutState, AboutAction, Void> {
Expand Down Expand Up @@ -87,21 +89,28 @@ final class AboutProcessor: StateProcessor<AboutState, AboutAction, Void> {

/// Prepare the text to be copied.
private func handleVersionTapped() {
var buildVariant = switch Bundle.main.bundleIdentifier {
case "com.8bit.bitwarden.beta": "Beta"
case "com.8bit.bitwarden": "Production"
default: "Unkown"
}
buildVariant = "πŸ“¦ \(buildVariant)"
let hardwareInfo = "πŸ“± \(services.systemDevice.modelIdentifier)"
let osInfo = "🍏 \(services.systemDevice.systemName) \(services.systemDevice.systemVersion)"
let deviceInfo = "\(hardwareInfo) \(osInfo) \(buildVariant)"
var infoParts = [
state.copyrightText,
"",
state.version,
"\n-------- Device --------\n",
"Model: \(services.systemDevice.modelIdentifier)",
"OS: \(services.systemDevice.systemName) \(services.systemDevice.systemVersion)",
deviceInfo,
]
if !aboutAdditionalInfo.ciBuildInfo.isEmpty {
infoParts.append("\n------- CI Info --------\n")
infoParts.append(
contentsOf: aboutAdditionalInfo.ciBuildInfo.map { key, value in
"\(key): \(value)"
}
.sorted()
contentsOf: aboutAdditionalInfo.ciBuildInfo
.filter { !$0.value.isEmpty }
.map { key, value in
"\(key) \(value)"
}
)
}
services.pasteboardService.copy(infoParts.joined(separator: "\n"))
Expand All @@ -112,12 +121,12 @@ final class AboutProcessor: StateProcessor<AboutState, AboutAction, Void> {
/// Protocol for additional info used by the `AboutProcessor`
protocol AboutAdditionalInfo {
/// CI Build information.
var ciBuildInfo: [String: String] { get }
var ciBuildInfo: KeyValuePairs<String, String> { get }
}

/// Default implementation of `AboutAdditionalInfo`
struct DefaultAboutAdditionalInfo: AboutAdditionalInfo {
var ciBuildInfo: [String: String] {
var ciBuildInfo: KeyValuePairs<String, String> {
CIBuildInfo.info
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ class AboutProcessorTests: BitwardenTestCase {
Β© Bitwarden Inc. 2015-2024

Version: 2024.6.0 (1)

-------- Device --------

Model: iPhone14,2
OS: iOS 16.4
πŸ“± iPhone14,2 🍏 iOS 16.4 πŸ“¦ Production
"""
)
XCTAssertEqual(subject.state.toast, Toast(title: Localizations.valueHasBeenCopied(Localizations.appInfo)))
Expand All @@ -176,8 +172,9 @@ class AboutProcessorTests: BitwardenTestCase {
@MainActor
func test_receive_versionTapped_withAdditionalInfo() {
aboutAdditionalInfo.ciBuildInfo = [
"Repository": "www.github.com/bitwarden/ios",
"Branch": "test-branch",
"🧱 commit:": "bitwarden/ios/main@abc123",
"πŸ’» build source:": "bitwarden/ios/actions/runs/123/attempts/123",
"πŸ› οΈ compiler flags:": "DEBUG_MENU",
]

subject.receive(.versionTapped)
Expand All @@ -187,16 +184,35 @@ class AboutProcessorTests: BitwardenTestCase {
Β© Bitwarden Inc. 2015-2024

Version: 2024.6.0 (1)
πŸ“± iPhone14,2 🍏 iOS 16.4 πŸ“¦ Production
🧱 commit: bitwarden/ios/main@abc123
πŸ’» build source: bitwarden/ios/actions/runs/123/attempts/123
πŸ› οΈ compiler flags: DEBUG_MENU
"""
)
XCTAssertEqual(subject.state.toast, Toast(title: Localizations.valueHasBeenCopied(Localizations.appInfo)))
}

-------- Device --------

Model: iPhone14,2
OS: iOS 16.4
/// `receive(_:)` with action `.versionTapped` copies the copyright, the version string,
/// device info and the additional info to the pasteboard, without including keys with empty values
@MainActor
func test_receive_versionTapped_additionalInfoFiltersEmptyValues() {
aboutAdditionalInfo.ciBuildInfo = [
"🧱 commit:": "bitwarden/ios/main@abc123",
"πŸ’» build source:": "bitwarden/ios/actions/runs/123/attempts/123",
"πŸ› οΈ compiler flags:": "",
]

------- CI Info --------
subject.receive(.versionTapped)
XCTAssertEqual(
pasteboardService.copiedString,
"""
Β© Bitwarden Inc. 2015-2024

Branch: test-branch
Repository: www.github.com/bitwarden/ios
Version: 2024.6.0 (1)
πŸ“± iPhone14,2 🍏 iOS 16.4 πŸ“¦ Production
🧱 commit: bitwarden/ios/main@abc123
πŸ’» build source: bitwarden/ios/actions/runs/123/attempts/123
"""
)
XCTAssertEqual(subject.state.toast, Toast(title: Localizations.valueHasBeenCopied(Localizations.appInfo)))
Expand All @@ -215,5 +231,5 @@ class AboutProcessorTests: BitwardenTestCase {
}

class MockAboutAdditionalInfo: AboutAdditionalInfo {
var ciBuildInfo: [String: String] = [:]
var ciBuildInfo: KeyValuePairs<String, String> = [:]
}
56 changes: 28 additions & 28 deletions Scripts/update_app_ci_build_info.sh
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
#!/bin/sh
# CI Build Info Updater
#
# Updates the CIBuildInfo.swift file to add any additional info we need from the CI build.
# Updates the CIBuildInfo.swift file with additional info from the CI build.
#
# Usage:
#
# $ ./update_app_ci_build_info.sh <ci_run_id> <ci_run_number> <ci_run_attempt> "<compiler_flags>"
# Prerequisites:
# - Git command line tools installed
# - Write access to CIBuildInfo.swift file

set -euo pipefail

if [ $# -lt 3 ]; then
echo >&2 "Called without necessary arguments."
echo >&2 "For example: \`Scripts/update_app_ci_build_info.sh 123123 111 1 \"DEBUG_MENU FEATURE1\"\`"
exit 1
if [ $# -ne 6 ]; then
echo >&2 "Called with $# arguments but expected 6."
echo "Usage: $0 <repository> <branch> <commit_hash> <ci_run_number> <ci_run_attempt> <compiler_flags>"
echo "E.g: $0 bitwarden/ios main abc123 1234567890 1 \"DEBUG_MENU FEATURE1\""
exit 1
fi

ci_run_id=$1
ci_run_number=$2
ci_run_attempt=$3
compiler_flags=${4:-''}
set -euo pipefail

repository=$1
branch=$2
commit_hash=$3
ci_run_number=$4
ci_run_attempt=$5
compiler_flags=${6:-''}

ci_build_info_file="BitwardenShared/Core/Platform/Utilities/CIBuildInfo.swift"
repository=$(git config --get remote.origin.url)
branch=$(git branch --show-current)
commit_hash=$(git rev-parse --verify HEAD)
git_source="${repository}/${branch}@${commit_hash}"
ci_run_source="${repository}/actions/runs/${ci_run_number}/attempts/${ci_run_attempt}"

echo "🧱 Updating app CI Build info..."
echo "🧱 CI run ID: ${ci_run_id}"
echo "🧱 CI run number: ${ci_run_number}"
echo "🧱 CI run attempt: ${ci_run_attempt}"
echo "🧱 Compiler Flags: ${compiler_flags}"
echo "🧱 🧱${git_source}"
echo "🧱 πŸ’»${ci_run_source}"
echo "🧱 πŸ› οΈ ${compiler_flags}"


cat << EOF > ${ci_build_info_file}
enum CIBuildInfo {
static let info: [String: String] = [
"Repository": "${repository}",
"Branch": "${branch}",
"Commit hash": "${commit_hash}",
"CI Run ID": "${ci_run_id}",
"CI Run Number": "${ci_run_number}",
"CI Run Attempt": "${ci_run_attempt}",
"Compiler Flags": "${compiler_flags}",
static let info: KeyValuePairs<String, String> = [
"🧱 commit:": "${git_source}",
"πŸ’» build source:": "${ci_run_source}",
"πŸ› οΈ compiler flags:": "${compiler_flags}",
]
}
EOF

echo "βœ… CI Build info updated successfully."
Loading
0