You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.9 KiB
174 lines
5.9 KiB
# This is a simplification of the workflow for sharkdp/bat. |
|
|
|
name: Release |
|
on: |
|
push: |
|
# The idea here is to trigger a release upon receiving a release-like tag |
|
tags: |
|
- 'v[0-9]+.[0-9]+.[0-9]+' |
|
|
|
env: |
|
CICD_INTERMEDIATES_DIR: "_cicd-intermediates" |
|
|
|
jobs: |
|
|
|
build: |
|
name: ${{ matrix.job.os }} (${{ matrix.job.target }}) |
|
runs-on: ${{ matrix.job.os }} |
|
strategy: |
|
fail-fast: false |
|
matrix: |
|
job: |
|
- { os: ubuntu-22.04, target: x86_64-unknown-linux-gnu } |
|
- { os: ubuntu-22.04, target: arm-unknown-linux-gnueabihf, use-cross: true } |
|
- { os: ubuntu-22.04, target: arm-unknown-linux-musleabihf, use-cross: true } |
|
- { os: ubuntu-22.04, target: i686-unknown-linux-gnu, use-cross: true } |
|
- { os: ubuntu-22.04, target: i686-unknown-linux-musl, use-cross: true } |
|
- { os: ubuntu-22.04, target: x86_64-unknown-linux-musl, use-cross: true } |
|
- { os: macos-11, target: x86_64-apple-darwin } |
|
steps: |
|
- name: Checkout source code |
|
uses: actions/checkout@v4 |
|
|
|
- name: Set up cargo cache |
|
uses: actions/cache@v3 |
|
continue-on-error: false |
|
with: |
|
path: | |
|
~/.cargo/bin/ |
|
~/.cargo/registry/index/ |
|
~/.cargo/registry/cache/ |
|
~/.cargo/git/db/ |
|
target/ |
|
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} |
|
restore-keys: ${{ runner.os }}-cargo- |
|
|
|
- name: Install prerequisites |
|
shell: bash |
|
run: | |
|
case ${{ matrix.job.target }} in |
|
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;; |
|
esac |
|
|
|
- name: Extract crate information |
|
shell: bash |
|
run: | |
|
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV |
|
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV |
|
|
|
- name: Install Rust toolchain |
|
uses: actions-rs/toolchain@v1 |
|
with: |
|
toolchain: stable |
|
target: ${{ matrix.job.target }} |
|
override: true |
|
profile: minimal |
|
|
|
- name: Show version information (Rust, cargo, GCC) |
|
shell: bash |
|
run: | |
|
gcc --version || true |
|
rustup -V |
|
rustup toolchain list |
|
rustup default |
|
cargo -V |
|
rustc -V |
|
|
|
- name: Build |
|
uses: actions-rs/cargo@v1 |
|
with: |
|
use-cross: ${{ matrix.job.use-cross }} |
|
command: build |
|
args: --release --target=${{ matrix.job.target }} |
|
|
|
- name: Strip debug information from executable |
|
id: strip |
|
shell: bash |
|
run: | |
|
STRIP="strip" |
|
case ${{ matrix.job.target }} in |
|
arm-unknown-*) STRIP="arm-linux-gnueabihf-strip" ;; |
|
esac; |
|
|
|
BIN_DIR="${{ env.CICD_INTERMEDIATES_DIR }}/stripped-release-bin" |
|
mkdir -p "${BIN_DIR}" |
|
BIN_NAME="${{ env.PROJECT_NAME }}" |
|
BIN_PATH="${BIN_DIR}/${BIN_NAME}" |
|
# Copy the release build binary to the result location |
|
"${STRIP}" "target/${{ matrix.job.target }}/release/${BIN_NAME}" |
|
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}" |
|
# Let subsequent steps know where to find the (stripped) bin |
|
echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT |
|
|
|
- name: Set testing options |
|
id: test-options |
|
shell: bash |
|
run: | |
|
# test only library unit tests and binary for arm-type targets |
|
unset CARGO_TEST_OPTIONS |
|
case ${{ matrix.job.target }} in arm-*-*) CARGO_TEST_OPTIONS="--lib --bin ${PROJECT_NAME}" ;; esac; |
|
echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT |
|
|
|
- name: Run tests |
|
uses: actions-rs/cargo@v1 |
|
with: |
|
use-cross: ${{ matrix.job.use-cross }} |
|
command: test |
|
args: --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}} -- --test-threads 1 |
|
|
|
- name: Create tarball |
|
id: package |
|
shell: bash |
|
run: | |
|
PKG_BASENAME=${PROJECT_NAME}-${PROJECT_VERSION}-${{ matrix.job.target }} |
|
PKG_NAME=${PKG_BASENAME}.tar.gz |
|
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT |
|
|
|
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package" |
|
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" |
|
mkdir -p "${ARCHIVE_DIR}" |
|
cp "${{ steps.strip.outputs.BIN_PATH }}" LICENSE "$ARCHIVE_DIR" |
|
tar -C "${PKG_STAGING}/${PKG_BASENAME}" -cvzf "${PKG_STAGING}/${PKG_NAME}" "${PROJECT_NAME}" LICENSE |
|
|
|
# Let subsequent steps know where to find the compressed package |
|
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT |
|
|
|
- name: Install cargo-deb |
|
if: contains(matrix.job.target, 'musl') |
|
run: cargo install cargo-deb |
|
|
|
- name: Create deb package |
|
if: contains(matrix.job.target, 'musl') |
|
id: debian-package |
|
shell: bash |
|
run: | |
|
cargo deb --target ${{ matrix.job.target }} --no-build --no-strip |
|
DEB_PATH=target/${{ matrix.job.target }}/debian/*.deb |
|
DEB_NAME=$(basename ${DEB_PATH}) |
|
echo Names are ${DEB_NAME} and ${DEB_PATH} |
|
echo "DEB_NAME=${DEB_NAME}" >> $GITHUB_OUTPUT |
|
echo "DEB_PATH=${DEB_PATH}" >> $GITHUB_OUTPUT |
|
|
|
- name: "Artifact upload: tarball" |
|
uses: actions/upload-artifact@v3 |
|
with: |
|
name: ${{ steps.package.outputs.PKG_NAME }} |
|
path: ${{ steps.package.outputs.PKG_PATH }} |
|
if-no-files-found: error |
|
|
|
- name: "Artifact upload: Debian package" |
|
uses: actions/upload-artifact@v3 |
|
if: steps.debian-package.outputs.DEB_NAME |
|
with: |
|
name: ${{ steps.debian-package.outputs.DEB_NAME }} |
|
path: ${{ steps.debian-package.outputs.DEB_PATH }} |
|
if-no-files-found: error |
|
|
|
- name: Publish archives and packages |
|
uses: softprops/action-gh-release@v1 |
|
with: |
|
files: | |
|
${{ steps.package.outputs.PKG_PATH }} |
|
${{ steps.debian-package.outputs.DEB_PATH }} |
|
env: |
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|