From 1238f92aabf342ae6db7076d1052a7388f4d1591 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Wed, 17 Apr 2024 16:47:10 +0200 Subject: [PATCH] feat: Automate Release (#71) * feat: Store project version in version.txt * fix: Remove cargo-deb metadata section in `zenoh-jni` * feat: Add `bump-and-tag.bash` script * chore: Rename release workflow to pre-release * chore: Disable release event on publish workflows * fix: Typo in ci/scripts * feat: Automate Release * chore: Remove enforce-linking-issues workflow * fix: Set permissions for publishing jobs * feat: Add publish-dokka to release workflow * fix: Set release branch in publishing jobs * fix: Make `branch` input unrequired in publishing jobs * style: Uniformize publishing workflow names * fix: Unecessary use of `BOT_TOKEN_WORKFLOW` * fix: Incorrect Cargo manifest/lockfile path * fix: Add missing `live-run` input for publish-dokka job * fix: Typo in pre-release workflow name * fix: Remove `if: always()` in publish-github job * fix: Remove unecessary SSH passphrase/privatekey inputs * chore: Retrigger CI * fix: Support jq 1.6 ubuntu-22.04 runners use jq 1.6 which doesn't recognize a dot for `[]` value iterator. See: jqlang/jq#1168. --- .github/workflows/ci.yml | 4 +- .github/workflows/enforce-linking-issues.yml | 10 -- .github/workflows/pre-release.yml | 60 ++++++++ ...ublish_android.yml => publish-android.yml} | 12 +- .../{documentation.yml => publish-dokka.yml} | 17 ++- .../{publish_jvm.yml => publish-jvm.yml} | 20 ++- .github/workflows/release.yml | 132 ++++++++++++------ build.gradle.kts | 2 +- ci/scripts/bump-and-tag.bash | 66 +++++++++ version.txt | 1 + zenoh-jni/Cargo.toml | 5 - 11 files changed, 251 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/enforce-linking-issues.yml create mode 100644 .github/workflows/pre-release.yml rename .github/workflows/{publish_android.yml => publish-android.yml} (89%) rename .github/workflows/{documentation.yml => publish-dokka.yml} (64%) rename .github/workflows/{publish_jvm.yml => publish-jvm.yml} (93%) create mode 100644 ci/scripts/bump-and-tag.bash create mode 100644 version.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b69d24443..c5fc3e6ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,7 +85,7 @@ jobs: name: Publish JVM snapshot package if: github.ref == 'refs/heads/main' needs: ci - uses: ./.github/workflows/publish_jvm.yml + uses: ./.github/workflows/publish-jvm.yml permissions: contents: read packages: write @@ -96,7 +96,7 @@ jobs: name: Publish Android snapshot package if: github.ref == 'refs/heads/main' needs: ci - uses: ./.github/workflows/publish_android.yml + uses: ./.github/workflows/publish-android.yml permissions: contents: read packages: write diff --git a/.github/workflows/enforce-linking-issues.yml b/.github/workflows/enforce-linking-issues.yml deleted file mode 100644 index ebeddd9ee..000000000 --- a/.github/workflows/enforce-linking-issues.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Enforce linking issues - -on: - pull_request_target: - types: [opened, edited, labeled] - -jobs: - main: - uses: eclipse-zenoh/zenoh/.github/workflows/enforce-linking-issues.yml@main - secrets: inherit diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 000000000..0c5b652ef --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,60 @@ +name: Pre-Release + +on: + schedule: + - cron: "0 1 * * 1-5" + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + release: + name: Build on ${{ matrix.os }} + runs-on: ["${{ matrix.os }}"] + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macOS-latest] + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + + - uses: nttld/setup-ndk@v1 + id: setup-ndk + with: + ndk-version: r26 + add-to-path: false + link-to-sdk: true + + - name: Install Rust toolchain + run: | + rustup show + rustup component add rustfmt clippy + + - name: Cargo Format + working-directory: zenoh-jni + run: cargo fmt --all --check + + - name: Clippy Check + working-directory: zenoh-jni + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Check for feature leaks + working-directory: zenoh-jni + run: cargo test --no-default-features + + - name: Build Zenoh-JNI + working-directory: zenoh-jni + run: cargo build + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Gradle Test + run: gradle jvmTest --info diff --git a/.github/workflows/publish_android.yml b/.github/workflows/publish-android.yml similarity index 89% rename from .github/workflows/publish_android.yml rename to .github/workflows/publish-android.yml index e9d1ca4c6..580e6087c 100644 --- a/.github/workflows/publish_android.yml +++ b/.github/workflows/publish-android.yml @@ -1,15 +1,17 @@ -name: Publish Android +name: Publish (Android) on: - release: - types: [published] workflow_call: inputs: snapshot: required: true type: boolean - description: 'If the publication is for a snapshot version.' + description: "If the publication is for a snapshot version." default: false + branch: + description: Target branch + type: string + required: false workflow_dispatch: env: @@ -24,6 +26,8 @@ jobs: packages: write steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} - uses: actions/setup-java@v3 with: diff --git a/.github/workflows/documentation.yml b/.github/workflows/publish-dokka.yml similarity index 64% rename from .github/workflows/documentation.yml rename to .github/workflows/publish-dokka.yml index 15357151e..11fa6ad18 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/publish-dokka.yml @@ -1,8 +1,16 @@ -name: Publish Documentation +name: Publish (Dokka) on: - release: - types: [published] + workflow_call: + inputs: + live-run: + description: Live-run + type: boolean + required: true + branch: + description: Target branch + type: string + required: false workflow_dispatch: env: @@ -14,6 +22,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} - uses: nttld/setup-ndk@v1 id: setup-ndk @@ -26,6 +36,7 @@ jobs: run: gradle dokkaHtml - name: Deploy doc + if: ${{ inputs.live-run || false }} uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish_jvm.yml b/.github/workflows/publish-jvm.yml similarity index 93% rename from .github/workflows/publish_jvm.yml rename to .github/workflows/publish-jvm.yml index c168c6119..73b923b23 100644 --- a/.github/workflows/publish_jvm.yml +++ b/.github/workflows/publish-jvm.yml @@ -1,20 +1,22 @@ -name: Publish JVM +name: Publish (JVM) on: - release: - types: [published] workflow_call: inputs: snapshot: required: true type: boolean - description: 'If the publication is for a snapshot version.' + description: "If the publication is for a snapshot version." default: false + 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. + JNI_LIB_PATHS: jni-libs # Edit on the inner build.gradle.kts file as well. jobs: builds: @@ -59,6 +61,8 @@ jobs: steps: - name: Checkout source code uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} - name: Install prerequisites shell: bash @@ -66,7 +70,7 @@ jobs: case ${{ matrix.job.target }} in *-linux-gnu*) cargo install cargo-deb ;; esac - + case ${{ matrix.job.target }} in aarch64-unknown-linux-gnu) sudo apt-get -y update @@ -90,7 +94,7 @@ jobs: run: | TARGET=${{ matrix.job.target }} MAIN_PKG_NAME="${GITHUB_WORKSPACE}/${TARGET}.zip" - + case ${TARGET} in *linux*) cd "zenoh-jni/target/${TARGET}/release/" @@ -132,6 +136,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + ref: ${{ inputs.branch }} - name: Create resources destination run: mkdir ${{env.JNI_LIB_PATHS}} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 97e469539..302770e76 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,62 +1,102 @@ +# +# Copyright (c) 2022 ZettaScale Technology +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +# which is available at https://www.apache.org/licenses/LICENSE-2.0. +# +# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +# +# Contributors: +# ZettaScale Zenoh Team, +# name: Release on: - release: - types: [published] schedule: - - cron: "0 1 * * 1-5" + - cron: "0 0 * * 1-5" workflow_dispatch: - -env: - CARGO_TERM_COLOR: always + inputs: + live-run: + type: boolean + description: Live-run + required: false + version: + type: string + description: Release number + required: false + zenoh-version: + type: string + description: Release number of Zenoh + required: false jobs: - release: - name: Build on ${{ matrix.os }} - runs-on: [ "${{ matrix.os }}" ] - strategy: - fail-fast: false - matrix: - os: [ ubuntu-latest, macOS-latest ] - + tag: + name: Branch, Bump & tag + runs-on: ubuntu-latest + outputs: + version: ${{ steps.create-release-branch.outputs.version }} + branch: ${{ steps.create-release-branch.outputs.branch }} steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-java@v3 + - id: create-release-branch + uses: eclipse-zenoh/ci/create-release-branch@main with: - distribution: temurin - java-version: 11 + repo: ${{ github.repository }} + live-run: ${{ inputs.live-run || false }} + version: ${{ inputs.version }} + github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }} - - uses: nttld/setup-ndk@v1 - id: setup-ndk + - name: Checkout this repository + uses: actions/checkout@v4 with: - ndk-version: r26 - add-to-path: false - link-to-sdk: true - - - name: Install Rust toolchain - run: | - rustup show - rustup component add rustfmt clippy + ref: ${{ steps.create-release-branch.outputs.branch }} - - name: Cargo Format - working-directory: zenoh-jni - run: cargo fmt --all --check + - name: Bump and tag project + run: bash ci/scripts/bump-and-tag.bash + env: + VERSION: ${{ steps.create-release-branch.outputs.version }} + BUMP_DEPS_VERSION: ${{ inputs.zenoh-version }} + BUMP_DEPS_PATTERN: ${{ inputs.zenoh-version && 'zenoh.*' || '' }} + BUMP_DEPS_BRANCH: ${{ inputs.zenoh-version && format('release/{0}', inputs.zenoh-version) || '' }} + GIT_USER_NAME: eclipse-zenoh-bot + GIT_USER_EMAIL: eclipse-zenoh-bot@users.noreply.github.com - - name: Clippy Check - working-directory: zenoh-jni - run: cargo clippy --all-targets --all-features -- -D warnings + publish-jvm: + name: Publish JVM package + needs: tag + uses: ./.github/workflows/publish-jvm.yml + with: + snapshot: ${{ !(inputs.live-run || false) }} + permissions: + contents: read + packages: write - - name: Check for feature leaks - working-directory: zenoh-jni - run: cargo test --no-default-features + publish-android: + name: Publish Android package + needs: tag + uses: ./.github/workflows/publish-android.yml + with: + snapshot: ${{ !(inputs.live-run || false) }} + permissions: + contents: read + packages: write - - name: Build Zenoh-JNI - working-directory: zenoh-jni - run: cargo build + publish-dokka: + name: Publish documentation + needs: tag + uses: ./.github/workflows/publish-dokka.yml + with: + live-run: ${{ inputs.live-run || false }} - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - - - name: Gradle Test - run: gradle jvmTest --info + publish-github: + needs: tag + runs-on: macos-latest + steps: + - uses: eclipse-zenoh/ci/publish-crates-github@main + with: + repo: ${{ github.repository }} + live-run: ${{ inputs.live-run || false }} + version: ${{ needs.tag.outputs.version }} + branch: ${{ needs.tag.outputs.branch }} + github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }} diff --git a/build.gradle.kts b/build.gradle.kts index 3720f47a3..44bd0f139 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ // val zenohGroup = "io.zenoh" -val zenohVersion = "1.0.0" +val zenohVersion = file("version.txt").readText() buildscript { repositories { diff --git a/ci/scripts/bump-and-tag.bash b/ci/scripts/bump-and-tag.bash new file mode 100644 index 000000000..a913e6318 --- /dev/null +++ b/ci/scripts/bump-and-tag.bash @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +set -xeo pipefail + +# Release number +readonly version=${VERSION:?input VERSION is required} +# Dependencies' pattern +readonly bump_deps_pattern=${BUMP_DEPS_PATTERN:-''} +# Dependencies' version +readonly bump_deps_version=${BUMP_DEPS_VERSION:-''} +# Dependencies' git branch +readonly bump_deps_branch=${BUMP_DEPS_BRANCH:-''} +# Git actor name +readonly git_user_name=${GIT_USER_NAME:?input GIT_USER_NAME is required} +# Git actor email +readonly git_user_email=${GIT_USER_EMAIL:?input GIT_USER_EMAIL is required} + +cargo +stable install toml-cli + +# NOTE(fuzzypixelz): toml-cli doesn't yet support in-place modification +# See: https://github.com/gnprice/toml-cli?tab=readme-ov-file#writing-ish-toml-set +function toml_set_in_place() { + local tmp=$(mktemp) + toml set "$1" "$2" "$3" > "$tmp" + mv "$tmp" "$1" +} + +export GIT_AUTHOR_NAME=$git_user_name +export GIT_AUTHOR_EMAIL=$git_user_email +export GIT_COMMITTER_NAME=$git_user_name +export GIT_COMMITTER_EMAIL=$git_user_email + +# Bump Gradle project version +printf '%s' "$version" > version.txt +# Propagate version change to zenoh-jni +toml_set_in_place zenoh-jni/Cargo.toml "package.version" "$version" + +git commit version.txt zenoh-jni/Cargo.toml -m "chore: Bump version to $version" + +# Select all package dependencies that match $bump_deps_pattern and bump them to $bump_deps_version +if [[ "$bump_deps_pattern" != '' ]]; then + deps=$(toml get zenoh-jni/Cargo.toml dependencies | jq -r "keys[] | select(test(\"$bump_deps_pattern\"))") + for dep in $deps; do + if [[ -n $bump_deps_version ]]; then + toml_set_in_place zenoh-jni/Cargo.toml "dependencies.$dep.version" "$bump_deps_version" + fi + + if [[ -n $bump_deps_branch ]]; then + toml_set_in_place zenoh-jni/Cargo.toml "dependencies.$dep.branch" "$bump_deps_branch" + fi + done + # Update lockfile + cargo check + + if [[ -n $bump_deps_version || -n $bump_deps_branch ]]; then + git commit zenoh-jni/Cargo.toml zenoh-jni/Cargo.lock -m "chore: Bump $bump_deps_pattern version to $bump_deps_version" + else + echo "warn: no changes have been made to any dependencies matching $bump_deps_pattern" + fi +fi + +git tag --force "$version" -m "v$version" +git log -10 +git show-ref --tags +git push origin +git push --force origin "$version" diff --git a/version.txt b/version.txt new file mode 100644 index 000000000..19a5fa437 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.11.0-dev \ No newline at end of file diff --git a/zenoh-jni/Cargo.toml b/zenoh-jni/Cargo.toml index 0f2c50bd7..097e1bf5c 100644 --- a/zenoh-jni/Cargo.toml +++ b/zenoh-jni/Cargo.toml @@ -46,11 +46,6 @@ crate_type = ["staticlib", "dylib"] [build-dependencies] rustc_version = "0.4.0" -[package.metadata.deb] -name = "zenoh_jni" -maintainer = "zenoh@zettascale.tech" -copyright = "2023 ZettaScale Technology" - [profile.release] debug = false # If you want debug symbol in release mode, set the env variable: RUSTFLAGS=-g lto = "fat"