Skip to content

Commit 73a9c02

Browse files
authored
Binary releases (#2)
* ci: update Linux build runner from ubuntu-20.04 to ubuntu-latest * chore: update CI runner from ubuntu-20.04 to ubuntu-latest * build: add explicit architecture flags for x86_64 and arm64 builds * ci: add architecture verification checks and remove explicit arch flags * refactor: simplify Docker build by removing cross-compilation and using native build only * ci: split Linux build job into separate AMD64 and ARM64 workflows * fix: handle multiple possible binary output paths in release workflow * fix: add multi-architecture build support using TARGETPLATFORM in Dockerfile * refactor: simplify Dockerfile by removing debug logging and redundant TARGETPLATFORM arg * refactor: simplify build pipeline by using native architecture compilation * chore: rename bundle manifest to info.json and use 7z for better compression * feat: enable cross-compilation of Linux binaries using Swift static SDK * ci: improve release workflow with descriptive job names and simplified artifact upload
1 parent 6a0718c commit 73a9c02

File tree

2 files changed

+76
-67
lines changed

2 files changed

+76
-67
lines changed

.github/workflows/release.yml

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,59 +30,68 @@ jobs:
3030
path: .build/apple/Products/Release/subtree
3131
retention-days: 5
3232

33-
linux:
34-
name: Build Linux binaries
35-
runs-on: ubuntu-20.04
33+
linux-amd64:
34+
name: Build Linux x86_64 binary
35+
runs-on: ubuntu-latest
3636
steps:
37-
- name: Checkout
38-
uses: actions/checkout@v4
39-
40-
- name: Set up Docker Buildx
41-
uses: docker/setup-buildx-action@v3
42-
43-
- name: Install cross-binutils for aarch64
44-
run: sudo apt install -y binutils-aarch64-linux-gnu
45-
46-
- name: Build and export binaries
47-
uses: docker/build-push-action@v5
37+
- uses: actions/checkout@v4
38+
- uses: docker/setup-buildx-action@v3
39+
- uses: docker/build-push-action@v5
4840
with:
4941
context: .
50-
platforms: linux/amd64,linux/arm64
5142
target: output
43+
platforms: linux/amd64
44+
build-args: |
45+
SWIFT_SDK_ID=x86_64-swift-linux-musl
5246
outputs: type=local,dest=artifacts
53-
54-
- name: Test and organize binaries
47+
- name: Assert x86_64 binary
5548
run: |
56-
# Test that binaries were built successfully
57-
echo "✅ Linux AMD64 binary built: $(file artifacts/linux_amd64/subtree)"
58-
echo "✅ Linux ARM64 binary built: $(file artifacts/linux_arm64/subtree)"
59-
60-
# Strip and organize AMD64 binary
61-
strip artifacts/linux_amd64/subtree
62-
mv artifacts/linux_amd64/subtree "${HOME}/subtree_linux"
63-
64-
# Strip and organize ARM64 binary
65-
aarch64-linux-gnu-strip artifacts/linux_arm64/subtree
66-
mv artifacts/linux_arm64/subtree "${HOME}/subtree_linux_aarch64"
67-
49+
file artifacts/subtree
50+
file artifacts/subtree | grep -q 'x86-64' # fail if not x86_64
51+
- name: Strip and prepare binary
52+
run: |
53+
strip artifacts/subtree
54+
mv artifacts/subtree subtree_linux
6855
- name: Upload AMD64 Artifact
6956
uses: actions/upload-artifact@v4
7057
with:
7158
name: subtree_linux
72-
path: ~/subtree_linux
59+
path: subtree_linux
7360
retention-days: 5
74-
61+
62+
linux-arm64:
63+
name: Build Linux aarch64 binary
64+
runs-on: ubuntu-24.04-arm
65+
steps:
66+
- uses: actions/checkout@v4
67+
- uses: docker/setup-buildx-action@v3
68+
- uses: docker/build-push-action@v5
69+
with:
70+
context: .
71+
target: output
72+
platforms: linux/arm64
73+
build-args: |
74+
SWIFT_SDK_ID=aarch64-swift-linux-musl
75+
outputs: type=local,dest=artifacts
76+
- name: Assert aarch64 binary
77+
run: |
78+
file artifacts/subtree
79+
file artifacts/subtree | grep -q 'ARM aarch64'
80+
- name: Strip and prepare binary
81+
run: |
82+
strip artifacts/subtree
83+
mv artifacts/subtree subtree_linux_aarch64
7584
- name: Upload ARM64 Artifact
7685
uses: actions/upload-artifact@v4
7786
with:
7887
name: subtree_linux_aarch64
79-
path: ~/subtree_linux_aarch64
88+
path: subtree_linux_aarch64
8089
retention-days: 5
8190

8291
upload:
8392
name: Upload release artifacts
84-
runs-on: ubuntu-20.04
85-
needs: [macos, linux]
93+
runs-on: ubuntu-latest
94+
needs: [macos, linux-amd64, linux-arm64]
8695
steps:
8796
- name: Checkout the repository
8897
uses: actions/checkout@v4
@@ -91,9 +100,6 @@ jobs:
91100
uses: actions/download-artifact@v4
92101
with:
93102
path: downloaded_artifacts
94-
95-
- name: Display structure of downloaded files
96-
run: ls -R downloaded_artifacts
97103

98104
- name: Prepare release binaries
99105
run: |
@@ -125,7 +131,7 @@ jobs:
125131
cp downloaded_artifacts/subtree_linux_aarch64/subtree_linux_aarch64 "${BUNDLE_DIR}/linux-arm64/subtree"
126132
127133
# Create artifact bundle manifest
128-
cat > "${BUNDLE_DIR}/artifactbundle.json" << EOF
134+
cat > "${BUNDLE_DIR}/info.json" << EOF
129135
{
130136
"schemaVersion": "1.0",
131137
"artifacts": {
@@ -151,12 +157,16 @@ jobs:
151157
}
152158
EOF
153159
154-
# Create zip archive
155-
zip -r "subtree.artifactbundle.zip" "${BUNDLE_DIR}"
160+
# Create zip archive with maximum compression
161+
7z a -tzip -mx=9 "subtree.artifactbundle.zip" "${BUNDLE_DIR}"
156162
157163
- name: Upload release binaries
158-
uses: skx/github-action-publish-binaries@master
159164
env:
160165
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
161-
with:
162-
args: 'subtree_${{ github.event.release.tag_name }}_macos subtree_${{ github.event.release.tag_name }}_linux_x86_64 subtree_${{ github.event.release.tag_name }}_linux_arm64 subtree.artifactbundle.zip'
166+
run: |
167+
VERSION="${{ github.event.release.tag_name }}"
168+
gh release upload "${VERSION}" \
169+
"subtree_${VERSION}_macos" \
170+
"subtree_${VERSION}_linux_x86_64" \
171+
"subtree_${VERSION}_linux_arm64" \
172+
"subtree.artifactbundle.zip"

Dockerfile

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11
# syntax=docker/dockerfile:1
22

3-
# Base image and static SDK have to be updated together.
43
FROM --platform=$BUILDPLATFORM swift:6.1 AS builder
4+
ARG TARGETPLATFORM
5+
ARG SWIFT_SDK_ID
56
WORKDIR /workspace
67

7-
# Install Swift static SDK for better portability
8+
# Install Swift static SDK (version must match base toolchain)
89
RUN swift sdk install \
9-
https://download.swift.org/swift-6.1-release/static-sdk/swift-6.1-RELEASE/swift-6.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz \
10-
--checksum 111c6f7d280a651208b8c74c0521dd99365d785c1976a6e23162f55f65379ac6
10+
https://download.swift.org/swift-6.1-release/static-sdk/swift-6.1-RELEASE/swift-6.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz \
11+
--checksum 111c6f7d280a651208b8c74c0521dd99365d785c1976a6e23162f55f65379ac6
1112

12-
# Copy source files
1313
COPY . /workspace
1414

15-
# Build with static SDK and cross-compilation support
16-
ARG TARGETPLATFORM
17-
RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM \
18-
echo "Building for platform: $TARGETPLATFORM" && \
19-
swift sdk list && \
20-
case "$TARGETPLATFORM" in \
21-
"linux/amd64") \
22-
swift build -c release --swift-sdk swift-6.1-RELEASE_static-linux-0.0.1 && \
23-
cp /workspace/.build/*/release/subtree /workspace/subtree ;; \
24-
"linux/arm64") \
25-
swift build -c release --swift-sdk swift-6.1-RELEASE_static-linux-0.0.1 && \
26-
cp /workspace/.build/*/release/subtree /workspace/subtree ;; \
27-
*) \
28-
echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
29-
esac
15+
# Install `file` utility
16+
RUN apt-get update && apt-get install -y --no-install-recommends file \
17+
&& rm -rf /var/lib/apt/lists/*
18+
19+
# Map platform -> correct SDK ID if not provided
20+
RUN if [ -z "$SWIFT_SDK_ID" ]; then \
21+
case "$TARGETPLATFORM" in \
22+
linux/amd64) SWIFT_SDK_ID=x86_64-swift-linux-musl ;; \
23+
linux/arm64) SWIFT_SDK_ID=aarch64-swift-linux-musl ;; \
24+
*) echo "Unsupported TARGETPLATFORM: $TARGETPLATFORM" && exit 1 ;; \
25+
esac; \
26+
fi && \
27+
echo "Using Swift SDK: $SWIFT_SDK_ID" && \
28+
swift build -c release --swift-sdk "$SWIFT_SDK_ID" -Xswiftc -Osize && \
29+
cp ".build/$SWIFT_SDK_ID/release/subtree" /workspace/subtree && \
30+
file /workspace/subtree
3031

31-
# Final minimal runtime image
3232
FROM scratch AS runner
3333
COPY --from=builder /workspace/subtree /usr/bin/subtree
34-
ENTRYPOINT [ "/usr/bin/subtree" ]
34+
ENTRYPOINT ["/usr/bin/subtree"]
3535
CMD ["--help"]
3636

37-
# Output stage for CI extraction
3837
FROM scratch AS output
39-
COPY --from=builder /workspace/subtree /subtree
38+
COPY --from=builder /workspace/subtree /subtree

0 commit comments

Comments
 (0)