From 6f9a0fb3cc0cb1fccba67eb8cf70e1e342788fb2 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Tue, 9 Jul 2024 12:07:16 +0900 Subject: [PATCH] Change to running swiftlint in docker build --- .../action.yml | 2 +- .../action.yml | 1 + .github/workflows/docker-image-ci.yml | 140 ++++++++++-------- Dockerfile | 17 +-- Package.resolved | 15 -- Package.swift | 24 --- Sources/main.swift | 25 ---- 7 files changed, 89 insertions(+), 135 deletions(-) delete mode 100644 Package.resolved delete mode 100644 Package.swift delete mode 100644 Sources/main.swift diff --git a/.github/actions/configure-docker-containerd-image-store/action.yml b/.github/actions/configure-docker-containerd-image-store/action.yml index d6a16d1..0fa0922 100644 --- a/.github/actions/configure-docker-containerd-image-store/action.yml +++ b/.github/actions/configure-docker-containerd-image-store/action.yml @@ -4,7 +4,7 @@ inputs: USE_CONTAINERD: description: use containerd as docker image store required: false - default: 'false' + default: 'true' runs: using: "composite" steps: diff --git a/.github/actions/install_qemu_user_static_from_debian/action.yml b/.github/actions/install_qemu_user_static_from_debian/action.yml index 9e50a92..9357b62 100644 --- a/.github/actions/install_qemu_user_static_from_debian/action.yml +++ b/.github/actions/install_qemu_user_static_from_debian/action.yml @@ -41,4 +41,5 @@ runs: TARGET_FLAG=${TARGET_RELEASE:+-t $TARGET_RELEASE} VERSION_REQUIREMENT=${VERSION:+=$VERSION} sudo apt-get update && sudo apt-get $TARGET_FLAG install -y qemu-user-static$VERSION_REQUIREMENT + sudo systemctl restart systemd-binfmt shell: bash diff --git a/.github/workflows/docker-image-ci.yml b/.github/workflows/docker-image-ci.yml index 9122b8a..ef88e41 100644 --- a/.github/workflows/docker-image-ci.yml +++ b/.github/workflows/docker-image-ci.yml @@ -8,48 +8,59 @@ on: - '.github/actions/*/action.yml' - '.github/workflows/docker-image-ci.yml' - 'Dockerfile' - - '**.swift' pull_request: paths: - '.github/actions/*/action.yml' - '.github/workflows/docker-image-ci.yml' - - '**.swift' + +defaults: + run: + shell: bash + +env: + NUMBER_OF_TRIES: 5 jobs: - use-qemu-user-static: - runs-on: ubuntu-${{ matrix.ubuntu_version }} + qemu-user-static-ubuntu: + name: qemu-user-static (ubuntu-${{ matrix.version }}) + runs-on: ubuntu-${{ matrix.version }} strategy: fail-fast: false matrix: - ubuntu_version: + version: - '20.04' - '22.04' # latest - - '24.04' - + - '24.04' steps: - uses: actions/checkout@v4 + + - name: install qemu-user-static + run: | + sudo apt-get update + sudo apt-get install -y qemu-user-static - - run: sudo apt-get update && sudo apt-get install -y qemu-user-static + - name: print qemu-user-static version + run: | + echo "::notice title=${{ github.job }}:${{ matrix.version }}::qemu-user-static:$(dpkg-query --show --showformat='${Version}' qemu-user-static)" - uses: ./.github/actions/configure-docker-containerd-image-store - with: - USE_CONTAINERD: true - - - name: build arm64 architecture - uses: docker/build-push-action@v5 - with: - load: true - platforms: linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max - use-qemu-user-static-from_debian: - name: qemu-user-static from debian ${{ matrix.target_release }} + - name: try to build docker image + run: | + docker pull --platform linux/arm64 norionomura/swiftlint:experimental-multi-arch + for i in $(seq 1 ${{ env.NUMBER_OF_TRIES }}); do + timeout --preserve-status --kill-after=60 240 docker buildx build --load --no-cache --platform linux/arm64 . && continue + echo "::error title=${{ github.job }} failed::on iteration:$i" + exit 1 + done + + qemu-user-static-debian: + name: qemu-user-static (debian ${{ matrix.version }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - target_release: + version: - 'buster' # 1:3.1+dfsg-8+deb10u12 - 'bullseye' # 1:5.2+dfsg-11+deb11u3 - 'bullseye-backports' # 1:7.2+dfsg-7+deb12u2~bpo11+1 @@ -57,33 +68,36 @@ jobs: - 'bookworm-backports' # 1:8.2.1+ds-1~bpo12+1 - 'trixie' # 1:8.2.4+ds-1 - 'sid' # 1:9.0.1+ds-1 - steps: - uses: actions/checkout@v4 - - uses: ./.github/actions/install_qemu_user_static_from_debian + - name: install qemu-user-static from debian + uses: ./.github/actions/install_qemu_user_static_from_debian with: - TARGET_RELEASE: ${{ matrix.target_release }} + TARGET_RELEASE: ${{ matrix.version }} + + - name: print qemu-user-static version + run: | + echo "::notice title=${{ github.job }}:${{ matrix.version }}::qemu-user-static:$(dpkg-query --show --showformat='${Version}' qemu-user-static)" - uses: ./.github/actions/configure-docker-containerd-image-store - with: - USE_CONTAINERD: true - - name: build arm64 architecture - uses: docker/build-push-action@v5 - with: - load: true - platforms: linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max + - name: try to build docker image + run: | + docker pull --platform linux/arm64 norionomura/swiftlint:experimental-multi-arch + for i in $(seq 1 ${{ env.NUMBER_OF_TRIES }}); do + timeout --preserve-status --kill-after=60 240 docker buildx build --load --no-cache --platform linux/arm64 . && continue + echo "::error title=${{ github.job }} failed::on iteration:$i" + exit 1 + done use-tonistiigi_binfmt: - name: tonistiigi/binfmt:${{ matrix.tag }} + name: tonistiigi/binfmt:${{ matrix.version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: - tag: + version: - latest - qemu-v5.0.1 - qemu-v5.1.0 @@ -95,34 +109,37 @@ jobs: - qemu-v8.0.4 - qemu-v8.1.4 - qemu-v8.1.5 - steps: - uses: actions/checkout@v4 - - uses: docker/setup-qemu-action@v3 + - name: install qemu-user-static + uses: docker/setup-qemu-action@v3 with: - image: tonistiigi/binfmt:${{ matrix.tag }} + image: tonistiigi/binfmt:${{ matrix.version }} platforms: linux/arm64 + - name: print qemu-user-static version + run: | + echo "::notice title=${{ github.job }}:${{ matrix.version }}::qemu-user-static:${{ matrix.version }}" + - uses: ./.github/actions/configure-docker-containerd-image-store - with: - USE_CONTAINERD: true - - name: build arm64 architecture - uses: docker/build-push-action@v5 - with: - load: true - platforms: linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max + - name: try to build docker image + run: | + docker pull --platform linux/arm64 norionomura/swiftlint:experimental-multi-arch + for i in $(seq 1 ${{ env.NUMBER_OF_TRIES }}); do + timeout --preserve-status --kill-after=60 240 docker buildx build --load --no-cache --platform linux/arm64 . && continue + echo "::error title=${{ github.job }} failed::on iteration:$i" + exit 1 + done use-multiarch_qemu-user-static: - name: multiarch/qemu-user-static:${{ matrix.tag }} + name: multiarch/qemu-user-static:${{ matrix.version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: - tag: + version: - latest - 3.1.1-2 - 4.0.0-5 @@ -135,20 +152,23 @@ jobs: - 7.0.0-7 - 7.1.0-2 - 7.2.0-1 # latest - steps: - uses: actions/checkout@v4 - - run: docker run --rm --privileged multiarch/qemu-user-static:${{ matrix.tag }} --reset -p yes + - name: install qemu-user-static + run: docker run --rm --privileged multiarch/qemu-user-static:${{ matrix.version }} --reset -p yes + - name: print qemu-user-static version + run: | + echo "::notice title=${{ github.job }}:${{ matrix.version }}::qemu-user-static:${{ matrix.version }}" + - uses: ./.github/actions/configure-docker-containerd-image-store - with: - USE_CONTAINERD: true - - name: build arm64 architecture - uses: docker/build-push-action@v5 - with: - load: true - platforms: linux/arm64 - cache-from: type=gha - cache-to: type=gha,mode=max + - name: try to build docker image + run: | + docker pull --platform linux/arm64 norionomura/swiftlint:experimental-multi-arch + for i in $(seq 1 ${{ env.NUMBER_OF_TRIES }}); do + timeout --preserve-status --kill-after=60 240 docker buildx build --load --no-cache --platform linux/arm64 . && continue + echo "::error title=${{ github.job }} failed::on iteration:$i" + exit 1 + done diff --git a/Dockerfile b/Dockerfile index 42f2823..111834d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,9 @@ # syntax=docker/dockerfile:1 -FROM swift:5.10 -WORKDIR /app -COPY Sources /app/Sources -COPY Package.* /app -ARG TARGETPLATFORM -RUN --mount=type=cache,target=/app/.build,sharing=locked,id=${TARGETPLATFORM} \ - swift build -c release --product hello-world && \ - install $(swift build -c release --show-bin-path)/hello-world /usr/local/bin -RUN hello-world -CMD ["hello-world"] +FROM norionomura/swiftlint:experimental-multi-arch +# remove stub script +RUN test ! -x /usr/local/bin/swiftlint || rm /usr/local/bin/swiftlint + +SHELL ["/bin/bash", "-eux", "-o", "pipefail", "-c"] +RUN ["timeout", "--preserve-status", "--kill-after=60", "120", "swiftlint", "version"] +RUN echo "_ = 0" | timeout --preserve-status --kill-after=60 120 swiftlint --use-stdin diff --git a/Package.resolved b/Package.resolved deleted file mode 100644 index 7734e99..0000000 --- a/Package.resolved +++ /dev/null @@ -1,15 +0,0 @@ -{ - "originHash" : "b9c47443daa3387adc9a9861ff912dd4f4dd9e850890e71c076288cde75316e7", - "pins" : [ - { - "identity" : "swift-argument-parser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser.git", - "state" : { - "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", - "version" : "1.4.0" - } - } - ], - "version" : 3 -} diff --git a/Package.swift b/Package.swift deleted file mode 100644 index 56ee812..0000000 --- a/Package.swift +++ /dev/null @@ -1,24 +0,0 @@ -// swift-tools-version: 5.10 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -let package = Package( - name: "hello-world", - products: [ - .executable(name: "hello-world", targets: ["hello-world"]), - ], - dependencies: [ - .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.2.1"), - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .executableTarget( - name: "hello-world", - dependencies: [ - .product(name: "ArgumentParser", package: "swift-argument-parser"), - ] - ), - ] -) diff --git a/Sources/main.swift b/Sources/main.swift deleted file mode 100644 index 2a9c965..0000000 --- a/Sources/main.swift +++ /dev/null @@ -1,25 +0,0 @@ -import ArgumentParser - -@main -struct Main: ParsableCommand { - static var configuration = CommandConfiguration( - commandName: "hello-world", - abstract: "A 'Hello, world!' program written in Swift.", - version: "1.0.0", - subcommands: [SayHello.self], - defaultSubcommand: SayHello.self - ) -} - -extension Main { - struct SayHello: ParsableCommand { - static var configuration = CommandConfiguration( - commandName: "say-hello", - abstract: "Prints 'Hello, world!' to the console." - ) - - func run() { - print("Hello, world!") - } - } -}