Skip to content

Commit 6f329b4

Browse files
committed
Add SDK builder workflow
1 parent cacc94c commit 6f329b4

File tree

1 file changed

+163
-0
lines changed

1 file changed

+163
-0
lines changed
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
name: Build Swift Android SDK
2+
on:
3+
push:
4+
branches: '*'
5+
tags: "[0-9]+.[0-9]+.[0-9]+"
6+
schedule:
7+
- cron: '30 4,9,16,21 * * *'
8+
workflow_dispatch:
9+
pull_request:
10+
11+
jobs:
12+
android-build:
13+
name: Build Android ${{ matrix.build-type }} ${{ matrix.swift-version }} ${{ matrix.arch }} SDK
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
#build-type: ['docker']
18+
build-type: ['docker', 'local']
19+
# blank arch builds all (aarch64,x86_64,armv7)
20+
arch: ['']
21+
# builds only x86_64 to speed up the validation
22+
#arch: ['x86_64']
23+
# build both the quick (x86_64) and complete (aarch64,x86_64,armv7) SDKs
24+
#arch: ['x86_64', '']
25+
swift-version: ['release', 'swift-6.2-branch', 'development']
26+
runs-on: ubuntu-24.04
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
- name: Checkout https://github.com/swiftlang/swift-docker/pull/467
31+
run: gh pr checkout 467
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
- name: Free Disk Space
35+
run: |
36+
df -h
37+
# brings available space from 25G to 32G
38+
# otherwise we sometimes run out of space during the build
39+
sudo rm -rf /usr/share/miniconda /usr/share/az* /usr/share/glade* /usr/local/share/chromium /usr/local/share/powershell /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL
40+
sudo docker image prune --all --force
41+
sudo docker builder prune -a
42+
df -h
43+
- name: Setup
44+
id: config
45+
run: |
46+
# these variabes are used by build-docker and build-local
47+
# to determine which Swift version to build for
48+
echo "BUILD_SCHEME=${{ matrix.swift-version }}" >> $GITHUB_ENV
49+
echo "TARGET_ARCHS=${{ matrix.arch }}" >> $GITHUB_ENV
50+
echo "WORKDIR=${{ runner.temp }}/swift-android-sdk" >> $GITHUB_ENV
51+
- name: Build Android SDK (Local)
52+
if: ${{ matrix.build-type == 'local' }}
53+
working-directory: swift-ci/sdks/android
54+
run: |
55+
sudo apt install -q ninja-build patchelf
56+
./build-local ${BUILD_SCHEME} ${WORKDIR}
57+
- name: Build Android SDK (Docker)
58+
if: ${{ matrix.build-type == 'docker' }}
59+
working-directory: swift-ci/sdks/android
60+
run: |
61+
./build-docker ${BUILD_SCHEME} ${WORKDIR}
62+
- name: Install Host Toolchain
63+
if: ${{ matrix.build-type == 'docker' }}
64+
working-directory: swift-ci/sdks/android
65+
run: |
66+
# when building in a Docker container, we don't have a
67+
# local host toolchain, but we need one in order to run
68+
# the SDK validation tests, so we install it now
69+
HOST_OS=ubuntu$(lsb_release -sr)
70+
source ./scripts/toolchain-vars.sh
71+
mkdir -p ${WORKDIR}/host-toolchain
72+
./scripts/install-swift.sh ${WORKDIR}/host-toolchain/$SWIFT_BASE/usr
73+
ls ${WORKDIR}/host-toolchain
74+
${WORKDIR}/host-toolchain/*/usr/bin/swift --version
75+
- name: Get artifact info
76+
id: info
77+
shell: bash
78+
run: |
79+
set -ex
80+
SWIFT_ROOT=$(dirname ${WORKDIR}/host-toolchain/*/usr)
81+
echo "swift-root=${SWIFT_ROOT}" >> $GITHUB_OUTPUT
82+
echo "swift-path=${SWIFT_ROOT}/usr/bin/swift" >> $GITHUB_OUTPUT
83+
84+
ARTIFACT_PATH=$(realpath ${WORKDIR}/products/*.artifactbundle.tar.gz)
85+
echo "artifact-path=${ARTIFACT_PATH}" >> $GITHUB_OUTPUT
86+
echo "sdk-id=x86_64-unknown-linux-android28" >> $GITHUB_OUTPUT
87+
88+
ARTIFACT_EXT=".artifactbundle.tar.gz"
89+
ARTIFACT_NAME="$(basename ${ARTIFACT_PATH} ${ARTIFACT_EXT})"
90+
# depending on whether we are building locally or in a container, add a maker to the name
91+
if [[ "${{ matrix.build-type }}" == 'local' ]]; then
92+
ARTIFACT_NAME="${ARTIFACT_NAME}-local"
93+
fi
94+
# artifacts need a unique name so we suffix with the matrix arch(s)
95+
if [[ ! -z "${{ matrix.arch }}" ]]; then
96+
ARTIFACT_NAME="${ARTIFACT_NAME}-$(echo ${{ matrix.arch }} | tr ',' '-')"
97+
fi
98+
ARTIFACT_NAME="${ARTIFACT_NAME}${ARTIFACT_EXT}"
99+
100+
# There is no way to prevent even a single-file artifact from being zipped:
101+
# https://github.com/actions/upload-artifact?tab=readme-ov-file#zip-archives
102+
# so the actual artifact download will look like:
103+
# swift-6.1-RELEASE_android-0.1-x86_64.artifactbundle.tar.gz.zip
104+
echo "artifact-name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT
105+
- name: Upload SDK artifactbundle
106+
uses: actions/upload-artifact@v4
107+
with:
108+
compression-level: 0
109+
name: ${{ steps.info.outputs.artifact-name }}
110+
path: ${{ steps.info.outputs.artifact-path }}
111+
- name: Cleanup
112+
run: |
113+
# need to free up some space or else when installing we get: No space left on device
114+
df -h
115+
rm -rf ${WORKDIR}/{build,source}
116+
sudo docker image prune --all --force
117+
sudo docker builder prune -a
118+
df -h
119+
- name: Install artifactbundle
120+
shell: bash
121+
run: |
122+
set -ex
123+
${{ steps.info.outputs.swift-path }} sdk install ${{ steps.info.outputs.artifact-path }}
124+
${{ steps.info.outputs.swift-path }} sdk configure --show-configuration $(${{ steps.info.outputs.swift-path }} sdk list | head -n 1) ${{ steps.info.outputs.sdk-id }}
125+
# recent releases require that ANDROID_NDK_ROOT *not* be set
126+
# see https://github.com/swiftlang/swift-driver/pull/1879
127+
echo "ANDROID_NDK_ROOT=" >> $GITHUB_ENV
128+
129+
- name: Create Demo Project
130+
run: |
131+
cd ${{ runner.temp }}
132+
mkdir DemoProject
133+
cd DemoProject
134+
${{ steps.info.outputs.swift-path }} --version
135+
${{ steps.info.outputs.swift-path }} package init
136+
echo 'import Foundation' >> Sources/DemoProject/DemoProject.swift
137+
echo 'import FoundationEssentials' >> Sources/DemoProject/DemoProject.swift
138+
echo 'import FoundationXML' >> Sources/DemoProject/DemoProject.swift
139+
echo 'import FoundationNetworking' >> Sources/DemoProject/DemoProject.swift
140+
echo 'import Dispatch' >> Sources/DemoProject/DemoProject.swift
141+
echo 'import Android' >> Sources/DemoProject/DemoProject.swift
142+
- name: Test Demo Project on Android
143+
uses: skiptools/swift-android-action@main
144+
with:
145+
# only test for the complete arch SDK build to speed up CI
146+
#run-tests: ${{ matrix.arch == '' }}
147+
package-path: ${{ runner.temp }}/DemoProject
148+
installed-sdk: ${{ steps.info.outputs.sdk-id }}
149+
installed-swift: ${{ steps.info.outputs.swift-root }}
150+
151+
- name: Checkout swift-algorithms
152+
uses: actions/checkout@v4
153+
with:
154+
repository: apple/swift-algorithms
155+
path: swift-algorithms
156+
- name: Test swift-algorithms
157+
uses: skiptools/swift-android-action@main
158+
with:
159+
run-tests: ${{ matrix.arch == '' }}
160+
package-path: swift-algorithms
161+
installed-sdk: ${{ steps.info.outputs.sdk-id }}
162+
installed-swift: ${{ steps.info.outputs.swift-root }}
163+

0 commit comments

Comments
 (0)