1+ name : Linux Build
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ ref :
7+ description : " Git ref to checkout"
8+ required : false
9+ default : ${{ github.ref }}
10+ type : string
11+ upload_artifacts :
12+ description : " Whether to upload artifacts"
13+ required : false
14+ default : false
15+ type : boolean
16+ artifact_retention_days :
17+ description : " How long to retain artifacts"
18+ required : false
19+ default : 7
20+ type : number
21+ outputs :
22+ artifact_name_x86_64 :
23+ description : " Name of the x86_64 Linux artifact"
24+ value : ${{ jobs.build-linux.outputs.artifact_name_x86_64 }}
25+ artifact_name_aarch64 :
26+ description : " Name of the aarch64 Linux artifact"
27+ value : ${{ jobs.build-linux.outputs.artifact_name_aarch64 }}
28+
29+ jobs :
30+ build-linux :
31+ strategy :
32+ fail-fast : false
33+ matrix :
34+ include :
35+ - arch : x86_64
36+ runner : ubuntu-latest
37+ triple : x86_64-unknown-linux-gnu
38+ - arch : aarch64
39+ runner : ubuntu-24.04-arm
40+ triple : aarch64-unknown-linux-gnu
41+ runs-on : ${{ matrix.runner }}
42+ outputs :
43+ artifact_name_x86_64 : linux-x86_64-binary
44+ artifact_name_aarch64 : linux-aarch64-binary
45+ steps :
46+ - name : Checkout code
47+ uses : actions/checkout@v4
48+ with :
49+ ref : ${{ inputs.ref }}
50+
51+ - name : Install Swift
52+ run : |
53+ # Check if Swift is already available
54+ if command -v swift >/dev/null 2>&1; then
55+ echo "Swift is already available:"
56+ swift --version
57+ else
58+ echo "Installing Swift using Swiftly..."
59+
60+ # Install Swiftly
61+ curl -L https://swift-server.github.io/swiftly/swiftly-install.sh | bash
62+
63+ # Add Swiftly to PATH for current session
64+ export PATH="$HOME/.local/bin:$PATH"
65+ echo "$HOME/.local/bin" >> $GITHUB_PATH
66+
67+ # Install latest Swift toolchain
68+ swiftly install latest
69+ swiftly use latest
70+
71+ echo "Swift installation completed:"
72+ swift --version
73+ fi
74+
75+ - name : Cache Swift Package Manager
76+ uses : actions/cache@v4
77+ with :
78+ path : |
79+ .build
80+ ~/.cache/org.swift.swiftpm
81+ key : ${{ runner.os }}-${{ matrix.arch }}-spm-${{ hashFiles('Package.swift', 'Package.resolved') }}
82+ restore-keys : |
83+ ${{ runner.os }}-${{ matrix.arch }}-spm-
84+ ${{ runner.os }}-spm-
85+
86+ - name : Build native binary
87+ run : |
88+ echo "Building natively for ${{ matrix.arch }} on ${{ matrix.runner }}..."
89+ swift --version
90+
91+ echo 'Resolving dependencies...'
92+ swift package resolve
93+
94+ echo 'Building release binary with static linking...'
95+ swift build -c release --triple ${{ matrix.triple }} -Xswiftc -Osize --static-swift-stdlib
96+
97+ echo 'Stripping binary for size optimization...'
98+ strip .build/${{ matrix.triple }}/release/swift-dependency-audit
99+
100+ echo "✅ Native build completed successfully for ${{ matrix.arch }}"
101+
102+ - name : Verify binary was created and get info
103+ run : |
104+ echo "Binary information for ${{ matrix.arch }}:"
105+ ls -la .build/${{ matrix.triple }}/release/swift-dependency-audit
106+ file .build/${{ matrix.triple }}/release/swift-dependency-audit
107+ du -h .build/${{ matrix.triple }}/release/swift-dependency-audit
108+
109+ - name : Test binary functionality
110+ run : |
111+ echo "Testing static binary functionality for ${{ matrix.arch }}..."
112+
113+ # Since we're running natively, we can test functionality on both architectures
114+ .build/${{ matrix.triple }}/release/swift-dependency-audit --version
115+ .build/${{ matrix.triple }}/release/swift-dependency-audit --help
116+
117+ # Verify static linking (should have no dynamic Swift dependencies)
118+ echo "Verifying static linking..."
119+ ldd .build/${{ matrix.triple }}/release/swift-dependency-audit || echo "✅ Static binary - no dynamic dependencies"
120+
121+ echo "✅ Binary functionality tests passed for ${{ matrix.arch }}"
122+
123+
124+ - name : Upload binary artifacts
125+ if : inputs.upload_artifacts
126+ uses : actions/upload-artifact@v4
127+ with :
128+ name : linux-${{ matrix.arch }}-binary
129+ path : .build/${{ matrix.triple }}/release/swift-dependency-audit
130+ retention-days : ${{ inputs.artifact_retention_days }}
0 commit comments