Skip to content

Commit

Permalink
Take release steps to CI to check them
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowhatter committed Sep 26, 2023
1 parent 73824ba commit 4156b6a
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 393 deletions.
249 changes: 206 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2023 ZettaScale Technology
# 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
Expand All @@ -22,77 +22,240 @@ on:
- cron: "0 6 * * 1-5"

jobs:
check:
name: Run checks on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]

checks:
name: Code checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
components: rustfmt, clippy

- name: Code format check
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

- name: Clippy
- name: Clippy check
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
args: -- -D warnings
- name: Environment setup
id: env
shell: bash
run: |
# log some info
gcc --version || true
rustup -V
rustup toolchain list
rustup default
cargo -V
rustc -V
test:
name: Run tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
echo "GITHUB_REF=${GITHUB_REF}"
echo "GITHUB_SHA=${GITHUB_SHA:0:8}"
GIT_BRANCH=`[[ $GITHUB_REF =~ ^refs/heads/.* ]] && echo ${GITHUB_REF/refs\/heads\//} || true`
echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_OUTPUT
GIT_TAG=`[[ $GITHUB_REF =~ ^refs/tags/.* ]] && echo ${GITHUB_REF/refs\/tags\//} || true`
echo "GIT_TAG=${GIT_TAG}" >> $GITHUB_OUTPUT
sudo apt-get update
sudo apt-get install -y jq
ZENOH_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "zenoh-plugin-ros1") | .version')
echo "ZENOH_VERSION=${ZENOH_VERSION}" >> $GITHUB_OUTPUT
if [ -n "${GIT_TAG}" ]; then
IS_RELEASE="true"
echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT
PKG_VERSION=${ZENOH_VERSION}
elif [ -n "${GIT_BRANCH}" ]; then
PKG_VERSION=${GIT_BRANCH}-${GITHUB_SHA:0:8}
else
PKG_VERSION=${ZENOH_VERSION}-${GITHUB_SHA:0:8}
fi
echo "PKG_VERSION=${PKG_VERSION}" >> $GITHUB_OUTPUT
cat ${GITHUB_OUTPUT}
outputs:
GIT_BRANCH: ${{ steps.env.outputs.GIT_BRANCH }}
GIT_TAG: ${{ steps.env.outputs.GIT_TAG }}
IS_RELEASE: ${{ steps.env.outputs.IS_RELEASE }}
ZENOH_VERSION: ${{ steps.env.outputs.ZENOH_VERSION }}
PKG_VERSION: ${{ steps.env.outputs.PKG_VERSION }}

builds:
name: Build for ${{ matrix.job.target }} on ${{ matrix.job.os }}
needs: checks
runs-on: ${{ matrix.job.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]

job:
- { target: x86_64-unknown-linux-gnu, arch: amd64, os: ubuntu-20.04 }
- { target: x86_64-apple-darwin, arch: darwin, os: macos-latest }
- { target: aarch64-apple-darwin, arch: darwin, os: macos-latest }
- {
target: x86_64-unknown-linux-musl,
arch: amd64,
os: ubuntu-20.04,
use-cross: true,
}
- {
target: arm-unknown-linux-gnueabi,
arch: armel,
os: ubuntu-20.04,
use-cross: true,
}
- {
target: arm-unknown-linux-gnueabihf,
arch: armhf,
os: ubuntu-20.04,
use-cross: true,
}
- {
target: armv7-unknown-linux-gnueabihf,
arch: armhf,
os: ubuntu-20.04,
use-cross: true,
}
- {
target: aarch64-unknown-linux-gnu,
arch: arm64,
os: ubuntu-20.04,
use-cross: true,
}
- {
target: aarch64-unknown-linux-musl,
arch: arm64,
os: ubuntu-20.04,
use-cross: true,
}
# win is possible to build on, but we don't target it for now
# - { target: x86_64-pc-windows-msvc, arch: win64, os: windows-2019 }
# - { target: x86_64-pc-windows-gnu , arch: win64 , os: windows-2019 }
steps:
- uses: actions/checkout@v2
- name: Checkout source code
uses: actions/checkout@v2
with:
fetch-depth: 500 # NOTE: get long history for git-version crate to correctly compute a version
- name: Fetch Git tags # NOTE: workaround for https://github.com/actions/checkout/issues/290
shell: bash
run: git fetch --tags --force
- name: Install prerequisites
shell: bash
run: |
case ${{ matrix.job.target }} in
*-linux-gnu*) cargo install cargo-deb;;
esac
- name: Install latest Rust toolchain
case ${{ matrix.job.target }} in
arm-unknown-linux-gnueabi)
sudo apt-get -y update
sudo apt-get -y install gcc-arm-linux-gnueabi
;;
arm*-unknown-linux-gnueabihf)
sudo apt-get -y update
sudo apt-get -y install gcc-arm-linux-gnueabihf
;;
aarch64-unknown-linux-gnu)
sudo apt-get -y update
sudo apt-get -y install gcc-aarch64-linux-gnu
;;
esac
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.job.target }}
override: true
profile: minimal

