Skip to content

Commit d3ee9b4

Browse files
authored
Merge pull request #187 from embrace-io/acohen/sanitizer-support
Add sanitizer support
2 parents 3d57780 + bbbfad1 commit d3ee9b4

File tree

6 files changed

+67
-4
lines changed

6 files changed

+67
-4
lines changed

.github/workflows/checks.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,26 @@ jobs:
302302
code-coverage: ${{ matrix.codecov }}
303303
action: ${{ matrix.action }}
304304

305+
verify-sanitizers:
306+
name: ${{ matrix.platform }} ${{ matrix.sanitizer }}
307+
runs-on: macos-latest
308+
needs: [verify-dist]
309+
strategy:
310+
matrix:
311+
platform:
312+
- macOS
313+
sanitizer:
314+
- thread
315+
- address
316+
steps:
317+
- uses: actions/checkout@v4
318+
- uses: ./
319+
with:
320+
platform: ${{ matrix.platform }}
321+
working-directory: fixtures/${{ matrix.platform }}
322+
sanitizer: ${{ matrix.sanitizer }}
323+
action: test
324+
305325
verify-dot-swift-version:
306326
name: .swift-version
307327
runs-on: macos-14

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ jobs:
6565
platform: ${{ matrix.platform }}
6666
action: build # default = `test`
6767
code-coverage: true # default = `false`
68+
sanitizer: thread # options: `thread`, `address` (only one at a time)
6869
warnings-as-errors: true # default = `false`
6970
configuration: release # no default, ie. `xcodebuild` decides itself
7071
```
@@ -186,10 +187,38 @@ opened in Xcode:
186187

187188
![img]
188189

189-
Youll even get your coverage report!
190+
You'll even get your coverage report!
190191

191192
> Note this feature requires Xcode >= 11
192193

194+
## Sanitizers
195+
196+
You can enable sanitizers to help detect bugs during testing. Only one sanitizer can be enabled at a time.
197+
198+
### Thread Sanitizer
199+
200+
Thread Sanitizer (TSan) detects data races and other threading issues:
201+
202+
```yaml
203+
- uses: mxcl/xcodebuild@v3
204+
with:
205+
action: test
206+
sanitizer: thread
207+
```
208+
209+
### Address Sanitizer
210+
211+
Address Sanitizer (ASan) detects memory corruption issues like buffer overflows and use-after-free:
212+
213+
```yaml
214+
- uses: mxcl/xcodebuild@v3
215+
with:
216+
action: test
217+
sanitizer: address
218+
```
219+
220+
Sanitizers are only applied for `test` and `build-for-testing` actions.
221+
193222
## `.swift-version` File
194223

195224
If your repo has a `.swift-version` file and neither `swift` nor `xcode` is

action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ inputs:
4242
description: Enables code coverage
4343
required: false
4444
default: 'false'
45+
sanitizer:
46+
description: |
47+
Enable a sanitizer for testing. Options: `thread`, `address`.
48+
* `thread`: Thread Sanitizer (TSan) detects threading issues like data races
49+
* `address`: Address Sanitizer (ASan) detects memory issues like buffer overflows
50+
Only one sanitizer can be enabled at a time. Leave unset to disable.
51+
required: false
4552
authentication-key-base64:
4653
description: |
4754
A Base64-encoded authentication key issued by App Store Connect. If

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,18 @@ async function main() {
225225
if (warningsAsErrors) args.push(warningsAsErrorsFlags)
226226
break
227227
case 'test':
228-
case 'build-for-testing':
228+
case 'build-for-testing': {
229229
if (core.getBooleanInput('code-coverage')) {
230230
args = args.concat(['-enableCodeCoverage', 'YES'])
231231
}
232+
const sanitizer = core.getInput('sanitizer')
233+
if (sanitizer === 'thread') {
234+
args = args.concat(['-enableThreadSanitizer', 'YES'])
235+
} else if (sanitizer === 'address') {
236+
args = args.concat(['-enableAddressSanitizer', 'YES'])
237+
}
232238
break
239+
}
233240
}
234241

235242
if (core.getBooleanInput('trust-plugins')) {

0 commit comments

Comments
 (0)