Skip to content
23 changes: 9 additions & 14 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,28 @@ jobs:
run: swift test --disable-experimental-swift-testing

build-swift-android:
name: Sample SwiftJavaExtractJNISampleApp (Android) (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} android:${{matrix.sdk_triple}})
runs-on: ubuntu-latest
name: Sample SwiftJavaExtractJNISampleApp (Android) (swift:${{ matrix.swift_version }} android:${{matrix.sdk_triple}} NDK:${{matrix.ndk_version}})
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
swift_version: ['nightly-main']
swift_version: ['nightly-main', 'nightly-6.3']
os_version: ['jammy']
jdk_vendor: ['corretto']
sdk_triple: ['x86_64-unknown-linux-android28', 'armv7-unknown-linux-android28']
ndk_version: ['r27d']
container:
image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }}
sdk_triple: ['aarch64-unknown-linux-android28', 'x86_64-unknown-linux-android28', 'armv7-unknown-linux-android28']
ndk_version: ['r27d', 'r28c']
steps:
- uses: actions/checkout@v6
- name: Prepare CI Environment
uses: ./.github/actions/prepare_env
- name: Install Swift SDK for Android and build
env:
JAVA_HOME: ${{ env.JAVA_HOME }}
JAVA_HOME_17: ${{ env.JAVA_HOME_17 }}
JAVA_HOME_25: ${{ env.JAVA_HOME_25 }}
ANDROID_NDK_HOME: ${{ env.ANDROID_NDK_HOME }}
run: |
apt-get -q update && apt-get -yq install curl
cd Samples/SwiftJavaExtractJNISampleApp
curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \
bash -s -- --android --build-command="swift build" --android-sdk-triple="${{ matrix.sdk_triple }}" --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }}
curl -L -O --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh
perl -pi -e "s#(download_and_extract_toolchain \".ANDROID_SDK_TAG\"\))#\1\n PATH=\\\$(dirname \\\$SWIFT_EXECUTABLE_FOR_ANDROID_SDK):\\\$PATH\n echo \"path is now \\\$PATH\"#" install-and-build-with-sdk.sh
Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, finally got this working in a GitHub runner without needing a Swift container image, by modifying the official workflow script with this regex that produces this diff:

--- install-and-build-with-sdk.sh                         +++ new.sh    
@@ -616,6 +616,8 @@
         log "Installing Swift toolchain to match Android Swift SDK snapshot: $ANDROID_SDK_TAG"
         initialize_os_info
         SWIFT_EXECUTABLE_FOR_ANDROID_SDK=$(download_and_extract_toolchain "$ANDROID_SDK_TAG")
+        PATH=$(dirname $SWIFT_EXECUTABLE_FOR_ANDROID_SDK):$PATH
+        echo "path is now $PATH"
         if [[ $? -eq $EXIT_TOOLCHAIN_NOT_FOUND ]]; then
             # Don't fail the workflow if we can't find the right toolchain
             exit 0

SWIFT_EXECUTABLE_FOR_ANDROID_SDK is the full path to the Swift toolchain that the official script uses, so this regex merely adds it to the PATH also, as this swift-java plugin requires.

I don't know why the new 6.3 snapshot testing I added in this pull never failed, @madsodgaard, does 6.3 not have the swift-java plugin enabled or something, ie some code in this repo checks that the SDK is from trunk and only runs then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah I see, thank you

Copy link
Collaborator

Choose a reason for hiding this comment

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

6.3 shouldn't be any different tbh, so that's a bit weird...

chmod 500 install-and-build-with-sdk.sh
./install-and-build-with-sdk.sh --android --build-command="swift build" --android-sdk-triple="${{ matrix.sdk_triple }}" --android-ndk-version="${{ matrix.ndk_version }}" ${{ matrix.swift_version }}

verify-samples:
name: Sample ${{ matrix.sample_app }} (${{ matrix.os_version }} swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}})
Expand Down
Loading