- name: Build
- name: zenoh-plugin-ros1 > Build
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: build
args: --verbose --all-targets
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
args: --release --target=${{ matrix.job.target }} -p zenoh-plugin-ros1

- name: Install ROS
run: sudo apt install -y ros-base
- name: zenoh-bridge-ros1 > Build
uses: actions-rs/cargo@v1
with:
use-cross: ${{ matrix.job.use-cross }}
command: build
args: --release --target=${{ matrix.job.target }} -p zenoh-bridge-ros1

- name: Run tests
- name: zenoh-plugin-ros1 > Debian package
if: contains(matrix.job.target, '-linux-gnu')
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
ASYNC_STD_THREAD_COUNT: 4
command: deb
args: --no-build --target=${{ matrix.job.target }} -p zenoh-plugin-ros1

- name: Run doctests
- name: zenoh-bridge-ros1 > Debian package
if: contains(matrix.job.target, '-linux-gnu')
uses: actions-rs/cargo@v1
with:
command: test
args: --doc
env:
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
ASYNC_STD_THREAD_COUNT: 4
command: deb
args: --no-build --target=${{ matrix.job.target }} -p zenoh-bridge-ros1

- name: Packaging
id: package
shell: bash
run: |
TARGET=${{ matrix.job.target }}
LIB_PKG_NAME="${GITHUB_WORKSPACE}/zenoh-plugin-ros1-${{ needs.checks.outputs.PKG_VERSION }}-${TARGET}.zip"
BIN_PKG_NAME="${GITHUB_WORKSPACE}/zenoh-bridge-ros1-${{ needs.checks.outputs.PKG_VERSION }}-${TARGET}.zip"
DEBS_PKG_NAME="${GITHUB_WORKSPACE}/zenoh-plugin-ros1-${{ needs.checks.outputs.PKG_VERSION }}-${TARGET}-deb-pkgs.zip"
case ${TARGET} in
*linux*)
cd "target/${TARGET}/release/"
echo "Packaging ${LIB_PKG_NAME}:"
zip ${LIB_PKG_NAME} libzenoh_plugin*.so
echo "Packaging ${BIN_PKG_NAME}:"
zip ${BIN_PKG_NAME} zenoh-bridge-ros1
cd -
echo "LIB_PKG_NAME=${LIB_PKG_NAME}" >> $GITHUB_OUTPUT
echo "BIN_PKG_NAME=${BIN_PKG_NAME}" >> $GITHUB_OUTPUT
# check if debian packages has been created and packages them in a single tgz
if [[ -d target/${TARGET}/debian ]]; then
cd target/${TARGET}/debian
echo "Packaging ${DEBS_PKG_NAME}:"
zip ${DEBS_PKG_NAME} *.deb
cd -
echo "DEBS_PKG_NAME=${DEBS_PKG_NAME}" >> $GITHUB_OUTPUT
fi
;;
*apple*)
cd "target/${TARGET}/release/"
echo "Packaging ${LIB_PKG_NAME}:"
zip ${LIB_PKG_NAME} libzenoh_plugin*.dylib
echo "Packaging ${BIN_PKG_NAME}:"
zip ${BIN_PKG_NAME} zenoh-bridge-ros1
cd -
echo "LIB_PKG_NAME=${LIB_PKG_NAME}" >> $GITHUB_OUTPUT
echo "BIN_PKG_NAME=${BIN_PKG_NAME}" >> $GITHUB_OUTPUT
;;
*windows*)
cd "target/${TARGET}/release/"
echo "Packaging ${LIB_PKG_NAME}:"
7z -y a "${LIB_PKG_NAME}" zenoh-plugin*.dll
echo "Packaging ${BIN_PKG_NAME}:"
7z -y a "${BIN_PKG_NAME}" zenoh-bridge-ros1.exe
cd -
echo "LIB_PKG_NAME=${LIB_PKG_NAME}" >> $GITHUB_OUTPUT
echo "BIN_PKG_NAME=${BIN_PKG_NAME}" >> $GITHUB_OUTPUT
;;
esac
- name: "Upload packages"
uses: actions/upload-artifact@master
with:
name: ${{ matrix.job.target }}
path: |
${{ steps.package.outputs.LIB_PKG_NAME }}
${{ steps.package.outputs.BIN_PKG_NAME }}
${{ steps.package.outputs.DEBS_PKG_NAME }}
Loading

0 comments on commit 4156b6a

Please sign in to comment.