From a01dedefc1ed001b28109f94c30981d8dd4888fc Mon Sep 17 00:00:00 2001 From: Konrad `ktoso` Malawski Date: Tue, 12 Nov 2024 11:56:30 +0900 Subject: [PATCH] ci: reorganize jobs --- .github/actions/prepare_env/action.yml | 44 ++++++++++ .github/workflows/pull_request.yml | 107 ++++--------------------- Sources/JExtractSwift/Swift2Java.swift | 2 +- 3 files changed, 61 insertions(+), 92 deletions(-) create mode 100644 .github/actions/prepare_env/action.yml diff --git a/.github/actions/prepare_env/action.yml b/.github/actions/prepare_env/action.yml new file mode 100644 index 00000000..ebcc8aed --- /dev/null +++ b/.github/actions/prepare_env/action.yml @@ -0,0 +1,44 @@ +name: 'Swift Java CI Env' +description: 'Prepare the CI environment by installing Swift and selected JDK etc.' + +runs: + using: composite + steps: + - name: Install System Dependencies + run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev + shell: bash + - name: Cache JDK + id: cache-jdk + uses: actions/cache@v4 + continue-on-error: true + with: + path: /usr/lib/jvm/default-jdk/ + key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }} + restore-keys: | + ${{ runner.os }}-jdk- + - name: Install JDK + if: steps.cache-jdk.outputs.cache-hit != 'true' + run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'" + shell: bash + # TODO: not using setup-java since incompatible with the swiftlang/swift base image + # - name: Install Untested Nightly Swift + # run: "bash -xc './docker/install_untested_nightly_swift.sh'" + - name: Cache local Gradle repository + uses: actions/cache@v4 + continue-on-error: true + with: + path: | + /root/.gradle/caches + /root/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }} + restore-keys: | + ${{ runner.os }}-gradle- + - name: Cache local SwiftPM repository + uses: actions/cache@v4 + continue-on-error: true + with: + path: /__w/swift-java/swift-java/.build/checkouts + key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }} + restore-keys: | + ${{ runner.os }}-swiftpm-cache + ${{ runner.os }}-swiftpm- diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6a095aa6..35c9509a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -20,6 +20,7 @@ jobs: strategy: fail-fast: true matrix: + # swift_version: ['nightly-main'] swift_version: ['6.0.2'] os_version: ['jammy'] jdk_vendor: ['Corretto'] @@ -29,50 +30,14 @@ jobs: JAVA_HOME: "/usr/lib/jvm/default-jdk" steps: - uses: actions/checkout@v4 - - name: Install System Dependencies - run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev - - name: Cache JDK - id: cache-jdk - uses: actions/cache@v4 - continue-on-error: true - with: - path: /usr/lib/jvm/default-jdk/ - key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }} - restore-keys: | - ${{ runner.os }}-jdk- - - name: Install JDK - if: steps.cache-jdk.outputs.cache-hit != 'true' - run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'" - # TODO: not using setup-java since incompatible with the swiftlang/swift base image - # - name: Install Untested Nightly Swift - # run: "bash -xc './docker/install_untested_nightly_swift.sh'" - - name: Cache local Gradle repository - uses: actions/cache@v4 - continue-on-error: true - with: - path: | - /root/.gradle/caches - /root/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }} - restore-keys: | - ${{ runner.os }}-gradle- - - name: Cache local SwiftPM repository - uses: actions/cache@v4 - continue-on-error: true - with: - path: /__w/swift-java/swift-java/.build/checkouts - key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }} - restore-keys: | - ${{ runner.os }}-swiftpm-cache - ${{ runner.os }}-swiftpm- - # run the actual build + - name: Prepare CI Environment + uses: ./.github/actions/prepare_env - name: Gradle build - run: | - ./gradlew build -x test --no-daemon # just build - ./gradlew build --info --no-daemon - - name: Gradle build (benchmarks) - run: | - ./gradlew compileJmh --info --no-daemon + run: ./gradlew build -x test # just build + - name: Gradle check + run: ./gradlew check --info + - name: Gradle compile benchmarks + run: ./gradlew compileJmh --info test-swift: name: Swift tests (swift:${{ matrix.swift_version }} jdk:${{matrix.jdk_vendor}} os:${{ matrix.os_version }}) @@ -90,40 +55,11 @@ jobs: JAVA_HOME: "/usr/lib/jvm/default-jdk" steps: - uses: actions/checkout@v4 - - name: Install System Dependencies - run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev - - name: Cache JDK - id: cache-jdk - uses: actions/cache@v4 - continue-on-error: true - with: - path: /usr/lib/jvm/default-jdk/ - key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }} - restore-keys: | - ${{ runner.os }}-jdk- - - name: Install JDK - if: steps.cache-jdk.outputs.cache-hit != 'true' - run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'" - - name: Cache local Gradle repository - uses: actions/cache@v4 - continue-on-error: true - with: - path: | - /root/.gradle/caches - /root/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('*/*.gradle*', 'settings.gradle') }} - restore-keys: | - ${{ runner.os }}-gradle- - - name: Cache local SwiftPM repository - uses: actions/cache@v4 - continue-on-error: true - with: - path: /__w/swift-java/swift-java/.build/checkouts - key: ${{ runner.os }}-swiftpm-cache-${{ hashFiles('Package.swift') }} - restore-keys: | - ${{ runner.os }}-swiftpm-cache - ${{ runner.os }}-swiftpm- - - name: Test Swift + - name: Prepare CI Environment + uses: ./.github/actions/prepare_env + - name: Swift Build + run: "swift build --build-tests" + - name: Swift Test run: "swift test" verify-samples: @@ -132,6 +68,7 @@ jobs: strategy: fail-fast: false matrix: + # swift_version: ['nightly-main'] swift_version: ['6.0.2'] os_version: ['jammy'] jdk_vendor: ['Corretto'] @@ -141,20 +78,8 @@ jobs: JAVA_HOME: "/usr/lib/jvm/default-jdk" steps: - uses: actions/checkout@v4 - - name: Install System Dependencies - run: apt-get -qq update && apt-get -qq install -y make curl wget libjemalloc2 libjemalloc-dev - - name: Cache JDK - id: cache-jdk - uses: actions/cache@v4 - continue-on-error: true - with: - path: /usr/lib/jvm/default-jdk/ - key: ${{ runner.os }}-jdk-${{ matrix.jdk_vendor }}-${{ hashFiles('/usr/lib/jvm/default-jdk/*') }} - restore-keys: | - ${{ runner.os }}-jdk- - - name: Install JDK - if: steps.cache-jdk.outputs.cache-hit != 'true' - run: "bash -xc 'JDK_VENDOR=${{ matrix.jdk_vendor }} ./docker/install_jdk.sh'" + - name: Prepare CI Environment + uses: ./.github/actions/prepare_env - name: Verify Samples (All) run: .github/scripts/validate_samples.sh # TODO: Benchmark compile crashes in CI, enable when nightly toolchains in better shape. diff --git a/Sources/JExtractSwift/Swift2Java.swift b/Sources/JExtractSwift/Swift2Java.swift index 315633b8..2167c391 100644 --- a/Sources/JExtractSwift/Swift2Java.swift +++ b/Sources/JExtractSwift/Swift2Java.swift @@ -107,6 +107,6 @@ extension Logger.Level: ExpressibleByArgument { func isDirectory(url: URL) -> Bool { var isDirectory: ObjCBool = false - FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory) + _ = FileManager.default.fileExists(atPath: url.path, isDirectory: &isDirectory) return isDirectory.boolValue }