cargo-binstall/.github/workflows/rust.yml

156 lines
4.8 KiB
YAML

name: Rust
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
output: cargo-binstall
archive: tgz
- target: x86_64-apple-darwin
os: macos-latest
output: cargo-binstall
archive: zip
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-20.04
output: cargo-binstall
archive: tgz
- target: x86_64-pc-windows-msvc
os: windows-latest
output: cargo-binstall.exe
archive: zip
steps:
- uses: actions/checkout@v2
- uses: FranzDiebold/github-env-vars-action@v1.2.1
- name: Configure toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: ${{ matrix.target }}
override: true
- name: Install openssl (apt armv7)
if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
uses: ryankurte/action-apt@v0.3.0
with:
arch: armhf
packages: libssl-dev:armhf libssl1.1:armhf zlib1g-dev:armhf zlib1g:armhf libc-dev:armhf
- name: Configure caching
uses: actions/cache@v2
# Caching disabled on macos due to https://github.com/actions/cache/issues/403
if: ${{ matrix.os != 'macos-latest' }}
with:
key: ${{ matrix.os }}-${{ matrix.target }}
path: |
${{ env.HOME }}/.cargo"
target
- name: Install cross toolchain (armv7)
if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
run: sudo apt install gcc-arm-linux-gnueabihf
- name: Enable cross compilation (armv7)
if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
run: |
echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
echo "LZMA_API_STATIC=1" >> $GITHUB_ENV
- name: Build release
uses: actions-rs/cargo@v1
with:
command: build
args: --target ${{ matrix.target }} --release
- name: Copy and rename utility
run: cp target/${{ matrix.target }}/release/${{ matrix.output }} ${{ matrix.output }}
- name: Create archive (tgz, linux)
if: ${{ matrix.os != 'macos-latest' && matrix.os != 'windows-latest' }}
run: tar -czvf cargo-binstall-${{ matrix.target }}.tgz ${{ matrix.output }}
- name: Create archive (zip, windows)
if: ${{ matrix.os == 'windows-latest' }}
run: tar.exe -a -c -f cargo-binstall-${{ matrix.target }}.zip ${{ matrix.output }}
- name: Create archive (zip, macos)
if: ${{ matrix.os == 'macos-latest' }}
run: zip cargo-binstall-${{ matrix.target }}.zip ${{ matrix.output }}
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
path: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
- name: Upload binary to release
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
asset_name: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
tag: ${{ github.ref }}
overwrite: true
test:
name: Test
runs-on: ${{ matrix.os }}
needs: build
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
output: cargo-binstall
archive: tgz
- target: x86_64-apple-darwin
os: macos-latest
output: cargo-binstall
archive: zip
- target: x86_64-pc-windows-msvc
os: windows-latest
output: cargo-binstall.exe
archive: zip
steps:
- uses: actions/checkout@v2
- uses: FranzDiebold/github-env-vars-action@v1.2.1
- uses: actions/download-artifact@v2
with:
name: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
- name: "Extract build artifact (tgz, linux)"
if: ${{ matrix.os != 'windows-latest' && matrix.os != 'macos-latest' }}
run: tar -xvf cargo-binstall-${{ matrix.target }}.tgz
- name: "Extract build artifact (zip, windows)"
if: ${{ matrix.os == 'windows-latest' }}
run: tar.exe -xvf cargo-binstall-${{ matrix.target }}.zip
- name: "Extract build artifact (zip, macos)"
if: ${{ matrix.os == 'macos-latest' }}
run: unzip cargo-binstall-${{ matrix.target }}.zip
- name: "Run binstall"
run: ./${{ matrix.output }} cargo-binstall --manifest-path . --no-confirm