Skip to content

Commit b2806ba

Browse files
authored
Add support for running on Linux as well as macOS (#1)
* Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Workflow and CI * Update README * Update README * Update README * Update README * Update README * Update README and cleanup script * Fix copy-files handling * Update README
1 parent 970de52 commit b2806ba

File tree

3 files changed

+355
-69
lines changed

3 files changed

+355
-69
lines changed

.github/workflows/test-action.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: swift-android-action ci
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches: [ main ]
6+
jobs:
7+
demo:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
os: ['ubuntu-24.04', 'ubuntu-22.04', 'ubuntu-20.04', 'macos-13', 'macos-15']
13+
steps:
14+
- name: Checkout apple/swift-algorithms
15+
uses: actions/checkout@v4
16+
with:
17+
repository: apple/swift-algorithms
18+
path: apple/swift-algorithms
19+
- name: Test apple/swift-algorithms
20+
uses: marcprux/swift-android-action@main
21+
with:
22+
package-path: apple/swift-algorithms
23+
run-tests: ${{ matrix.os != 'macos-15' }} # no tests on macOS ARM
24+
25+
- name: Checkout skiptools/swift-sqlite
26+
uses: actions/checkout@v4
27+
with:
28+
repository: skiptools/swift-sqlite
29+
path: skiptools/swift-sqlite
30+
- name: Test skiptools/swift-sqlite
31+
uses: marcprux/swift-android-action@main
32+
with:
33+
package-path: skiptools/swift-sqlite
34+
run-tests: ${{ matrix.os != 'macos-15' }} # no tests on macOS ARM
35+

README.md

Lines changed: 105 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
# Swift Android native cross-compiler and test runner action
22

3-
GitHub action to build and run Swift package tests on an Android emulator.
3+
This GitHub action will build and run Swift package tests on an Android emulator.
44
This uses the [swift-android-toolchain](https://github.com/skiptools/swift-android-toolchain)
55
project to provide a cross-compiler for building
6-
Swift natively for Android on a macOS host.
6+
Swift natively for Android on a Linux or macOS host.
77

88
After building the package, it will run the SwiftPM
9-
test targets on an Android emulator (which it provided by the
9+
test targets on an Android emulator (which is provided by the
1010
[Android Emulator Runner action](https://github.com/marketplace/actions/android-emulator-runner)).
1111
To build the package for Android without running the tests
1212
(which is considerably faster), set the `run-tests` option to `false`.
1313

14-
1514
You can add this action to your Swift CI workflow from the
1615
[GitHub Marketplace](https://github.com/marketplace/actions/swift-android-action),
1716
or you can manually create a workflow by adding a
@@ -20,76 +19,131 @@ This sample action will run your Swift package's test cases
2019
on a host macOS machine, as well as on an Android emulator
2120
and an iOS simulator.
2221

22+
## Example
23+
24+
The following `ci.yml` workflow will check out the current repository and test the Swift package on Linux and Android:
25+
2326
```yml
24-
name: Swift Package CI
27+
name: ci
2528
on:
2629
push:
27-
branches: [ main ]
30+
branches:
31+
- '*'
32+
workflow_dispatch:
2833
pull_request:
2934
branches:
3035
- '*'
3136
jobs:
32-
test:
33-
# Runner must be macos-13, since lack of nested virtualization support on macos-14 prevents the Android emulator from working
34-
# see: https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#limitations-for-arm64-macos-runners
35-
runs-on: macos-13
37+
linux-android:
38+
runs-on: ubuntu-latest
3639
steps:
3740
- uses: actions/checkout@v4
38-
- name: "Test Swift Package on macOS"
41+
- name: "Test Swift Package on Linux"
42+
run: swift test
43+
- name: "Test Swift Package on Android"
44+
uses: skiptools/swift-android-action@v2
45+
```
46+
47+
48+
## Configuration
49+
50+
The following configuration options can be passed to the workflow. For example, to specify the version of Swift you want to use for building and testing, you can use the `swift-version` parameter like so:
51+
52+
```yml
53+
jobs:
54+
linux-android:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
- name: "Test Swift Package on Linux"
59+
run: swift test
60+
- name: "Test Swift Package on Android"
61+
uses: skiptools/swift-android-action@v2
62+
with:
63+
swift-version: 6.0.2
64+
```
65+
66+
### Configuration Options
67+
68+
| Parameter | Default | Description |
69+
|-----|-----|-----|
70+
| swift-version | The version of the Swift toolchain to use | 6.0.2 |
71+
| package-path | The folder where the swift package is checked out | . |
72+
| swift-build-flags | Additional flags to pass to the swift build command | |
73+
| swift-test-flags | Additional flags to pass to the swift test command | |
74+
| build-tests | Whether to build the package tests or just the sources | true |
75+
| run-tests | Whether to run the tests or just perform the build | true |
76+
| copy-files | Additional files to copy to emulator for testing | |
77+
| android-api-level | The API level of the Android emulator to run against | 29 |
78+
| android-emulator-options | Options to pass to the Android emulator | -no-window … |
79+
| android-emulator-boot-timeout | Emulator boot timeout in seconds | 600 |
80+
81+
### Platform Support
82+
83+
This action can be run on any of the GitHub `ubuntu-*` and `macos-*` [runner images](https://github.com/actions/runner-images). However, due to the inability of macOS on ARM to run nested virtualization ([issue](https://github.com/ReactiveCircus/android-emulator-runner/issues/350)), the Android emulator cannot be run on these platforms, and so running on any macOS image that uses ARM (including `macos-14` and `macos-15`) requires disabling tests with `run-tests: false`. Running tests are supported on `macos-13`, as well as the large Intel macOS images like `macos-14-large` and `macos-15-large`.
84+
85+
## Complete Universal CI Example
86+
87+
Following is an example of a `ci.yml` workflow that checks out and tests a Swift package on each of macOS, iOS, Linux, Android, and Windows.
88+
89+
```yml
90+
name: swift-algorithms ci
91+
on:
92+
push:
93+
branches:
94+
- '*'
95+
workflow_dispatch:
96+
pull_request:
97+
branches:
98+
- '*'
99+
jobs:
100+
linux-android:
101+
runs-on: ubuntu-latest
102+
steps:
103+
- uses: actions/checkout@v4
104+
- name: "Test Swift Package on Linux"
39105
run: swift test
40106
- name: "Test Swift Package on Android"
41-
uses: skiptools/swift-android-action@v1
107+
uses: skiptools/swift-android-action@v2
108+
macos-ios:
109+
runs-on: macos-latest
110+
steps:
111+
- uses: actions/checkout@v4
112+
- name: "Test Swift Package on macOS"
113+
run: swift test
42114
- name: "Test Swift Package on iOS"
43-
run: xcodebuild test -sdk "iphonesimulator" -destination "platform=iOS Simulator,name=iPhone 15" -scheme "$(xcodebuild -list -json | jq -r '.workspace.schemes[-1]')" -skipPackagePluginValidation
115+
run: xcodebuild test -sdk "iphonesimulator" -destination "platform=iOS Simulator,name=iPhone 15" -scheme "$(xcodebuild -list -json | jq -r '.workspace.schemes[-1]')"
116+
windows:
117+
runs-on: windows-latest
118+
steps:
119+
- uses: actions/checkout@v4
120+
- name: "Setup Swift on Windows"
121+
uses: compnerd/gha-setup-swift@main
122+
with:
123+
branch: swift-6.0.2-release
124+
tag: 6.0.2-RELEASE
125+
- name: "Test Swift Package on Windows"
126+
run: swift test
44127
45128
```
46129

47-
For an example of a workflow in action, see a run history
130+
For an example of this workflow in action, see a run history
48131
for the [Swift Algorithms](https://github.com/skiptools/swift-algorithms) package at:
49132
[https://github.com/skiptools/swift-algorithms/actions](https://github.com/skiptools/swift-algorithms/actions)
50133

51-
## Configuration Options
52134

135+
## Development
53136

54-
```
55-
swift-version:
56-
description: 'The version of the Swift toolchain to use'
57-
default: '6.0.1'
58-
package-path:
59-
description: 'The folder where the swift package is checked out'
60-
default: '.'
61-
swift-build-flags:
62-
description: 'Additional flags to pass to the swift build command'
63-
default: ''
64-
swift-test-flags:
65-
description: 'Additional flags to pass to the swift test command'
66-
default: ''
67-
run-tests:
68-
description: 'Whether to run the tests or just the build'
69-
default: 'true'
70-
android-api-level:
71-
description: 'The API level of the Android emulator to run against'
72-
default: 29
73-
android-emulator-options:
74-
description: 'Options to pass to the Android emulator'
75-
default: '-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim'
76-
android-emulator-arch:
77-
description: 'Architecture for the Android emulator (x86_64 or arm64-v8)'
78-
required: true
79-
default: 'x86_64'
80-
android-emulator-boot-timeout:
81-
description: 'Emulator boot timeout in seconds'
82-
default: 600
83-
```
84-
85-
## Releasing
137+
### Releasing new versions
86138

87-
To create a new release, make a new tag (like 1.0.0),
88-
and then update the symbolic major v1 tag with:
139+
To create a new release, make a new tag (like 2.0.2),
140+
and then update the symbolic major v2 tag with:
89141

90142
```
91-
git tag v1.0.2 && git push --tags
92-
git tag -fa v1 -m "Update v1 tag" && git push origin v1 --force
143+
git tag v2.0.2
144+
git push --tags
145+
git tag -fa v2 -m "Update v2 tag"
146+
git push origin v2 --force
93147
```
94148

95149

0 commit comments

Comments
 (0)