From 092f2e456ceb888909f6c18fbe30363816ddf3a7 Mon Sep 17 00:00:00 2001 From: Diogo Mendes Matsubara Date: Tue, 14 Jan 2025 18:42:59 +0100 Subject: [PATCH] feat: rework release workflow - split jvm build from publication - split github/maven into their own jobs - make github publication depend on maven one --- .github/workflows/build-jvm.yml | 128 ++++++++++++++++++++++++++ .github/workflows/publish-android.yml | 2 + .github/workflows/publish-jvm.yml | 114 ----------------------- .github/workflows/release.yml | 51 +++++++++- 4 files changed, 177 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/build-jvm.yml diff --git a/.github/workflows/build-jvm.yml b/.github/workflows/build-jvm.yml new file mode 100644 index 000000000..ad147cdea --- /dev/null +++ b/.github/workflows/build-jvm.yml @@ -0,0 +1,128 @@ +name: Build (JVM) + +on: + workflow_call: + inputs: + branch: + description: Target branch + type: string + required: false + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + JNI_LIB_PATHS: jni-libs # Edit on the inner build.gradle.kts file as well. + +jobs: + builds: + name: Build for ${{ matrix.job.target }} on ${{ matrix.job.os }} + if: ${{ !(github.event.inputs.build == 'false') }} + runs-on: ${{ matrix.job.os }} + strategy: + fail-fast: false + matrix: + job: + # In order to load any added target at runtime, editing the Zenoh class under jvmMain is required. + - { + target: x86_64-unknown-linux-gnu, + arch: amd64, + os: ubuntu-20.04, + build-cmd: "cargo", + } + - { + target: aarch64-unknown-linux-gnu, + arch: arm64, + os: ubuntu-20.04, + build-cmd: "cross", + } + - { + target: x86_64-apple-darwin, + arch: darwin, + os: macos-latest, + build-cmd: "cargo", + } + - { + target: aarch64-apple-darwin, + arch: darwin, + os: macos-latest, + build-cmd: "cargo", + } + - { + target: x86_64-pc-windows-msvc, + arch: win64, + os: windows-2019, + build-cmd: "cargo", + } + - { + target: aarch64-pc-windows-msvc, + arch: arm64, + os: windows-2019, + build-cmd: "cargo", + } + steps: + - name: Checkout source code + uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} + + - name: Install prerequisites + shell: bash + run: | + case ${{ matrix.job.target }} in + *-linux-gnu*) cargo +stable install cargo-deb --locked ;; + esac + + case ${{ matrix.job.target }} in + aarch64-unknown-linux-gnu) + sudo apt-get -y update + sudo apt-get -y install gcc-aarch64-linux-gnu + ;; + esac + + cargo +stable install cross --locked + + - name: Install Rust toolchain + run: | + rustup show + rustup target add ${{ matrix.job.target }} + + - name: Build + run: ${{ matrix.job.build-cmd }} build --release --bins --lib --features=${{ github.event.inputs.features}} --target=${{ matrix.job.target }} --manifest-path zenoh-jni/Cargo.toml + + - name: Packaging + id: package + shell: bash + run: | + TARGET=${{ matrix.job.target }} + MAIN_PKG_NAME="${GITHUB_WORKSPACE}/${TARGET}.zip" + + case ${TARGET} in + *linux*) + cd "zenoh-jni/target/${TARGET}/release/" + echo "Packaging ${MAIN_PKG_NAME}:" + zip ${MAIN_PKG_NAME} libzenoh_jni.so + cd - + echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT + ;; + *apple*) + cd "zenoh-jni/target/${TARGET}/release/" + echo "Packaging ${MAIN_PKG_NAME}:" + zip ${MAIN_PKG_NAME} libzenoh_jni.dylib + cd - + echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT + ;; + *windows*) + cd "zenoh-jni/target/${TARGET}/release/" + echo "Packaging ${MAIN_PKG_NAME}:" + 7z -y a "${MAIN_PKG_NAME}" zenoh_jni.dll + cd - + echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT + ;; + esac + + - name: "Upload packages" + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.job.target }} + path: | + ${{ steps.package.outputs.MAIN_PKG_NAME }} \ No newline at end of file diff --git a/.github/workflows/publish-android.yml b/.github/workflows/publish-android.yml index 3581315bc..eba0434c1 100644 --- a/.github/workflows/publish-android.yml +++ b/.github/workflows/publish-android.yml @@ -24,9 +24,11 @@ on: inputs: github_publish: description: 'Publish to github packages' + type: boolean default: true maven_publish: description: 'Publish to Maven Central' + type: boolean default: true env: diff --git a/.github/workflows/publish-jvm.yml b/.github/workflows/publish-jvm.yml index ba12de12b..ed20f297b 100644 --- a/.github/workflows/publish-jvm.yml +++ b/.github/workflows/publish-jvm.yml @@ -34,122 +34,8 @@ env: JNI_LIB_PATHS: jni-libs # Edit on the inner build.gradle.kts file as well. jobs: - builds: - name: Build for ${{ matrix.job.target }} on ${{ matrix.job.os }} - if: ${{ !(github.event.inputs.build == 'false') }} - runs-on: ${{ matrix.job.os }} - strategy: - fail-fast: false - matrix: - job: - # In order to load any added target at runtime, editing the Zenoh class under jvmMain is required. - - { - target: x86_64-unknown-linux-gnu, - arch: amd64, - os: ubuntu-20.04, - build-cmd: "cargo", - } - - { - target: aarch64-unknown-linux-gnu, - arch: arm64, - os: ubuntu-20.04, - build-cmd: "cross", - } - - { - target: x86_64-apple-darwin, - arch: darwin, - os: macos-latest, - build-cmd: "cargo", - } - - { - target: aarch64-apple-darwin, - arch: darwin, - os: macos-latest, - build-cmd: "cargo", - } - - { - target: x86_64-pc-windows-msvc, - arch: win64, - os: windows-2019, - build-cmd: "cargo", - } - - { - target: aarch64-pc-windows-msvc, - arch: arm64, - os: windows-2019, - build-cmd: "cargo", - } - steps: - - name: Checkout source code - uses: actions/checkout@v4 - with: - ref: ${{ inputs.branch }} - - - name: Install prerequisites - shell: bash - run: | - case ${{ matrix.job.target }} in - *-linux-gnu*) cargo +stable install cargo-deb --locked ;; - esac - - case ${{ matrix.job.target }} in - aarch64-unknown-linux-gnu) - sudo apt-get -y update - sudo apt-get -y install gcc-aarch64-linux-gnu - ;; - esac - - cargo +stable install cross --locked - - - name: Install Rust toolchain - run: | - rustup show - rustup target add ${{ matrix.job.target }} - - - name: Build - run: ${{ matrix.job.build-cmd }} build --release --bins --lib --features=${{ github.event.inputs.features}} --target=${{ matrix.job.target }} --manifest-path zenoh-jni/Cargo.toml - - - name: Packaging - id: package - shell: bash - run: | - TARGET=${{ matrix.job.target }} - MAIN_PKG_NAME="${GITHUB_WORKSPACE}/${TARGET}.zip" - - case ${TARGET} in - *linux*) - cd "zenoh-jni/target/${TARGET}/release/" - echo "Packaging ${MAIN_PKG_NAME}:" - zip ${MAIN_PKG_NAME} libzenoh_jni.so - cd - - echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT - ;; - *apple*) - cd "zenoh-jni/target/${TARGET}/release/" - echo "Packaging ${MAIN_PKG_NAME}:" - zip ${MAIN_PKG_NAME} libzenoh_jni.dylib - cd - - echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT - ;; - *windows*) - cd "zenoh-jni/target/${TARGET}/release/" - echo "Packaging ${MAIN_PKG_NAME}:" - 7z -y a "${MAIN_PKG_NAME}" zenoh_jni.dll - cd - - echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT - ;; - esac - - - name: "Upload packages" - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.job.target }} - path: | - ${{ steps.package.outputs.MAIN_PKG_NAME }} - publish_jvm_package: name: Publish JVM package - needs: builds permissions: contents: read packages: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bca02dc5a..d085b34ab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -68,25 +68,68 @@ jobs: GIT_USER_NAME: eclipse-zenoh-bot GIT_USER_EMAIL: eclipse-zenoh-bot@users.noreply.github.com - publish-jvm: - name: Publish JVM package + build-jvm: + name: Build JVM package needs: tag + uses: ./.github/workflows/build-jvm.yml + with: + branch: ${{ needs.tag.outputs.branch }} + permissions: + contents: read + packages: write + secrets: inherit + + publish-jvm-maven: + name: Publish JVM package + needs: [tag, build-jvm] + uses: ./.github/workflows/publish-jvm.yml + with: + snapshot: ${{ !(inputs.live-run || false) }} + branch: ${{ needs.tag.outputs.branch }} + maven_publish: true + github_publish: false + permissions: + contents: read + packages: write + secrets: inherit + + publish-jvm-github: + name: Publish JVM package + needs: [tag, build-jvm, publish-jvm-maven] uses: ./.github/workflows/publish-jvm.yml with: snapshot: ${{ !(inputs.live-run || false) }} branch: ${{ needs.tag.outputs.branch }} + maven_publish: false + github_publish: true permissions: contents: read packages: write secrets: inherit - publish-android: + publish-android-maven: name: Publish Android package needs: tag uses: ./.github/workflows/publish-android.yml with: snapshot: ${{ !(inputs.live-run || false) }} branch: ${{ needs.tag.outputs.branch }} + maven_publish: true + github_publish: false + permissions: + contents: read + packages: write + secrets: inherit + + publish-android-github: + name: Publish Android package + needs: [tag, publish-android-maven] + uses: ./.github/workflows/publish-android.yml + with: + snapshot: ${{ !(inputs.live-run || false) }} + branch: ${{ needs.tag.outputs.branch }} + maven_publish: false + github_publish: true permissions: contents: read packages: write @@ -101,7 +144,7 @@ jobs: branch: ${{ needs.tag.outputs.branch }} publish-github: - needs: tag + needs: [tag, publish-android-github, publish-jvm-github] runs-on: macos-latest steps: - uses: eclipse-zenoh/ci/publish-crates-github@main