Tidy up features
[ouch.git] / .github / workflows / build-and-test.yml
blob4a9c955f6bc9753e3ac6258c7a6836f1ee74fb08
1 name: build-and-test
3 on:
4   push:
5     branches:
6       - main
7     tags:
8       - "[0-9]+.[0-9]+.[0-9]+"
9   pull_request:
11 jobs:
12   build:
13     name: build
14     runs-on: ${{ matrix.os }}
15     env:
16       CARGO: cargo
17     strategy:
18       matrix:
19         include:
20           - target: aarch64-unknown-linux-gnu
21             os: ubuntu-latest
22             no-zstd-thin: true
24           - target: aarch64-unknown-linux-musl
25             os: ubuntu-latest
26             no-zstd-thin: true
28           - target: armv7-unknown-linux-gnueabihf
29             os: ubuntu-latest
30             no-zstd-thin: true
32           - target: armv7-unknown-linux-musleabihf
33             os: ubuntu-latest
34             no-zstd-thin: true
36           - target: x86_64-apple-darwin
37             os: macos-latest
39           - target: x86_64-pc-windows-gnu
40             os: windows-latest
41             no-zstd-thin: true
42             ext: .exe
44           - target: x86_64-pc-windows-msvc
45             os: windows-latest
46             ext: .exe
48           - target: aarch64-pc-windows-msvc
49             os: windows-latest
50             ext: .exe
51             skip-test: true
53           - target: x86_64-unknown-linux-gnu
54             os: ubuntu-latest
56           - target: x86_64-unknown-linux-musl
57             os: ubuntu-latest
59     steps:
60       - name: Checkout
61         uses: actions/checkout@v4
63       - name: Install cross (non-x86_64 linux)
64         if: matrix.target != 'x86_64-unknown-linux-gnu' && runner.os == 'Linux'
65         run: |
66           pushd "$(mktemp -d)"
67           wget https://github.com/cross-rs/cross/releases/download/v0.2.4/cross-x86_64-unknown-linux-musl.tar.gz
68           tar xf cross-x86_64-unknown-linux-musl.tar.gz
69           cp cross ~/.cargo/bin
70           popd
71           echo CARGO=cross >> $GITHUB_ENV
73       - name: Set up extra cargo flags
74         if: matrix.no-zstd-thin
75         run: |
76           echo "EXTRA_CARGO_FLAGS=--no-default-features --features use_zlib" >> $GITHUB_ENV
78       - name: Install Rust
79         run: |
80           rustup toolchain install stable nightly --profile minimal -t ${{ matrix.target }}
82       - name: Test on stable
83         if: ${{ ! matrix.skip-test }}
84         run: |
85           ${{ env.CARGO }} +stable test --target ${{ matrix.target }} $EXTRA_CARGO_FLAGS
87       - name: Release on nightly
88         run: |
89           ${{ env.CARGO }} +nightly build --release --target ${{ matrix.target }} $EXTRA_CARGO_FLAGS
90         env:
91           OUCH_ARTIFACTS_FOLDER: artifacts
92           RUSTFLAGS: -C strip=symbols
94       - name: Upload artifacts
95         uses: actions/upload-artifact@v3
96         with:
97           name: ouch-${{ matrix.target }}${{ matrix.ext }}
98           path: |
99             target/${{ matrix.target }}/release/ouch${{ matrix.ext }}
100             artifacts/
103   clippy-rustfmt:
104     name: clippy-rustfmt
105     runs-on: ubuntu-latest
106     steps:
107       - name: Checkout
108         uses: actions/checkout@v4
110       - name: "Cargo: clippy, fmt"
111         run: |
112           rustup toolchain install stable --profile minimal -c clippy
113           rustup toolchain install nightly --profile minimal -c rustfmt
114           cargo +stable clippy -- -D warnings
115           cargo +nightly fmt -- --check
117   github-release:
118     name: github-release
119     runs-on: ubuntu-latest
120     if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
121     needs: build
122     steps:
123       - name: Checkout
124         uses: actions/checkout@v4
126       - name: Download artifacts
127         uses: dawidd6/action-download-artifact@v2
128         with:
129           path: artifacts
131       - name: Package release assets
132         run: scripts/package-release-assets.sh
134       - name: Create release
135         uses: softprops/action-gh-release@v1
136         with:
137           draft: true
138           files: release/ouch-*