Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 53 additions & 43 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,59 +30,68 @@ jobs:
path: .build/apple/Products/Release/subtree
retention-days: 5

linux:
name: Build Linux binaries
runs-on: ubuntu-20.04
linux-amd64:
name: Build Linux x86_64 binary
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Install cross-binutils for aarch64
run: sudo apt install -y binutils-aarch64-linux-gnu

- name: Build and export binaries
uses: docker/build-push-action@v5
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
target: output
platforms: linux/amd64
build-args: |
SWIFT_SDK_ID=x86_64-swift-linux-musl
outputs: type=local,dest=artifacts

- name: Test and organize binaries
- name: Assert x86_64 binary
run: |
# Test that binaries were built successfully
echo "✅ Linux AMD64 binary built: $(file artifacts/linux_amd64/subtree)"
echo "✅ Linux ARM64 binary built: $(file artifacts/linux_arm64/subtree)"

# Strip and organize AMD64 binary
strip artifacts/linux_amd64/subtree
mv artifacts/linux_amd64/subtree "${HOME}/subtree_linux"

# Strip and organize ARM64 binary
aarch64-linux-gnu-strip artifacts/linux_arm64/subtree
mv artifacts/linux_arm64/subtree "${HOME}/subtree_linux_aarch64"

file artifacts/subtree
file artifacts/subtree | grep -q 'x86-64' # fail if not x86_64
- name: Strip and prepare binary
run: |
strip artifacts/subtree
mv artifacts/subtree subtree_linux
- name: Upload AMD64 Artifact
uses: actions/upload-artifact@v4
with:
name: subtree_linux
path: ~/subtree_linux
path: subtree_linux
retention-days: 5


linux-arm64:
name: Build Linux aarch64 binary
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/build-push-action@v5
with:
context: .
target: output
platforms: linux/arm64
build-args: |
SWIFT_SDK_ID=aarch64-swift-linux-musl
outputs: type=local,dest=artifacts
- name: Assert aarch64 binary
run: |
file artifacts/subtree
file artifacts/subtree | grep -q 'ARM aarch64'
- name: Strip and prepare binary
run: |
strip artifacts/subtree
mv artifacts/subtree subtree_linux_aarch64
- name: Upload ARM64 Artifact
uses: actions/upload-artifact@v4
with:
name: subtree_linux_aarch64
path: ~/subtree_linux_aarch64
path: subtree_linux_aarch64
retention-days: 5

upload:
name: Upload release artifacts
runs-on: ubuntu-20.04
needs: [macos, linux]
runs-on: ubuntu-latest
needs: [macos, linux-amd64, linux-arm64]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
Expand All @@ -91,9 +100,6 @@ jobs:
uses: actions/download-artifact@v4
with:
path: downloaded_artifacts

- name: Display structure of downloaded files
run: ls -R downloaded_artifacts

- name: Prepare release binaries
run: |
Expand Down Expand Up @@ -125,7 +131,7 @@ jobs:
cp downloaded_artifacts/subtree_linux_aarch64/subtree_linux_aarch64 "${BUNDLE_DIR}/linux-arm64/subtree"

# Create artifact bundle manifest
cat > "${BUNDLE_DIR}/artifactbundle.json" << EOF
cat > "${BUNDLE_DIR}/info.json" << EOF
{
"schemaVersion": "1.0",
"artifacts": {
Expand All @@ -151,12 +157,16 @@ jobs:
}
EOF

# Create zip archive
zip -r "subtree.artifactbundle.zip" "${BUNDLE_DIR}"
# Create zip archive with maximum compression
7z a -tzip -mx=9 "subtree.artifactbundle.zip" "${BUNDLE_DIR}"

- name: Upload release binaries
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
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'
run: |
VERSION="${{ github.event.release.tag_name }}"
gh release upload "${VERSION}" \
"subtree_${VERSION}_macos" \
"subtree_${VERSION}_linux_x86_64" \
"subtree_${VERSION}_linux_arm64" \
"subtree.artifactbundle.zip"
47 changes: 23 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
# syntax=docker/dockerfile:1

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

# Install Swift static SDK for better portability
# Install Swift static SDK (version must match base toolchain)
RUN swift sdk install \
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 \
--checksum 111c6f7d280a651208b8c74c0521dd99365d785c1976a6e23162f55f65379ac6
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 \
--checksum 111c6f7d280a651208b8c74c0521dd99365d785c1976a6e23162f55f65379ac6

# Copy source files
COPY . /workspace

# Build with static SDK and cross-compilation support
ARG TARGETPLATFORM
RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM \
echo "Building for platform: $TARGETPLATFORM" && \
swift sdk list && \
case "$TARGETPLATFORM" in \
"linux/amd64") \
swift build -c release --swift-sdk swift-6.1-RELEASE_static-linux-0.0.1 && \
cp /workspace/.build/*/release/subtree /workspace/subtree ;; \
"linux/arm64") \
swift build -c release --swift-sdk swift-6.1-RELEASE_static-linux-0.0.1 && \
cp /workspace/.build/*/release/subtree /workspace/subtree ;; \
*) \
echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
esac
# Install `file` utility
RUN apt-get update && apt-get install -y --no-install-recommends file \
&& rm -rf /var/lib/apt/lists/*

# Map platform -> correct SDK ID if not provided
RUN if [ -z "$SWIFT_SDK_ID" ]; then \
case "$TARGETPLATFORM" in \
linux/amd64) SWIFT_SDK_ID=x86_64-swift-linux-musl ;; \
linux/arm64) SWIFT_SDK_ID=aarch64-swift-linux-musl ;; \
*) echo "Unsupported TARGETPLATFORM: $TARGETPLATFORM" && exit 1 ;; \
esac; \
fi && \
echo "Using Swift SDK: $SWIFT_SDK_ID" && \
swift build -c release --swift-sdk "$SWIFT_SDK_ID" -Xswiftc -Osize && \
cp ".build/$SWIFT_SDK_ID/release/subtree" /workspace/subtree && \
file /workspace/subtree

# Final minimal runtime image
FROM scratch AS runner
COPY --from=builder /workspace/subtree /usr/bin/subtree
ENTRYPOINT [ "/usr/bin/subtree" ]
ENTRYPOINT ["/usr/bin/subtree"]
CMD ["--help"]

# Output stage for CI extraction
FROM scratch AS output
COPY --from=builder /workspace/subtree /subtree
COPY --from=builder /workspace/subtree /subtree