Skip to content

Commit

Permalink
[PM-17411] Pull simulator type/version from file for testing (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
KatherineInCode authored Feb 4, 2025
1 parent 18f6811 commit dc7beeb
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 23 deletions.
157 changes: 134 additions & 23 deletions .github/workflows/test-bwa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,47 @@ on:
- "main"
- "rc"
- "hotfix-rc"
pull_request_target:
pull_request:
types: [opened, synchronize]
workflow_dispatch:
inputs:
xcode-version:
description: "Xcode version override - e.g. '15.2'"
type: string
simulator-name:
description: "Simulator name override - e.g. 'iPhone 16 Pro'"
type: string
simulator-version:
description: "Simulator iOS version override - e.g. '18.0.1'"
type: string
compiler-flags:
description: "Compiler Flags - e.g. 'DEBUG_MENU FEATURE2'"
type: string
workflow_call:
inputs:
xcode-version:
description: "Xcode version override - e.g. '15.2'"
type: string
simulator-name:
description: "Simulator name override - e.g. 'iPhone 16 Pro'"
type: string
simulator-version:
description: "Simulator iOS version override - e.g. '18.0.1'"
type: string
compiler-flags:
description: "Compiler Flags - e.g. 'DEBUG_MENU FEATURE2'"
type: string

env:
DEVELOPER_DIR: /Applications/Xcode_15.4.app/Contents/Developer
MINT_LINK_PATH: .mint/bin
MINT_PATH: .mint/lib
SIMULATOR_DESTINATION: platform=iOS Simulator,name=iPhone 15 Pro,OS=17.0.1
RESULT_BUNDLE_PATH: build/AuthenticatorTests.xcresult
COVERAGE_PATH: build/coverage.xml
XCODE_VERSION: 15.4
MINT_LINK_PATH: .mint/bin # used by mint in bootstrap.sh
MINT_PATH: .mint/lib # used by mint in bootstrap.sh
_COVERAGE_PATH: build/coverage.xml
_RESULT_BUNDLE_PATH: build/BitwardenTests.xcresult
_SIMULATOR_NAME: ${{ inputs.simulator-name }}
_SIMULATOR_VERSION: ${{ inputs.simulator-version }}
_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:
check-run:
Expand All @@ -29,18 +59,38 @@ jobs:
needs: check-run
permissions:
contents: read
pull-requests: write

steps:
- name: Log inputs to job summary
run: |
echo "<details><summary>Build Workflow Inputs</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```json' >> $GITHUB_STEP_SUMMARY
echo '${{ toJson(inputs) }}' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
- name: Check out repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Read Xcode version and simulator configuration from file if not provided
run: |
if [ -z "$_XCODE_VERSION" ]; then
echo "_XCODE_VERSION=$(cat .xcode-version | tr -d '\n')" >> "$GITHUB_ENV"
fi
if [ -z "$_SIMULATOR_NAME" ]; then
echo "_SIMULATOR_NAME=$(cat .test-simulator-device-name | tr -d '\n')" >> "$GITHUB_ENV"
fi
if [ -z "$_SIMULATOR_VERSION" ]; then
echo "_SIMULATOR_VERSION=$(cat .test-simulator-ios-version | tr -d '\n')" >> "$GITHUB_ENV"
fi
- name: Set Xcode version
uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd # v1.6.0
with:
xcode-version: ${{ env.XCODE_VERSION }}
xcode-version: ${{ env._XCODE_VERSION }}

- name: Configure Ruby
uses: ruby/setup-ruby@1287d2b408066abada82d5ad1c63652e758428d9 # v1.214.0
Expand All @@ -63,38 +113,99 @@ jobs:
restore-keys: |
${{ runner.os }}-spm-
- name: Install yeetd
- name: Update local config
run: |
wget https://github.com/biscuitehh/yeetd/releases/download/1.0/yeetd-normal.pkg
sudo installer -pkg yeetd-normal.pkg -target /
yeetd &
./Scripts-bwa/update_test_local_config.sh "${{ env._COMPILER_FLAGS }}"
- name: Install Mint, protobuf, xcbeautify, and xcresultparser
- name: Install Mint, protobuf, and xcresultparser
run: |
brew install mint swift-protobuf xcbeautify a7ex/homebrew-formulae/xcresultparser
brew install mint swift-protobuf xcresultparser
./Scripts-bwa/bootstrap.sh
- name: Build and test
run: |
set -o pipefail && \
xcodebuild test \
xcrun xcodebuild test \
-project Authenticator.xcodeproj \
-scheme Authenticator \
-configuration Debug \
-destination "${{ env.SIMULATOR_DESTINATION }}" \
-resultBundlePath ${{ env.RESULT_BUNDLE_PATH }} \
-destination "platform=iOS Simulator,name=$_SIMULATOR_NAME,OS=$_SIMULATOR_VERSION" \
-resultBundlePath $_RESULT_BUNDLE_PATH \
-derivedDataPath build/DerivedData \
-enableCodeCoverage YES \
| xcbeautify --renderer github-actions
-test-timeouts-enabled yes \
-maximum-test-execution-time-allowance 1 \
-quiet
- name: Print Logs Summary
if: always()
run: |
xcresultparser -o cli "$_RESULT_BUNDLE_PATH"
echo "# Test Summary" >> $GITHUB_STEP_SUMMARY
xcresultparser -f -o txt "$_RESULT_BUNDLE_PATH" | grep "Number of" >> $GITHUB_STEP_SUMMARY
- name: Convert coverage to Cobertura
run: |
set -o pipefail && \
xcresultparser --output-format cobertura \
"$RESULT_BUNDLE_PATH" >"$COVERAGE_PATH"
"$_RESULT_BUNDLE_PATH" > "$_COVERAGE_PATH"
- name: Upload test reports
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
if: always()
with:
name: test-reports
compression-level: 9
path: |
${{ env._COVERAGE_PATH }}
${{ env._RESULT_BUNDLE_PATH }}
- name: Upload to codecov.io
id: upload-to-codecov
uses: codecov/codecov-action@13ce06bfc6bbe3ecf90edbbf1bc32fe5978ca1d3 # v5.3.1
continue-on-error: true
with:
plugin: xcode
files: ${{ env.COVERAGE_PATH }}

report:
name: Process Test Reports
needs: test
runs-on: ubuntu-24.04
permissions:
issues: write
pull-requests: write
if: success()

steps:
- name: Check out repo
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
sparse-checkout: .github/codecov.yml
sparse-checkout-cone-mode: false

- name: Download test artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: test-reports

- name: Upload to codecov.io
id: upload-to-codecov
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
continue-on-error: true
with:
files: coverage.xml
fail_ci_if_error: true

- name: Comment PR if tests failed
if: steps.upload-to-codecov.outcome == 'failure'
env:
PR_NUMBER: ${{ github.event.number }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ACTOR: ${{ github.triggering_actor }}
run: |
echo "> [!WARNING]" >> $GITHUB_STEP_SUMMARY
echo "> Uploading code coverage report failed. Please check the \"Upload to codecov.io\" step of \"Process Test Reports\" job for more details." >> $GITHUB_STEP_SUMMARY
if [ ! -z "$PR_NUMBER" ]; then
message=$'> [!WARNING]\n> @'$RUN_ACTOR' Uploading code coverage report failed. Please check the "Upload to codecov.io" step of [Process Test Reports job]('$_GITHUB_ACTION_RUN_URL') for more details.'
gh pr comment --repo $GITHUB_REPOSITORY $PR_NUMBER --body "$message"
fi
1 change: 1 addition & 0 deletions .test-simulator-device-name
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iPhone 15 Pro
1 change: 1 addition & 0 deletions .test-simulator-ios-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17.0.1
1 change: 1 addition & 0 deletions .xcode-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15.4
33 changes: 33 additions & 0 deletions Scripts-bwa/update_test_local_config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
#
# Updates the test local config setting the compiler flags.
#
# Usage:
#
# $ ./Scripts/update_test_local_config.sh "<compiler_flags>"
# Example:
# $ ./Scripts/update_test_local_config.sh DEBUG_MENU
# $ ./Scripts/update_test_local_config.sh "FEATURE1 FEATURE2"

set -euo pipefail

bold=$(tput -T ansi bold)
normal=$(tput -T ansi sgr0)

if [ $# -lt 1 ]; then
echo "🧱 No compiler flags to update test local config."
exit 0
fi

compiler_flags=${1:-''}

echo "🧱 Updating Test local config..."
echo "🛠️ Compiler flags: ${compiler_flags}"

local_xcconfig_file="Configs-bwa/Local.xcconfig"

cat << EOF > ${local_xcconfig_file}
BITWARDEN_FLAGS = \$(inherited) ${compiler_flags}
EOF

echo "✅ Test local config updated successfully."

0 comments on commit dc7beeb

Please sign in to comment.