generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 37
197 lines (175 loc) · 6.87 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Test
on:
push:
branches:
- "main"
- "rc"
- "hotfix-rc"
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:
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:
test:
name: Test
runs-on: macos-15-xlarge
timeout-minutes: 30
permissions:
contents: read
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
- 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 }}
- name: Configure Ruby
uses: ruby/setup-ruby@4a9ddd6f338a97768b8006bf671dfbad383215f4 # v1.207.0
with:
bundler-cache: true
- name: Cache Mint packages
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: .mint
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
restore-keys: |
${{ runner.os }}-mint-
- name: Cache SPM packages
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: build/DerivedData/SourcePackages
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Update local config
run: |
./Scripts/update_test_local_config.sh "${{ env._COMPILER_FLAGS }}"
- name: Install Mint and xcresultparser
run: |
brew install mint xcresultparser
./Scripts/bootstrap.sh
- name: Build and test
run: |
xcrun xcodebuild test \
-project Bitwarden.xcodeproj \
-scheme Bitwarden \
-configuration Debug \
-destination "platform=iOS Simulator,name=$_SIMULATOR_NAME,OS=$_SIMULATOR_VERSION" \
-resultBundlePath $_RESULT_BUNDLE_PATH \
-derivedDataPath build/DerivedData \
-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"
- 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 }}
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