Add udev_hwdb feature and fix cross build with feature enabled #284
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: | |
- main | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+' | |
pull_request: | |
workflow_dispatch: | |
name: Test, build and package | |
env: | |
PROJECT_NAME: cyme | |
INTERMEDIATES_DIR: intermediates | |
jobs: | |
build: | |
name: Build and test for ${{ matrix.job.os }} (${{ matrix.job.target }}) | |
runs-on: ${{ matrix.job.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
job: | |
- { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, use-cross: true, feature-flags: "--all-features" } | |
- { os: ubuntu-latest, target: x86_64-pc-windows-gnu, use-cross: true, feature-flags: "--all-features" } | |
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, use-cross: false, feature-flags: "--all-features" } | |
- { os: macos-latest, target: universal-apple-darwin, use-cross: false, feature-flags: "--all-features" } | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: dtolnay/rust-toolchain@v1 | |
with: | |
toolchain: stable | |
- name: Install prerequisites | |
shell: bash | |
run: | | |
case ${{ matrix.job.target }} in | |
*-linux-*) | |
sudo apt-get -y update; | |
sudo apt-get -y install libudev-dev; | |
sudo apt-get -y install libusb-1.0-0-dev; | |
cargo install cargo-deb | |
;; | |
universal-apple-*) | |
brew install libusb | |
rustup target add x86_64-apple-darwin | |
rustup target add aarch64-apple-darwin | |
;; | |
*) | |
;; | |
esac | |
- name: Set cargo cmd | |
shell: bash | |
run: echo "CARGO_CMD=cargo" >> "$GITHUB_ENV" | |
- name: Rustup add target | |
if: matrix.job.use-cross == false && !startsWith(matrix.job.target, 'universal-apple') | |
shell: bash | |
run: rustup target add ${{ matrix.job.target }} | |
- name: Set cargo cmd to cross | |
shell: bash | |
if: matrix.job.use-cross == true | |
run: echo "CARGO_CMD=cross" >> "$GITHUB_ENV" | |
- name: Install cross | |
shell: bash | |
if: matrix.job.use-cross == true | |
run: cargo install cross | |
- name: Format and clippy | |
id: format | |
shell: bash | |
if: matrix.job.use-cross == false | |
run: | | |
cargo fmt -- --check | |
cargo clippy --all-targets -- -Dwarnings | |
cargo clippy --all-targets --all-features -- -Dwarnings | |
- name: Test | |
id: test | |
shell: bash | |
if: matrix.job.use-cross == false | |
run: cargo test | |
- name: Build release | |
id: build | |
shell: bash | |
run: | | |
case ${{ matrix.job.target }} in | |
universal-apple-*) | |
cargo build --locked --release ${{ matrix.job.feature-flags }} --target=aarch64-apple-darwin | |
cargo build --locked --release ${{ matrix.job.feature-flags }} --target=x86_64-apple-darwin | |
mkdir -p target/universal-apple-darwin/release | |
# merge into universal | |
lipo -create -output target/universal-apple-darwin/release/cyme target/aarch64-apple-darwin/release/cyme target/x86_64-apple-darwin/release/cyme | |
;; | |
*) | |
${{ env.CARGO_CMD }} build --locked --release ${{ matrix.job.feature-flags }} --target=${{ matrix.job.target }} | |
;; | |
esac | |
- name: Prepare and extract crate information | |
id: prepare | |
shell: bash | |
run: | | |
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> "$GITHUB_ENV" | |
echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> "$GITHUB_ENV" | |
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> "$GITHUB_ENV" | |
# Figure out suffix of binary | |
EXE_SUFFIX="" | |
case ${{ matrix.job.target }} in | |
*-pc-windows-*) EXE_SUFFIX=".exe" ;; | |
esac; | |
# Setup paths | |
BIN_DIR="${{ env.INTERMEDIATES_DIR }}/release-bin" | |
mkdir -p "${BIN_DIR}" | |
BIN_NAME="${{ env.PROJECT_NAME }}${EXE_SUFFIX}" | |
BIN_PATH="${BIN_DIR}/${BIN_NAME}" | |
# Copy the release build binary to the result location | |
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}" | |
echo "BIN_PATH=${BIN_PATH}" >> "$GITHUB_OUTPUT" | |
echo "BIN_NAME=${BIN_NAME}" >> "$GITHUB_OUTPUT" | |
- name: Generate bin outputs | |
id: generate | |
shell: bash | |
if: matrix.job.use-cross == false | |
run: | | |
"${{ steps.prepare.outputs.BIN_PATH }}" --gen | |
- name: Create tarball | |
id: package | |
shell: bash | |
run: | | |
PKG_SUFFIX=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_SUFFIX=".zip" ;; esac; | |
PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }} | |
PKG_NAME=${PKG_BASENAME}${PKG_SUFFIX} | |
echo "PKG_NAME=${PKG_NAME}" >> "$GITHUB_OUTPUT" | |
PKG_STAGING="${{ env.INTERMEDIATES_DIR }}/package" | |
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" | |
mkdir -p "${ARCHIVE_DIR}" | |
# Binary | |
cp "${{ steps.prepare.outputs.BIN_PATH }}" "$ARCHIVE_DIR" | |
# README and LICENSE | |
cp "README.md" "LICENSE" "$ARCHIVE_DIR" | |
# Man page | |
cp 'doc/${{ env.PROJECT_NAME }}.1' "$ARCHIVE_DIR" | |
# Autocompletion files | |
mkdir -p autocomplete | |
cp 'doc/${{ env.PROJECT_NAME }}.fish' 'doc/${{ env.PROJECT_NAME }}.bash' 'doc/_${{ env.PROJECT_NAME }}' 'doc/_${{ env.PROJECT_NAME }}.ps1' autocomplete | |
cp -r autocomplete "${ARCHIVE_DIR}" | |
# base compressed package | |
pushd "${PKG_STAGING}/" >/dev/null | |
case ${{ matrix.job.target }} in | |
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;; | |
*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;; | |
esac; | |
popd >/dev/null | |
# Let subsequent steps know where to find the compressed package | |
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> "$GITHUB_OUTPUT" | |
- name: Create Debian package | |
id: debian-package | |
shell: bash | |
if: startsWith(matrix.job.os, 'ubuntu') && !contains(matrix.job.target, 'windows') | |
run: | | |
DPKG_STAGING="${{ env.INTERMEDIATES_DIR }}/debian-package" | |
DPKG_DIR="${DPKG_STAGING}/dpkg" | |
case ${{ matrix.job.target }} in | |
aarch64-*-linux-*) DPKG_ARCH=arm64 ;; | |
arm-*-linux-*hf) DPKG_ARCH=armhf ;; | |
i686-*-linux-*) DPKG_ARCH=i686 ;; | |
x86_64-*-linux-*) DPKG_ARCH=amd64 ;; | |
*) DPKG_ARCH=notset ;; | |
esac; | |
DPKG_NAME="${PROJECT_NAME}-v${PROJECT_VERSION}-1-${DPKG_ARCH}.deb" | |
echo "DPKG_NAME=${DPKG_NAME}" >> $GITHUB_OUTPUT | |
mkdir -p "${DPKG_DIR}" | |
DPKG_PATH="${DPKG_STAGING}/${DPKG_NAME}" | |
echo "DPKG_PATH=${DPKG_PATH}" >> $GITHUB_OUTPUT | |
cargo deb --target=${{ matrix.job.target }} --output "${DPKG_PATH}" --no-build --no-strip | |
- name: Upload package artifact | |
uses: actions/upload-artifact@master | |
with: | |
name: ${{ steps.package.outputs.PKG_NAME }} | |
path: ${{ steps.package.outputs.PKG_PATH }} | |
- name: Upload dpkg artifact | |
uses: actions/upload-artifact@master | |
if: steps.debian-package.outputs.DPKG_NAME | |
with: | |
name: ${{ steps.debian-package.outputs.DPKG_NAME }} | |
path: ${{ steps.debian-package.outputs.DPKG_PATH }} | |
- name: Check for release | |
id: is-release | |
shell: bash | |
run: | | |
unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi | |
echo "IS_RELEASE=${IS_RELEASE}" >> "$GITHUB_OUTPUT" | |
- name: Publish archives and packages | |
uses: softprops/action-gh-release@v1 | |
if: steps.is-release.outputs.IS_RELEASE | |
with: | |
files: | | |
${{ steps.package.outputs.PKG_PATH }} | |
${{ steps.debian-package.outputs.DPKG_PATH }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Wait package uploaded | |
if: steps.is-release.outputs.IS_RELEASE && startsWith(matrix.job.target, 'universal-apple') | |
run: sleep 5 # sleep to ensure package is uploaded before homebrew | |
- name: Bump Homebrew formula | |
uses: mislav/bump-homebrew-formula-action@v2 | |
if: steps.is-release.outputs.IS_RELEASE && startsWith(matrix.job.target, 'universal-apple') | |
with: | |
formula-name: cyme | |
formula-path: Formula/cyme.rb | |
homebrew-tap: tuna-f1sh/homebrew-taps | |
download-url: https://github.com/tuna-f1sh/cyme/releases/download/v${{ env.PROJECT_VERSION}}/${{ steps.package.outputs.PKG_NAME }} | |
commit-message: | | |
{{formulaName}} {{version}} | |
Created by https://github.com/mislav/bump-homebrew-formula-action | |
env: | |
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }} |