a few more examples #245
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, pull_request] | |
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: arm-unknown-linux-gnueabihf, use-cross: true } | |
- { os: ubuntu-latest, target: aarch64-unknown-linux-gnu, use-cross: true } | |
# - { os: ubuntu-latest, target: i686-unknown-linux-gnu, use-cross: true } | |
# - { os: ubuntu-latest, target: i686-pc-windows-gnu, use-cross: true } | |
- { os: ubuntu-latest, target: x86_64-pc-windows-gnu, use-cross: true } | |
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, use-cross: false } | |
- { os: macos-latest, target: universal-apple-darwin, use-cross: false } | |
# Targets are built as part of universal | |
# - { os: macos-latest, target: x86_64-apple-darwin, use-cross: false } | |
# - { os: macos-latest, target: aarch64-apple-darwin, use-cross: false } | |
# Windows host targets don't build | |
# - { os: windows-latest, target: i686-pc-windows-gnu, use-cross: false } | |
# - { os: windows-latest, target: x86_64-pc-windows-gnu, use-cross: false } | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions-rs/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; | |
;; | |
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: Test | |
id: test | |
shell: bash | |
# don't run tests on Windows because libusb needs install TODO | |
if: matrix.job.use-cross == false && !startsWith(matrix.job.os, 'windows') | |
run: cargo test | |
# run: | | |
# case ${{ matrix.job.target }} in | |
# # apple only test on platform arch | |
# *-apple-*) | |
# cargo test | |
# ;; | |
# # else test on target arch | |
# *) | |
# ${{ env.CARGO_CMD }} test --target=${{ matrix.job.target }} | |
# ;; | |
# esac | |
- name: Build release | |
id: build | |
shell: bash | |
run: | | |
case ${{ matrix.job.target }} in | |
universal-apple-*) | |
cargo build --locked --release --all-features --target=aarch64-apple-darwin | |
cargo build --locked --release --all-features --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 --all-features --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: Upload package artifact | |
uses: actions/upload-artifact@master | |
with: | |
name: ${{ steps.package.outputs.PKG_NAME }} | |
path: ${{ steps.package.outputs.PKG_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 }} | |
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 }} |