ci: improve `build.yml`

pull/41/head
sgoudham 1 year ago
parent 1999f1b700
commit 6f5e421ffb
Signed by: hammy
GPG Key ID: 44E818FD5457EEA4

@ -1,107 +1,128 @@
# Copyright (c) 2023 Hamothy
# Copyright (c) 2015 Andrew Gallant
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
name: build
on:
workflow_dispatch:
push:
branches:
- '**'
paths:
- "src/**"
- "Cargo.toml"
- "Cargo.lock"
pull_request:
paths:
- "src/**"
- "Cargo.toml"
- "Cargo.lock"
env:
BINARY: mdbook-template
jobs:
install-cross:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 50
- uses: XAMPPRocky/get-github-release@v1
id: cross
with:
owner: rust-embedded
repo: cross
matches: ${{ matrix.platform }}
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/upload-artifact@v1
with:
name: cross-${{ matrix.platform }}
path: ${{ steps.cross.outputs.install_path }}
compile:
env:
CARGO: cargo
TARGET_FLAGS:
TARGET_DIR: ./target
RUST_BACKTRACE: 1
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
platform: [ linux-musl, apple-darwin ]
windows:
runs-on: windows-latest
needs: install-cross
build:
- stable
- nightly-gnu
- nightly-musl
- nightly-32
- nightly-arm
- macos
- win-msvc
- win-gnu
include:
- build: stable
os: ubuntu-22.04
rust: stable
- build: nightly-gnu
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-gnu
- build: nightly-musl
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-musl
- build: nightly-32
os: ubuntu-22.04
rust: nightly
target: i686-unknown-linux-gnu
- build: nightly-arm
os: ubuntu-22.04
rust: nightly
target: arm-unknown-linux-gnueabihf
- build: macos
os: macos-12
rust: nightly
- build: win-msvc
os: windows-2022
rust: nightly
- build: win-gnu
os: windows-2022
rust: nightly-x86_64-gnu
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 50
- run: .github/scripts/set_rust_version.bash ${{ matrix.channel }} ${{ matrix.target }}
shell: bash
- run: .github/scripts/build.bash cargo ${{ matrix.target }}
shell: bash
- run: .github/scripts/test.bash cargo ${{ matrix.target }}
shell: bash
- name: Checkout repository
uses: actions/checkout@v3
strategy:
matrix:
channel: [ stable, beta ]
target:
- x86_64-pc-windows-gnu
- x86_64-pc-windows-msvc
- name: Install packages (Ubuntu)
if: matrix.os == 'ubuntu-22.04'
shell: bash
run: sudo apt-get update && sudo apt-get install -y --no-install-recommends musl-tools
macos:
runs-on: macos-latest
needs: install-cross
steps:
- uses: actions/checkout@v2
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
fetch-depth: 50
toolchain: ${{ matrix.rust }}
- uses: actions/download-artifact@v1
with:
name: cross-apple-darwin
path: /usr/local/bin/
- name: Cache Rust
uses: Swatinem/rust-cache@v2
- run: chmod +x /usr/local/bin/cross
- name: Use Cross
if: matrix.target != ''
run: |
cargo install cross
echo "CARGO=cross" >> $GITHUB_ENV
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
- run: .github/scripts/set_rust_version.bash ${{ matrix.channel }} ${{ matrix.target }}
- run: .github/scripts/build.bash cross ${{ matrix.target }}
- run: .github/scripts/test.bash cross ${{ matrix.target }}
if: matrix.target == 'x86_64-apple-darwin'
- name: Show command used for Cargo
run: |
echo "cargo command is: ${{ env.CARGO }}"
echo "target flag is: ${{ env.TARGET_FLAGS }}"
strategy:
matrix:
channel: [ stable, beta ]
target:
- x86_64-apple-darwin
- name: Compile
run: ${{ env.CARGO }} build --verbose ${{ env.TARGET_FLAGS }}
linux:
runs-on: ubuntu-latest
needs: install-cross
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 50
- name: Test
run: ${{ env.CARGO }} test --verbose ${{ env.TARGET_FLAGS }}
- name: Download Cross
uses: actions/download-artifact@v1
with:
name: cross-linux-musl
path: /tmp/
- run: chmod +x /tmp/cross
- run: .github/scripts/set_rust_version.bash ${{ matrix.channel }} ${{ matrix.target }}
- run: .github/scripts/build.bash /tmp/cross ${{ matrix.target }}
- run: .github/scripts/test.bash /tmp/cross ${{ matrix.target }}
if: |
!contains(matrix.target, 'android') &&
!contains(matrix.target, 'bsd') &&
!contains(matrix.target, 'solaris') &&
matrix.target != 'armv5te-unknown-linux-musleabi' &&
matrix.target != 'sparc64-unknown-linux-gnu'
- name: Retrieve Name of Binary
id: upload-artifact
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-2022" ]; then
echo "name=${{ env.TARGET_DIR }}/debug/${{ env.BINARY }}.exe" >> $GITHUB_OUTPUT
else
echo "name=${{ env.TARGET_DIR}}/debug/${{ env.BINARY }}" >> $GITHUB_OUTPUT
fi
strategy:
matrix:
channel: [ stable, beta ]
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
- name: Upload Binary
uses: actions/upload-artifact@v3
with:
name: ${{ env.BINARY }}-${{ matrix.build }}
path: ${{ steps.upload-artifact.outputs.name }}
Loading…
Cancel
Save