From 3cf5be11acd2b59889281fffcf85fe4faad23639 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Wed, 27 Nov 2024 22:58:56 +0000 Subject: [PATCH 01/30] Pipeline for building static linux binaries --- .dockerignore | 1 + Dockerfile | 77 +++++++++--------------------------- tools/build-linux-release.sh | 27 +++++++++++++ 3 files changed, 46 insertions(+), 59 deletions(-) create mode 100755 tools/build-linux-release.sh diff --git a/.dockerignore b/.dockerignore index 4f34bcf922..1acad6d4e5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ !Source !Tests !Package.* +!tools/build-linux-release.sh diff --git a/Dockerfile b/Dockerfile index d4b0c2f92e..a6e7487459 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,64 +1,23 @@ -# Explicitly specify `noble` to keep the Swift & Ubuntu images in sync. -ARG BUILDER_IMAGE=swift:6.0-noble -ARG RUNTIME_IMAGE=ubuntu:noble +# syntax=docker/dockerfile:1 -# Builder image -FROM ${BUILDER_IMAGE} AS builder -RUN apt-get update && apt-get install -y \ - libcurl4-openssl-dev \ - libxml2-dev \ - && rm -r /var/lib/apt/lists/* -WORKDIR /workdir/ -COPY Plugins Plugins/ -COPY Source Source/ -COPY Tests Tests/ -COPY Package.* ./ +# Base image and static SDK have to be updated together. +FROM swift:6.0.1 AS builder +WORKDIR /workspace +RUN swift sdk install \ + https://download.swift.org/swift-6.0.1-release/static-sdk/swift-6.0.1-RELEASE/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz \ + --checksum d4f46ba40e11e697387468e18987ee622908bc350310d8af54eb5e17c2ff5481 -RUN swift package update -ARG SWIFT_FLAGS="-c release -Xswiftc -static-stdlib -Xlinker -l_CFURLSessionInterface -Xlinker -l_CFXMLInterface -Xlinker -lcurl -Xlinker -lxml2 -Xswiftc -I. -Xlinker -fuse-ld=lld -Xlinker -L/usr/lib/swift/linux" -RUN swift build $SWIFT_FLAGS --product swiftlint -RUN mv `swift build $SWIFT_FLAGS --show-bin-path`/swiftlint /usr/bin -RUN strip /usr/bin/swiftlint +COPY . /workspace +ARG TARGETPLATFORM +RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM \ + ./tools/build-linux-release.sh && \ + cp /workspace/.build/release/swiftlint /workspace -# Runtime image -FROM ${RUNTIME_IMAGE} -LABEL org.opencontainers.image.source=https://github.com/realm/SwiftLint -RUN apt-get update && apt-get install -y \ - libcurl4 \ - libxml2 \ - && rm -r /var/lib/apt/lists/* -COPY --from=builder /usr/lib/libsourcekitdInProc.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftBasicFormat.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftCompilerPluginMessageHandling.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftDiagnostics.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftIDEUtils.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftOperators.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftParser.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftParserDiagnostics.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftRefactor.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftSyntax.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftSyntaxBuilder.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftSyntaxMacroExpansion.so /usr/lib -COPY --from=builder /usr/lib/swift/host/libSwiftSyntaxMacros.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/lib_FoundationICU.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libBlocksRuntime.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libdispatch.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libFoundation.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libFoundationInternationalization.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libFoundationEssentials.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libFoundationNetworking.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libFoundationXML.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswift_Concurrency.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswift_RegexParser.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswift_StringProcessing.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswiftCore.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswiftDispatch.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswiftGlibc.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswiftSynchronization.so /usr/lib -COPY --from=builder /usr/lib/swift/linux/libswiftSwiftOnoneSupport.so /usr/lib -COPY --from=builder /usr/bin/swiftlint /usr/bin +FROM scratch AS runner +COPY --from=builder /workspace/swiftlint /usr/bin/swiftlint -RUN swiftlint version -RUN echo "_ = 0" | swiftlint --use-stdin +RUN /usr/bin/swiftlint version +RUN echo "_ = 0" | /usr/bin/swiftlint --use-stdin -CMD ["swiftlint"] +ENTRYPOINT [ "/usr/bin/swiftlint" ] +CMD ["."] diff --git a/tools/build-linux-release.sh b/tools/build-linux-release.sh new file mode 100755 index 0000000000..a82f248567 --- /dev/null +++ b/tools/build-linux-release.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -eo pipefail + +pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null + +BUILD_ARGS=( + --product swiftlint + --configuration release + -Xlinker -S +) + +if [[ -z "$TARGETPLATFORM" ]]; then + ARCH="$(uname -m)" +else + if [[ "$TARGETPLATFORM" = "linux/amd64" ]]; then + ARCH="x86_64" + elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]; then + ARCH="aarch64" + else + echo "Unsupported target platform: $TARGETPLATFORM" + exit 1 + fi +fi +BUILD_ARGS+=(--swift-sdk "${ARCH}-swift-linux-musl") + +swift build "${BUILD_ARGS[@]}" From 1def7a23e303ee96972053d5b3c63cfccf7f4baa Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Wed, 27 Nov 2024 23:02:33 +0000 Subject: [PATCH 02/30] Build for arm and amd --- .github/workflows/docker.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 19cdec68eb..4711ff147e 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -25,6 +25,9 @@ jobs: build: name: Build Docker Image runs-on: ubuntu-24.04 + strategy: + matrix: + platform: [amd64, arm64] steps: - name: Define variables on push to `main` if: github.event_name == 'push' @@ -69,16 +72,16 @@ jobs: with: context: . tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }} - platforms: linux/amd64 + platforms: linux/${{ matrix.platform }} outputs: ${{ env.OUTPUT_TYPE }} - name: Rename binary artifact if: contains(env.OUTPUT_TYPE, 'local') - run: mv artifacts/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_amd64 + run: mv artifacts/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_${{ matrix.platform }} - name: Upload binary artifact if: contains(env.OUTPUT_TYPE, 'local') uses: actions/upload-artifact@v4 with: - name: swiftlint_linux_amd64 - path: artifacts/usr/bin/swiftlint_linux_amd64 + name: swiftlint_linux_${{ matrix.platform }} + path: artifacts/usr/bin/swiftlint_linux_${{ matrix.platform }} if-no-files-found: error retention-days: 2 From 202395ad51a65c06784efda9ef2434e8a0db2c9c Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Sat, 8 Mar 2025 16:53:56 +0000 Subject: [PATCH 03/30] Update swift linux sdk in dockerfile --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index a6e7487459..b971415377 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ # syntax=docker/dockerfile:1 # Base image and static SDK have to be updated together. -FROM swift:6.0.1 AS builder +FROM swift:6.0.3 AS builder WORKDIR /workspace RUN swift sdk install \ - https://download.swift.org/swift-6.0.1-release/static-sdk/swift-6.0.1-RELEASE/swift-6.0.1-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz \ - --checksum d4f46ba40e11e697387468e18987ee622908bc350310d8af54eb5e17c2ff5481 + https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz \ + --checksum 67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd COPY . /workspace ARG TARGETPLATFORM From 87df6b63d959734540155d85aa6c03c3bdd7b567 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Sat, 8 Mar 2025 17:10:00 +0000 Subject: [PATCH 04/30] Fix Dockerfile --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index b971415377..07597f0011 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,8 +16,5 @@ RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM \ FROM scratch AS runner COPY --from=builder /workspace/swiftlint /usr/bin/swiftlint -RUN /usr/bin/swiftlint version -RUN echo "_ = 0" | /usr/bin/swiftlint --use-stdin - ENTRYPOINT [ "/usr/bin/swiftlint" ] CMD ["."] From 5625f42b229ba870936aa8bbe8a6b1b30e46ca28 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Sat, 8 Mar 2025 17:25:58 +0000 Subject: [PATCH 05/30] Ensure that linux arm binary is uploaded as an artifact --- .github/workflows/docker.yml | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4711ff147e..38c8b97d86 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -25,9 +25,6 @@ jobs: build: name: Build Docker Image runs-on: ubuntu-24.04 - strategy: - matrix: - platform: [amd64, arm64] steps: - name: Define variables on push to `main` if: github.event_name == 'push' @@ -62,6 +59,8 @@ jobs: REPOSITORY: ${{ github.repository }} - 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: Login to GitHub registry uses: docker/login-action@v3 with: @@ -72,16 +71,29 @@ jobs: with: context: . tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }} - platforms: linux/${{ matrix.platform }} + platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} - - name: Rename binary artifact + - name: Strip and move binary artifacts if: contains(env.OUTPUT_TYPE, 'local') - run: mv artifacts/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_${{ matrix.platform }} - - name: Upload binary artifact + run: | + strip artifacts/linux_amd64/usr/bin/swiftformat + mv artifacts/linux_amd64/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_amd64 + aarch64-linux-gnu-strip artifacts/linux_arm64/usr/bin/swiftformat + mv artifacts/linux_arm64/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_arm64 + + - name: Upload AMD64 binary artifact + if: contains(env.OUTPUT_TYPE, 'local') + uses: actions/upload-artifact@v4 + with: + name: swiftlint_linux_amd64 + path: artifacts/usr/bin/swiftlint_linux_amd64 + if-no-files-found: error + retention-days: 2 + - name: Upload ARM64 binary artifact if: contains(env.OUTPUT_TYPE, 'local') uses: actions/upload-artifact@v4 with: - name: swiftlint_linux_${{ matrix.platform }} - path: artifacts/usr/bin/swiftlint_linux_${{ matrix.platform }} + name: swiftlint_linux_arm64 + path: artifacts/usr/bin/swiftlint_linux_arm64 if-no-files-found: error retention-days: 2 From d48533a303ff3e4e9c3b5dd4796d05aeb2704094 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Sat, 8 Mar 2025 17:32:48 +0000 Subject: [PATCH 06/30] Add arm64 to arifact bundle --- tools/info.json.template | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/info.json.template b/tools/info.json.template index 0829f935da..149e68bb7a 100644 --- a/tools/info.json.template +++ b/tools/info.json.template @@ -12,6 +12,10 @@ { "path": "swiftlint-__VERSION__-linux-gnu/bin/swiftlint", "supportedTriples": ["x86_64-unknown-linux-gnu"] + }, + { + "path": "swiftlint-__VERSION__-linux-gnu/bin/swiftlint_arm64", + "supportedTriples": ["x86_64-unknown-linux-gnu", "arm64-unknown-linux-gnu"] } ] } From a3454cb8ea28f823b3e81be2471172179fd11f04 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Sat, 8 Mar 2025 17:40:54 +0000 Subject: [PATCH 07/30] Hook up installables in makefile This should be fully backwards compatible, so that existing amd64 binaries, including paths etc. are not affected --- Makefile | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d96690f97b..6128f12509 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ SWIFTLINT_EXECUTABLE_PARENT=.build/universal SWIFTLINT_EXECUTABLE=$(SWIFTLINT_EXECUTABLE_PARENT)/swiftlint SWIFTLINT_EXECUTABLE_LINUX_PARENT=.build/linux SWIFTLINT_EXECUTABLE_LINUX_AMD64=$(SWIFTLINT_EXECUTABLE_LINUX_PARENT)/swiftlint_linux_amd64 +SWIFTLINT_EXECUTABLE_LINUX_ARM64=$(SWIFTLINT_EXECUTABLE_LINUX_PARENT)/swiftlint_linux_arm64 ARTIFACT_BUNDLE_PATH=$(TEMPORARY_FOLDER)/SwiftLintBinary.artifactbundle @@ -87,6 +88,11 @@ $(SWIFTLINT_EXECUTABLE_LINUX_AMD64): docker run --platform linux/amd64 "ghcr.io/realm/swiftlint:$(VERSION_STRING)" cat /usr/bin/swiftlint > "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" chmod +x "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" +$(SWIFTLINT_EXECUTABLE_LINUX_ARM64): + mkdir -p "$(SWIFTLINT_EXECUTABLE_LINUX_PARENT)" + docker run --platform linux/arm64 "ghcr.io/realm/swiftlint:$(VERSION_STRING)" cat /usr/bin/swiftlint > "$(SWIFTLINT_EXECUTABLE_LINUX_ARM64)" + chmod +x "$(SWIFTLINT_EXECUTABLE_LINUX_ARM64)" + build_with_disable_sandbox: swift build --disable-sandbox $(SWIFT_BUILD_FLAGS) @@ -102,9 +108,10 @@ installables: $(SWIFTLINT_EXECUTABLE) install -d "$(TEMPORARY_FOLDER)$(BINARIES_FOLDER)" install "$(SWIFTLINT_EXECUTABLE)" "$(TEMPORARY_FOLDER)$(BINARIES_FOLDER)" -installables_linux: $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) +installables_linux: $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) install -d "$(TEMPORARY_FOLDER)$(BINARIES_FOLDER)" install "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" "$(TEMPORARY_FOLDER)$(BINARIES_FOLDER)" + install "$(SWIFTLINT_EXECUTABLE_LINUX_ARM64)" "$(TEMPORARY_FOLDER)$(BINARIES_FOLDER)" prefix_install: build_with_disable_sandbox install -d "$(PREFIX)/bin/" @@ -115,26 +122,29 @@ portable_zip: installables cp -f "$(LICENSE_PATH)" "$(TEMPORARY_FOLDER)" (cd "$(TEMPORARY_FOLDER)"; zip -yr - "swiftlint" "LICENSE") > "./portable_swiftlint.zip" -spm_artifactbundle: $(SWIFTLINT_EXECUTABLE) $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) +spm_artifactbundle: $(SWIFTLINT_EXECUTABLE) $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) mkdir -p "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-macos/bin" mkdir -p "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-linux-gnu/bin" sed 's/__VERSION__/$(VERSION_STRING)/g' tools/info.json.template > "$(ARTIFACT_BUNDLE_PATH)/info.json" cp -f "$(SWIFTLINT_EXECUTABLE)" "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-macos/bin/swiftlint" cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-linux-gnu/bin/swiftlint" + cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_ARM64)" "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-linux-gnu/bin/swiftlint_arm64" cp -f "$(LICENSE_PATH)" "$(ARTIFACT_BUNDLE_PATH)" (cd "$(TEMPORARY_FOLDER)"; zip -yr - "SwiftLintBinary.artifactbundle") > "./SwiftLintBinary.artifactbundle.zip" -zip_linux: docker_image $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) +zip_linux: docker_image $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) $(eval TMP_FOLDER := $(shell mktemp -d)) cp -f $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) "$(TMP_FOLDER)/swiftlint" + cp -f $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) "$(TMP_FOLDER)/swiftlint_arm64" cp -f "$(LICENSE_PATH)" "$(TMP_FOLDER)" - (cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "LICENSE") > "./swiftlint_linux.zip" + (cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint_arm64" "LICENSE") > "./swiftlint_linux.zip" -zip_linux_release: $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) +zip_linux_release: $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) $(eval TMP_FOLDER := $(shell mktemp -d)) cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" "$(TMP_FOLDER)/swiftlint" + cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_ARM64)" "$(TMP_FOLDER)/swiftlint_arm64" cp -f "$(LICENSE_PATH)" "$(TMP_FOLDER)" - (cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "LICENSE") > "./swiftlint_linux.zip" + (cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint_arm64" "LICENSE") > "./swiftlint_linux.zip" package: $(SWIFTLINT_EXECUTABLE) $(eval PACKAGE_ROOT := $(shell mktemp -d)) From d35102258c45f7426f6c727b5dc088bc02a40361 Mon Sep 17 00:00:00 2001 From: Bradley Mackey Date: Sat, 8 Mar 2025 17:42:23 +0000 Subject: [PATCH 08/30] Fix triple in artifact bundle --- tools/info.json.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/info.json.template b/tools/info.json.template index 149e68bb7a..63b6e2a861 100644 --- a/tools/info.json.template +++ b/tools/info.json.template @@ -15,7 +15,7 @@ }, { "path": "swiftlint-__VERSION__-linux-gnu/bin/swiftlint_arm64", - "supportedTriples": ["x86_64-unknown-linux-gnu", "arm64-unknown-linux-gnu"] + "supportedTriples": ["aarch64-unknown-linux-gnu", "arm64-unknown-linux-gnu"] } ] } From 7ec8765abb0f170ef8c76990073ffaffd4b342c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Thu, 14 Aug 2025 21:52:21 +0200 Subject: [PATCH 09/30] Update build steps --- .github/workflows/docker.yml | 22 ++----------- Dockerfile | 63 ++++++++++++++++++++++++++++++------ tools/build-linux-release.sh | 36 +++++++++++++-------- 3 files changed, 79 insertions(+), 42 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 38c8b97d86..e56f1bac7d 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -73,27 +73,11 @@ jobs: tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }} platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} - - name: Strip and move binary artifacts - if: contains(env.OUTPUT_TYPE, 'local') - run: | - strip artifacts/linux_amd64/usr/bin/swiftformat - mv artifacts/linux_amd64/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_amd64 - aarch64-linux-gnu-strip artifacts/linux_arm64/usr/bin/swiftformat - mv artifacts/linux_arm64/usr/bin/swiftlint artifacts/usr/bin/swiftlint_linux_arm64 - - - name: Upload AMD64 binary artifact - if: contains(env.OUTPUT_TYPE, 'local') - uses: actions/upload-artifact@v4 - with: - name: swiftlint_linux_amd64 - path: artifacts/usr/bin/swiftlint_linux_amd64 - if-no-files-found: error - retention-days: 2 - - name: Upload ARM64 binary artifact + - name: Upload binary artifacts if: contains(env.OUTPUT_TYPE, 'local') uses: actions/upload-artifact@v4 with: - name: swiftlint_linux_arm64 - path: artifacts/usr/bin/swiftlint_linux_arm64 + name: swiftlint_linux + path: swiftlint_linux_* if-no-files-found: error retention-days: 2 diff --git a/Dockerfile b/Dockerfile index 07597f0011..93b1e19c6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,65 @@ # syntax=docker/dockerfile:1 # Base image and static SDK have to be updated together. -FROM swift:6.0.3 AS builder +ARG SWIFT_VERSION=6.1.2 +ARG SWIFT_SDK_VERSION=0.0.1 +ARG SWIFT_SDK_CHECKSUM=df0b40b9b582598e7e3d70c82ab503fd6fbfdff71fd17e7f1ab37115a0665b3b +ARG RUNTIME_IMAGE=ubuntu:noble +FROM swift:${SWIFT_VERSION}-noble AS builder + +LABEL org.opencontainers.image.source=https://github.com/realm/SwiftLint + +RUN apt-get update +RUN apt-get install -y libcurl4-openssl-dev libxml2-dev +RUN rm -r /var/lib/apt/lists/* + WORKDIR /workspace +COPY Plugins Plugins/ +COPY Source Source/ +COPY Tests Tests/ +COPY Package.* ./ +COPY tools/build-linux-release.sh tools/ + RUN swift sdk install \ - https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz \ - --checksum 67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd + https://download.swift.org/swift-${SWIFT_VERSION}-release/static-sdk/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE_static-linux-${SWIFT_SDK_VERSION}.artifactbundle.tar.gz \ + --checksum ${SWIFT_SDK_CHECKSUM} -COPY . /workspace ARG TARGETPLATFORM -RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM \ - ./tools/build-linux-release.sh && \ - cp /workspace/.build/release/swiftlint /workspace +RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM ./tools/build-linux-release.sh + +COPY --from=builder /usr/lib/libsourcekitdInProc.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftBasicFormat.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftCompilerPluginMessageHandling.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftDiagnostics.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftIDEUtils.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftOperators.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftParser.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftParserDiagnostics.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftRefactor.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftSyntax.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftSyntaxBuilder.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftSyntaxMacroExpansion.so /usr/lib +COPY --from=builder /usr/lib/swift/host/libSwiftSyntaxMacros.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/lib_FoundationICU.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libBlocksRuntime.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libdispatch.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libFoundation.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libFoundationInternationalization.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libFoundationEssentials.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libFoundationNetworking.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libFoundationXML.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswift_Concurrency.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswift_RegexParser.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswift_StringProcessing.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswiftCore.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswiftDispatch.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswiftGlibc.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswiftSynchronization.so /usr/lib +COPY --from=builder /usr/lib/swift/linux/libswiftSwiftOnoneSupport.so /usr/lib +COPY --from=builder /workspace/swiftlint_linux_* /usr/bin/ -FROM scratch AS runner -COPY --from=builder /workspace/swiftlint /usr/bin/swiftlint +RUN swiftlint version +RUN echo "_ = 0" | swiftlint --use-stdin ENTRYPOINT [ "/usr/bin/swiftlint" ] CMD ["."] diff --git a/tools/build-linux-release.sh b/tools/build-linux-release.sh index a82f248567..be7b13183e 100755 --- a/tools/build-linux-release.sh +++ b/tools/build-linux-release.sh @@ -4,24 +4,32 @@ set -eo pipefail pushd "$(dirname "${BASH_SOURCE[0]}")/.." > /dev/null +if [[ "$TARGETPLATFORM" = "linux/amd64" ]]; then + ARCH="x86_64" + STRIP_CMD="strip" +elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]; then + ARCH="aarch64" + STRIP_CMD="aarch64-linux-gnu-strip" +else + echo "Unsupported target platform: $TARGETPLATFORM" + exit 1 +fi + BUILD_ARGS=( --product swiftlint --configuration release + --swift-sdk "${ARCH}-swift-linux-musl" + -Xswiftc -I. + -Xswiftc -static-stdlib + -Xlinker -l_CFURLSessionInterface + -Xlinker -l_CFXMLInterface + -Xlinker -lcurl + -Xlinker -lxml2 + -Xlinker -fuse-ld=lld + -Xlinker -L/usr/lib/swift/linux -Xlinker -S ) -if [[ -z "$TARGETPLATFORM" ]]; then - ARCH="$(uname -m)" -else - if [[ "$TARGETPLATFORM" = "linux/amd64" ]]; then - ARCH="x86_64" - elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]; then - ARCH="aarch64" - else - echo "Unsupported target platform: $TARGETPLATFORM" - exit 1 - fi -fi -BUILD_ARGS+=(--swift-sdk "${ARCH}-swift-linux-musl") - swift build "${BUILD_ARGS[@]}" +mv ".build/release/swiftlint" "swiftlint_linux_${ARCH}" +${STRIP_CMD} "swiftlint_linux_${ARCH}" From d983d4cbdaa37b1a56e1715d61f2934c5e50e50b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Thu, 14 Aug 2025 21:52:32 +0200 Subject: [PATCH 10/30] Build in PR --- .github/workflows/docker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e56f1bac7d..9b69ec2cef 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -16,6 +16,7 @@ on: description: 'Docker tag' required: true type: string + pull_request: permissions: contents: read @@ -70,7 +71,7 @@ jobs: - uses: docker/build-push-action@v6 with: context: . - tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }} + tags: ghcr.io/${{ env.REPOSITORY_LC }}:test platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} - name: Upload binary artifacts From 0abcd82468f5badbffc69b51d6b8c2e1c836d9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Thu, 14 Aug 2025 21:58:06 +0200 Subject: [PATCH 11/30] Build without SDK --- Dockerfile | 4 ---- tools/build-linux-release.sh | 4 +--- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 93b1e19c6f..fb57b581b0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,10 +20,6 @@ COPY Tests Tests/ COPY Package.* ./ COPY tools/build-linux-release.sh tools/ -RUN swift sdk install \ - https://download.swift.org/swift-${SWIFT_VERSION}-release/static-sdk/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE_static-linux-${SWIFT_SDK_VERSION}.artifactbundle.tar.gz \ - --checksum ${SWIFT_SDK_CHECKSUM} - ARG TARGETPLATFORM RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM ./tools/build-linux-release.sh diff --git a/tools/build-linux-release.sh b/tools/build-linux-release.sh index be7b13183e..e27d95946c 100755 --- a/tools/build-linux-release.sh +++ b/tools/build-linux-release.sh @@ -9,7 +9,7 @@ if [[ "$TARGETPLATFORM" = "linux/amd64" ]]; then STRIP_CMD="strip" elif [[ "$TARGETPLATFORM" = "linux/arm64" ]]; then ARCH="aarch64" - STRIP_CMD="aarch64-linux-gnu-strip" + STRIP_CMD="strip" else echo "Unsupported target platform: $TARGETPLATFORM" exit 1 @@ -18,7 +18,6 @@ fi BUILD_ARGS=( --product swiftlint --configuration release - --swift-sdk "${ARCH}-swift-linux-musl" -Xswiftc -I. -Xswiftc -static-stdlib -Xlinker -l_CFURLSessionInterface @@ -27,7 +26,6 @@ BUILD_ARGS=( -Xlinker -lxml2 -Xlinker -fuse-ld=lld -Xlinker -L/usr/lib/swift/linux - -Xlinker -S ) swift build "${BUILD_ARGS[@]}" From 7a736153752636e1a938e0b6f53d33b4f5eb3caa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Thu, 14 Aug 2025 22:06:07 +0200 Subject: [PATCH 12/30] Separate runtime and builder image --- Dockerfile | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb57b581b0..87085c9b54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,24 +5,25 @@ ARG SWIFT_VERSION=6.1.2 ARG SWIFT_SDK_VERSION=0.0.1 ARG SWIFT_SDK_CHECKSUM=df0b40b9b582598e7e3d70c82ab503fd6fbfdff71fd17e7f1ab37115a0665b3b ARG RUNTIME_IMAGE=ubuntu:noble -FROM swift:${SWIFT_VERSION}-noble AS builder - -LABEL org.opencontainers.image.source=https://github.com/realm/SwiftLint - -RUN apt-get update -RUN apt-get install -y libcurl4-openssl-dev libxml2-dev -RUN rm -r /var/lib/apt/lists/* +# Builder image +FROM swift:${SWIFT_VERSION}-noble AS builder WORKDIR /workspace COPY Plugins Plugins/ COPY Source Source/ COPY Tests Tests/ COPY Package.* ./ COPY tools/build-linux-release.sh tools/ - ARG TARGETPLATFORM RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM ./tools/build-linux-release.sh +# Runtime image +FROM ${RUNTIME_IMAGE} AS runtime +LABEL org.opencontainers.image.source=https://github.com/realm/SwiftLint +RUN apt-get update +RUN apt-get install -y libcurl4-openssl-dev libxml2-dev +RUN rm -r /var/lib/apt/lists/* + COPY --from=builder /usr/lib/libsourcekitdInProc.so /usr/lib COPY --from=builder /usr/lib/swift/host/libSwiftBasicFormat.so /usr/lib COPY --from=builder /usr/lib/swift/host/libSwiftCompilerPluginMessageHandling.so /usr/lib From 93d3472e66e533d26246c829c4543e1818e26231 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Thu, 14 Aug 2025 22:35:13 +0200 Subject: [PATCH 13/30] Link to specific binary --- .github/workflows/docker.yml | 4 ++++ Dockerfile | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 9b69ec2cef..440fefb963 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -74,6 +74,10 @@ jobs: tags: ghcr.io/${{ env.REPOSITORY_LC }}:test platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} + - name: Move binary artifacts + if: contains(env.OUTPUT_TYPE, 'local') + run: | + mv artifacts/usr/bin/swiftlint_linux_* . - name: Upload binary artifacts if: contains(env.OUTPUT_TYPE, 'local') uses: actions/upload-artifact@v4 diff --git a/Dockerfile b/Dockerfile index 87085c9b54..315e65b35c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -53,7 +53,9 @@ COPY --from=builder /usr/lib/swift/linux/libswiftDispatch.so /usr/lib COPY --from=builder /usr/lib/swift/linux/libswiftGlibc.so /usr/lib COPY --from=builder /usr/lib/swift/linux/libswiftSynchronization.so /usr/lib COPY --from=builder /usr/lib/swift/linux/libswiftSwiftOnoneSupport.so /usr/lib -COPY --from=builder /workspace/swiftlint_linux_* /usr/bin/ +COPY --from=builder /workspace/swiftlint_linux_* /usr/bin + +RUN ln -s /usr/bin/swiftlint_linux_* /usr/bin/swiftlint RUN swiftlint version RUN echo "_ = 0" | swiftlint --use-stdin From c1cd18a8a1194a5e92b60b451af508bdc8127110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Thu, 14 Aug 2025 23:00:40 +0200 Subject: [PATCH 14/30] Use Swift 6.0.3 --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 315e65b35c..73ecafc81d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ # syntax=docker/dockerfile:1 # Base image and static SDK have to be updated together. -ARG SWIFT_VERSION=6.1.2 +ARG SWIFT_VERSION=6.0.3 ARG SWIFT_SDK_VERSION=0.0.1 -ARG SWIFT_SDK_CHECKSUM=df0b40b9b582598e7e3d70c82ab503fd6fbfdff71fd17e7f1ab37115a0665b3b +ARG SWIFT_SDK_CHECKSUM=67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd ARG RUNTIME_IMAGE=ubuntu:noble # Builder image From 2731dce9991d829d6fb65cab9f054450308eb490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 08:20:40 +0200 Subject: [PATCH 15/30] Run `tree` command to check output --- .github/workflows/docker.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 440fefb963..e2812109da 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -68,21 +68,24 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io + - name: Install and test `tree` + run: | + sudo apt-get install -y tree + tree -C - uses: docker/build-push-action@v6 with: context: . tags: ghcr.io/${{ env.REPOSITORY_LC }}:test platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} - - name: Move binary artifacts + - name: Run `tree` if: contains(env.OUTPUT_TYPE, 'local') - run: | - mv artifacts/usr/bin/swiftlint_linux_* . + run: tree -C - name: Upload binary artifacts if: contains(env.OUTPUT_TYPE, 'local') uses: actions/upload-artifact@v4 with: name: swiftlint_linux - path: swiftlint_linux_* + path: artifacts/usr/bin/swiftlint_linux_* if-no-files-found: error retention-days: 2 From 6ecfebd504283f00dd012cf6dc1ca6ffd1dc1b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 11:31:35 +0200 Subject: [PATCH 16/30] Fix artifact pattern --- .github/workflows/docker.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e2812109da..1d284534b5 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -68,24 +68,17 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} registry: ghcr.io - - name: Install and test `tree` - run: | - sudo apt-get install -y tree - tree -C - uses: docker/build-push-action@v6 with: context: . tags: ghcr.io/${{ env.REPOSITORY_LC }}:test platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} - - name: Run `tree` - if: contains(env.OUTPUT_TYPE, 'local') - run: tree -C - name: Upload binary artifacts if: contains(env.OUTPUT_TYPE, 'local') uses: actions/upload-artifact@v4 with: name: swiftlint_linux - path: artifacts/usr/bin/swiftlint_linux_* + path: artifacts/linux_*/usr/bin/swiftlint_linux_* if-no-files-found: error retention-days: 2 From 5d674b3a067711622860db2000ab84f93bed3b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 13:40:38 +0200 Subject: [PATCH 17/30] Move artifacts for simpler archive structure --- .github/workflows/docker.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 1d284534b5..d2962e1d0a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -74,11 +74,14 @@ jobs: tags: ghcr.io/${{ env.REPOSITORY_LC }}:test platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} + - name: Move binary artifacts + if: contains(env.OUTPUT_TYPE, 'local') + run: mv artifacts/linux_*/usr/bin/swiftlint_linux_* . - name: Upload binary artifacts if: contains(env.OUTPUT_TYPE, 'local') uses: actions/upload-artifact@v4 with: name: swiftlint_linux - path: artifacts/linux_*/usr/bin/swiftlint_linux_* + path: swiftlint_linux_* if-no-files-found: error retention-days: 2 From 2ff42b8769ca699878c50e8d73c927d41bc5de38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 13:44:46 +0200 Subject: [PATCH 18/30] Remove traces of Swift SDK --- Dockerfile | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 73ecafc81d..2b5a13b395 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,12 +2,10 @@ # Base image and static SDK have to be updated together. ARG SWIFT_VERSION=6.0.3 -ARG SWIFT_SDK_VERSION=0.0.1 -ARG SWIFT_SDK_CHECKSUM=67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd -ARG RUNTIME_IMAGE=ubuntu:noble +ARG UBUNTU_VERSION=noble # Builder image -FROM swift:${SWIFT_VERSION}-noble AS builder +FROM swift:${SWIFT_VERSION}-${UBUNTU_VERSION} AS builder WORKDIR /workspace COPY Plugins Plugins/ COPY Source Source/ @@ -18,7 +16,7 @@ ARG TARGETPLATFORM RUN --mount=type=cache,target=/workspace/.build,id=build-$TARGETPLATFORM ./tools/build-linux-release.sh # Runtime image -FROM ${RUNTIME_IMAGE} AS runtime +FROM ubuntu:${UBUNTU_VERSION} AS runtime LABEL org.opencontainers.image.source=https://github.com/realm/SwiftLint RUN apt-get update RUN apt-get install -y libcurl4-openssl-dev libxml2-dev From 35f8313800a06a690a7d46fefd0845b16c777ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 14:08:08 +0200 Subject: [PATCH 19/30] Run regularly per schedule only --- .github/workflows/docker.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index d2962e1d0a..fcdc08aa67 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,9 +1,8 @@ name: Docker Build on: - push: - branches: - - main + schedule: + - cron: '0 3 * * 3,6' # Every Wednesday and Saturday at 03:00 UTC release: types: published workflow_call: @@ -28,7 +27,7 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Define variables on push to `main` - if: github.event_name == 'push' + if: github.event_name == 'schedule' run: | { echo "CHECKOUT_REF=main" @@ -44,7 +43,7 @@ jobs: echo "OUTPUT_TYPE=type=registry" } >> "$GITHUB_ENV" - name: Define variables on workflow call - if: github.event_name != 'push' && github.event_name != 'release' + if: github.event_name != 'schedule' && github.event_name != 'release' run: | { echo "CHECKOUT_REF=${{ inputs.ref }}" From 2b6e7d54b62c8d84d8965227a883ccbb727e9560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 18:04:11 +0200 Subject: [PATCH 20/30] Build in PR if Docker-related files have changed --- .github/workflows/docker.yml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index fcdc08aa67..e3d571edcc 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -16,6 +16,10 @@ on: required: true type: string pull_request: + paths: + - '.github/workflows/docker.yml' + - 'Dockerfile' + - 'tools/build-linux-release.sh' permissions: contents: read @@ -42,8 +46,16 @@ jobs: echo "DOCKER_TAG=${{ github.event.release.tag_name }}" echo "OUTPUT_TYPE=type=registry" } >> "$GITHUB_ENV" + - name: Define variables on pull request + if: github.event_name == 'pull_request' + run: | + { + echo "CHECKOUT_REF=${{ github.event.pull_request.head.ref }}" + echo "DOCKER_TAG=pr-${{ github.event.pull_request.number }}" + echo "OUTPUT_TYPE=type=local,dest=artifacts" + } >> "$GITHUB_ENV" - name: Define variables on workflow call - if: github.event_name != 'schedule' && github.event_name != 'release' + if: github.event_name != 'schedule' && github.event_name != 'release' && github.event_name != 'pull_request' run: | { echo "CHECKOUT_REF=${{ inputs.ref }}" @@ -70,7 +82,7 @@ jobs: - uses: docker/build-push-action@v6 with: context: . - tags: ghcr.io/${{ env.REPOSITORY_LC }}:test + tags: ghcr.io/${{ env.REPOSITORY_LC }}:${{ env.DOCKER_TAG }} platforms: linux/amd64, linux/arm64 outputs: ${{ env.OUTPUT_TYPE }} - name: Move binary artifacts From e387a81af4e67b22d5482849474f7cf09fc11226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 18:17:19 +0200 Subject: [PATCH 21/30] Use swiftlint_linux_* as Linux binary names --- .github/workflows/release.yml | 2 +- Makefile | 13 +++---------- tools/info.json.template | 2 +- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 06cd5b851a..2ac448da3a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -148,7 +148,7 @@ jobs: - name: Download binary artifact for Linux uses: actions/download-artifact@v4 with: - name: swiftlint_linux_amd64 + name: swiftlint_linux path: ${{ env.LINUX_BUILD_DIR }} - name: Move Bazel release run: mv -f ${{ env.MACOS_BUILD_DIR }}/bazel.tar.gz ${{ env.MACOS_BUILD_DIR }}/bazel.tar.gz.sha256 . diff --git a/Makefile b/Makefile index 6128f12509..03b4b5a0d8 100644 --- a/Makefile +++ b/Makefile @@ -127,24 +127,17 @@ spm_artifactbundle: $(SWIFTLINT_EXECUTABLE) $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) mkdir -p "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-linux-gnu/bin" sed 's/__VERSION__/$(VERSION_STRING)/g' tools/info.json.template > "$(ARTIFACT_BUNDLE_PATH)/info.json" cp -f "$(SWIFTLINT_EXECUTABLE)" "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-macos/bin/swiftlint" - cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-linux-gnu/bin/swiftlint" + cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-linux-gnu/bin/swiftlint_amd64" cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_ARM64)" "$(ARTIFACT_BUNDLE_PATH)/swiftlint-$(VERSION_STRING)-linux-gnu/bin/swiftlint_arm64" cp -f "$(LICENSE_PATH)" "$(ARTIFACT_BUNDLE_PATH)" (cd "$(TEMPORARY_FOLDER)"; zip -yr - "SwiftLintBinary.artifactbundle") > "./SwiftLintBinary.artifactbundle.zip" -zip_linux: docker_image $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) - $(eval TMP_FOLDER := $(shell mktemp -d)) - cp -f $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) "$(TMP_FOLDER)/swiftlint" - cp -f $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) "$(TMP_FOLDER)/swiftlint_arm64" - cp -f "$(LICENSE_PATH)" "$(TMP_FOLDER)" - (cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint_arm64" "LICENSE") > "./swiftlint_linux.zip" - zip_linux_release: $(SWIFTLINT_EXECUTABLE_LINUX_AMD64) $(SWIFTLINT_EXECUTABLE_LINUX_ARM64) $(eval TMP_FOLDER := $(shell mktemp -d)) - cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" "$(TMP_FOLDER)/swiftlint" + cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_AMD64)" "$(TMP_FOLDER)/swiftlint_amd64" cp -f "$(SWIFTLINT_EXECUTABLE_LINUX_ARM64)" "$(TMP_FOLDER)/swiftlint_arm64" cp -f "$(LICENSE_PATH)" "$(TMP_FOLDER)" - (cd "$(TMP_FOLDER)"; zip -yr - "swiftlint" "swiftlint_arm64" "LICENSE") > "./swiftlint_linux.zip" + (cd "$(TMP_FOLDER)"; zip -yr - "swiftlint_amd64" "swiftlint_arm64" "LICENSE") > "./swiftlint_linux.zip" package: $(SWIFTLINT_EXECUTABLE) $(eval PACKAGE_ROOT := $(shell mktemp -d)) diff --git a/tools/info.json.template b/tools/info.json.template index 63b6e2a861..0b0590aca2 100644 --- a/tools/info.json.template +++ b/tools/info.json.template @@ -10,7 +10,7 @@ "supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"] }, { - "path": "swiftlint-__VERSION__-linux-gnu/bin/swiftlint", + "path": "swiftlint-__VERSION__-linux-gnu/bin/swiftlint_amd64", "supportedTriples": ["x86_64-unknown-linux-gnu"] }, { From 16e6089570e694003810ce531049fa9dfe57040c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 18:27:18 +0200 Subject: [PATCH 22/30] Add changelog entry --- CHANGELOG.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e9e44abdd..0518b29892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,12 @@ `redundant_optional_initialization` rule by default. `redundant_optional_initialization` is now an alias for `implicit_optional_initialization`. [leo-lem](https://github.com/leo-lem) - [#1940](https://github.com/realm/SwiftLint/issues/1940) + [#1940](https://github.com/realm/SwiftLint/issues/1940) + +* The `x86_64`/`amd64` binary in the `swiftlint_linux.zip` release archive has been renamed to + `swiftlint_amd64` from just `swiftlint` to avoid confusion with the new `swiftlint_arm64` binary. + [Bradley Mackey](https://github.com/bradleymackey) + [SimplyDanny](https://github.com/SimplyDanny) ### Experimental @@ -30,6 +35,14 @@ ### Enhancements +* Support for ARM64 Linux binaries has been added. The `swiftlint_linux.zip` release archive + now contains both `swiftlint_amd64` and `swiftlint_arm64` binaries. The `swiftlint_amd64` + binary was formerly named `swiftlint`. `SwiftLintBinary.artifactbundle.zip` now also provides + the new binary, making the [binary plugins](https://github.com/SimplyDanny/SwiftLintPlugins) + work on ARM64 Linux as well. + [Bradley Mackey](https://github.com/bradleymackey) + [SimplyDanny](https://github.com/SimplyDanny) + * Add `include_variables` configuration option to `non_optional_string_data_conversion` rule. When enabled, the rule will trigger on variables, properties, and function calls in addition to string literals. Defaults to `false` for backward compatibility. From a01ccaa7acbdafb5e13b44a244fbb58716ba57b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 18:33:02 +0200 Subject: [PATCH 23/30] Avoid explicit PR HEAD ref in workflow --- .github/workflows/docker.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e3d571edcc..9a31beeb39 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -50,7 +50,7 @@ jobs: if: github.event_name == 'pull_request' run: | { - echo "CHECKOUT_REF=${{ github.event.pull_request.head.ref }}" + echo "CHECKOUT_REF=pr" echo "DOCKER_TAG=pr-${{ github.event.pull_request.number }}" echo "OUTPUT_TYPE=type=local,dest=artifacts" } >> "$GITHUB_ENV" @@ -63,6 +63,9 @@ jobs: echo "OUTPUT_TYPE=type=local,dest=artifacts" } >> "$GITHUB_ENV" - uses: actions/checkout@v4 + if: env.CHECKOUT_REF == 'pr' + - uses: actions/checkout@v4 + if: env.CHECKOUT_REF != 'pr' with: ref: ${{ env.CHECKOUT_REF }} - name: Set lowercase repository name From de0702ff3327ccd272cb2a89ed94e3ff4225b098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Fri, 15 Aug 2025 18:42:46 +0200 Subject: [PATCH 24/30] Shorter workflow/job names --- .github/workflows/docker.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 9a31beeb39..ca185d0362 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,4 @@ -name: Docker Build +name: Docker on: schedule: @@ -27,7 +27,7 @@ permissions: jobs: build: - name: Build Docker Image + name: Build Images runs-on: ubuntu-24.04 steps: - name: Define variables on push to `main` From 1409470ad81b304961657044629f3d09851262bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 16 Aug 2025 11:07:09 +0200 Subject: [PATCH 25/30] Try to build on ARM --- .github/workflows/docker.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ca185d0362..816579d3cb 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -28,7 +28,7 @@ permissions: jobs: build: name: Build Images - runs-on: ubuntu-24.04 + runs-on: ubuntu-24.04-arm steps: - name: Define variables on push to `main` if: github.event_name == 'schedule' @@ -72,10 +72,12 @@ jobs: run: echo "REPOSITORY_LC=${REPOSITORY,,}" >> "$GITHUB_ENV" env: REPOSITORY: ${{ github.repository }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: amd64 - 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: Login to GitHub registry uses: docker/login-action@v3 with: From 273b499167710fae83e7458ee9ec34a44c1a23bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 16 Aug 2025 11:11:18 +0200 Subject: [PATCH 26/30] Use PRs checkout ref --- .github/workflows/docker.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 816579d3cb..feda823cb4 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -16,7 +16,7 @@ on: required: true type: string pull_request: - paths: + paths: - '.github/workflows/docker.yml' - 'Dockerfile' - 'tools/build-linux-release.sh' @@ -50,7 +50,7 @@ jobs: if: github.event_name == 'pull_request' run: | { - echo "CHECKOUT_REF=pr" + echo "CHECKOUT_REF=pull/${{ github.event.pull_request.number }}/merge" echo "DOCKER_TAG=pr-${{ github.event.pull_request.number }}" echo "OUTPUT_TYPE=type=local,dest=artifacts" } >> "$GITHUB_ENV" @@ -63,9 +63,6 @@ jobs: echo "OUTPUT_TYPE=type=local,dest=artifacts" } >> "$GITHUB_ENV" - uses: actions/checkout@v4 - if: env.CHECKOUT_REF == 'pr' - - uses: actions/checkout@v4 - if: env.CHECKOUT_REF != 'pr' with: ref: ${{ env.CHECKOUT_REF }} - name: Set lowercase repository name From 5b102f335fb608f022cd65ca2b8a1c2f81ebf0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 16 Aug 2025 15:00:30 +0200 Subject: [PATCH 27/30] Reduce scheduled build and trigger on push --- .github/workflows/docker.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index feda823cb4..43b2f40705 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -2,7 +2,14 @@ name: Docker on: schedule: - - cron: '0 3 * * 3,6' # Every Wednesday and Saturday at 03:00 UTC + - cron: '0 3 * * 3' # Every Wednesday at 03:00 UTC + push: + branches: + - main + paths: + - '.github/workflows/docker.yml' + - 'Dockerfile' + - 'tools/build-linux-release.sh' release: types: published workflow_call: @@ -31,7 +38,7 @@ jobs: runs-on: ubuntu-24.04-arm steps: - name: Define variables on push to `main` - if: github.event_name == 'schedule' + if: github.event_name == 'schedule' || github.event_name == 'push' run: | { echo "CHECKOUT_REF=main" From 2669ac692e63a0684757dca0bf950e94fa7fa958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 16 Aug 2025 15:09:47 +0200 Subject: [PATCH 28/30] Simplify condition --- .github/workflows/docker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 43b2f40705..949987b5f1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -62,7 +62,7 @@ jobs: echo "OUTPUT_TYPE=type=local,dest=artifacts" } >> "$GITHUB_ENV" - name: Define variables on workflow call - if: github.event_name != 'schedule' && github.event_name != 'release' && github.event_name != 'pull_request' + if: env.DOCKER_TAG == null run: | { echo "CHECKOUT_REF=${{ inputs.ref }}" From d63859a1dea09428899b53d7f7a2f21192f34999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 16 Aug 2025 15:14:29 +0200 Subject: [PATCH 29/30] Make both binaries executable --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ac448da3a..d586033788 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -153,7 +153,7 @@ jobs: - name: Move Bazel release run: mv -f ${{ env.MACOS_BUILD_DIR }}/bazel.tar.gz ${{ env.MACOS_BUILD_DIR }}/bazel.tar.gz.sha256 . - name: Make binaries executable - run: chmod +x ${{ env.MACOS_BUILD_DIR }}/swiftlint ${{ env.LINUX_BUILD_DIR }}/swiftlint_linux_amd64 + run: chmod +x ${{ env.MACOS_BUILD_DIR }}/swiftlint ${{ env.LINUX_BUILD_DIR }}/swiftlint_linux_* - name: Create artifacts run: | make --debug spm_artifactbundle From 89032dd7aa1c6d02c35f9b0aad30d565a06de598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danny=20M=C3=B6sch?= Date: Sat, 16 Aug 2025 15:20:03 +0200 Subject: [PATCH 30/30] Revert "Use PRs checkout ref" This reverts commit 273b499167710fae83e7458ee9ec34a44c1a23bf. --- .github/workflows/docker.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 949987b5f1..e817b30398 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -57,7 +57,7 @@ jobs: if: github.event_name == 'pull_request' run: | { - echo "CHECKOUT_REF=pull/${{ github.event.pull_request.number }}/merge" + echo "CHECKOUT_REF=pr" echo "DOCKER_TAG=pr-${{ github.event.pull_request.number }}" echo "OUTPUT_TYPE=type=local,dest=artifacts" } >> "$GITHUB_ENV" @@ -70,6 +70,9 @@ jobs: echo "OUTPUT_TYPE=type=local,dest=artifacts" } >> "$GITHUB_ENV" - uses: actions/checkout@v4 + if: env.CHECKOUT_REF == 'pr' + - uses: actions/checkout@v4 + if: env.CHECKOUT_REF != 'pr' with: ref: ${{ env.CHECKOUT_REF }} - name: Set lowercase repository name