Skip to content

refactor(ci): use cross #1341

refactor(ci): use cross

refactor(ci): use cross #1341

Workflow file for this run

name: Build/Test/Release
on:
push:
tags: [ "v*" ]
branches: [ "master" ]
pull_request:
branches: [ "master" ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
PACKAGE: "clash"
jobs:
compile:
name: ${{ matrix.release-name || 'Unknown' }}
permissions:
contents: write
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
include:
# Example
# when not set, default will be used (except target, cross)
# - os: ubuntu-latest
# target: x86_64-unknown-linux-gnu
# release-name: x86_64-linux
# toolchain: stable
# cross: true
# postfix: ""
# extra-args: ""
# components: ""
# Linux x86
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
release-name: x86_64-linux
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
release-name: x86_64-linux-musl
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: i686-unknown-linux-gnu
release-name: i686-linux
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: i686-unknown-linux-musl
release-name: i686-linux-musl
cross: true
extra-args: "--all-features"
# Linux arm
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
release-name: aarch64-linux
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
release-name: aarch64-linux-musl
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: armv7-unknown-linux-gnueabi
release-name: armv7-linux
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
release-name: armv7-linux-hf
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: armv7-unknown-linux-musleabi
release-name: armv7-linux-musl
cross: true
extra-args: "--all-features"
- os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
release-name: armv7-linux-muslhf
cross: true
extra-args: "--all-features"
# Linux mips tier-3, pity
# - os: ubuntu-latest
# target: mips-unknown-linux-gnu
# release-name: mips-linux
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# - os: ubuntu-latest
# target: mips-unknown-linux-musl
# release-name: mips-linux-musl
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# - os: ubuntu-latest
# target: mips64-unknown-linux-gnuabi64
# release-name: mips64-linux
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# - os: ubuntu-latest
# target: mips64-unknown-linux-muslabi64
# release-name: mips64-linux-musl
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# Linux mipsel
# - os: ubuntu-latest
# target: mipsel-unknown-linux-gnu
# release-name: mipsel-linux
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# - os: ubuntu-latest
# target: mipsel-unknown-linux-musl
# release-name: mipsel-linux-musl
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# - os: ubuntu-latest
# target: mips64el-unknown-linux-gnuabi64
# release-name: mips64el-linux
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# - os: ubuntu-latest
# target: mips64el-unknown-linux-muslabi64
# release-name: mips64el-linux-musl
# toolchain: nightly
# components: rust-src
# extra-args: "-Zbuild-std"
# Need update rustls
# # Linux risc-v
# - os: ubuntu-latest
# target: riscv64gc-unknown-linux-gnu
# release-name: riscv64gc-linux
# toolchain: nightly
# Windows
- os: windows-latest
target: x86_64-pc-windows-msvc
release-name: x86_64-windows
cross: false
postfix: ".exe"
extra-args: "--all-features"
- os: windows-latest
target: i686-pc-windows-msvc
release-name: i686-windows
cross: false
postfix: ".exe"
extra-args: "--all-features"
# Windows GNU TODO: wine has bug now (
# - os: ubuntu-latest
# target: x86_64-pc-windows-gnu
# release-name: x86_64-windows-gnu
# cross: true
# postfix: ".exe"
# extra-args: "--all-features"
# MacOSX
- os: macos-12
target: x86_64-apple-darwin
release-name: x86_64-darwin
cross: false
extra-args: "--all-features"
- os: macos-14
target: aarch64-apple-darwin
release-name: aarch64-darwin
cross: false
extra-args: "--all-features"
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ matrix.target }}-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ matrix.target }}
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.toolchain || 'stable' }}
target: ${{ matrix.target }}
components: ${{ matrix.components || 'rustfmt, clippy' }}
- name: Cargo fmt
uses: clechasseur/rs-cargo@v2
with:
use-cross: ${{ matrix.cross }}
command: fmt
args: --all -- --check
- name: Cargo clippy
uses: clechasseur/rs-cargo@v2
with:
use-cross: ${{ matrix.cross }}
command: clippy
args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }} -- -D warnings
- name: Cargo test
uses: clechasseur/rs-cargo@v2
if: startsWith(matrix.os, 'ubuntu')
with:
use-cross: ${{ matrix.cross }}
command: test
args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }}
env:
CROSS_CONTAINER_OPTS: "--network host"
- name: Cargo test (no docker test)
uses: clechasseur/rs-cargo@v2
if: ${{ !startsWith(matrix.os, 'ubuntu') }}
with:
use-cross: ${{ matrix.cross }}
command: test
args: --all --target ${{ matrix.target }} ${{ matrix.extra-args }}
env:
CLASH_RS_CI: "true"
- name: Cargo build
uses: clechasseur/rs-cargo@v2
with:
use-cross: ${{ matrix.cross }}
command: build
args: --release --target ${{ matrix.target }} ${{ matrix.extra-args }}
- name: Rename binary
run: mv target/${{ matrix.target }}/release/${{ env.PACKAGE }}${{ matrix.postfix }} ${{ env.PACKAGE }}-${{ matrix.release-name }}${{ matrix.postfix }}
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.target }}-${{ env.PACKAGE }}
path: ${{ env.PACKAGE }}-${{ matrix.release-name }}${{ matrix.postfix }}
release:
name: Release
needs: [compile]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Merge binaries
uses: actions/upload-artifact/merge@v4
with:
name: binaries
pattern: binary-*
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: ./packages
- name: Github stable release
uses: "mathieucarbou/marvinpinto-action-automatic-releases@master"
if: startsWith(github.ref, 'refs/tags/v')
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
files: |
packages/*
LICENSE
- name: Github nightly release
uses: "mathieucarbou/marvinpinto-action-automatic-releases@master"
if: startsWith(github.ref, 'refs/heads/master')
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: true
automatic_release_tag: "latest"
files: |
packages/*
LICENSE