Merge pull request #317 from ouch-org/edit-cargo-manifest-keywords
[ouch.git] / .github / workflows / build-and-test.yml
blobde41f5208c2756b5fd213767a504d17a84fd75f5
1 name: build-and-test
3 on: [push, pull_request]
5 jobs:
6   build:
7     name: build
8     runs-on: ${{ matrix.os }}
9     env:
10       CARGO: cargo
11     strategy:
12       matrix:
13         include:
14           - target: aarch64-unknown-linux-gnu
15             os: ubuntu-latest
16             no-zstd-thin: true
18           - target: aarch64-unknown-linux-musl
19             os: ubuntu-latest
20             no-zstd-thin: true
22           - target: armv7-unknown-linux-gnueabihf
23             os: ubuntu-latest
24             no-zstd-thin: true
26           - target: armv7-unknown-linux-musleabihf
27             os: ubuntu-latest
28             no-zstd-thin: true
30           - target: x86_64-apple-darwin
31             os: macos-latest
33           - target: x86_64-pc-windows-gnu
34             os: windows-latest
35             no-zstd-thin: true
36             ext: .exe
38           - target: x86_64-pc-windows-msvc
39             os: windows-latest
40             ext: .exe
42           - target: x86_64-unknown-linux-gnu
43             os: ubuntu-latest
45           - target: x86_64-unknown-linux-musl
46             os: ubuntu-latest
48     steps:
49       - name: Checkout
50         uses: actions/checkout@v3
52       - name: Install cross (non-x86_64 linux)
53         if: "!contains(matrix.target, 'x86_64') && runner.os == 'Linux'"
54         run: |
55           pushd "$(mktemp -d)"
56           wget https://github.com/cross-rs/cross/releases/download/v0.2.4/cross-x86_64-unknown-linux-musl.tar.gz
57           tar xf cross-x86_64-unknown-linux-musl.tar.gz
58           cp cross ~/.cargo/bin
59           popd
60           echo CARGO=cross >> $GITHUB_ENV
62       - name: Install dependencies (x86_64-unknown-linux-musl)
63         if: matrix.target == 'x86_64-unknown-linux-musl'
64         run: |
65           sudo apt-get update
66           sudo apt-get install musl-tools
68       - name: Set up extra cargo flags
69         if: matrix.no-zstd-thin
70         run: |
71           echo "EXTRA_CARGO_FLAGS=--no-default-features --features flate2/zlib,zip/deflate-zlib" >> $GITHUB_ENV
73       - name: Install Rust
74         run: |
75           rustup toolchain install stable nightly --profile minimal -t ${{ matrix.target }}
77       - name: Test on stable
78         run: |
79           ${{ env.CARGO }} +stable test --target ${{ matrix.target }} $EXTRA_CARGO_FLAGS
81       - name: Release on nightly
82         run: |
83           ${{ env.CARGO }} +nightly build --release --target ${{ matrix.target }} $EXTRA_CARGO_FLAGS
84         env:
85           OUCH_ARTIFACTS_FOLDER: artifacts
86           RUSTFLAGS: -C strip=symbols
88       - name: Upload binary
89         uses: actions/upload-artifact@v3
90         with:
91           name: ouch-${{ matrix.target }}${{ matrix.ext }}
92           path: target/${{ matrix.target }}/release/ouch${{ matrix.ext }}
94       - name: Upload artifacts (musl)
95         if: matrix.target == 'x86_64-unknown-linux-musl'
96         uses: actions/upload-artifact@v3
97         with:
98           name: artifacts
99           path: artifacts
101   clippy-rustfmt:
102     name: clippy-rustfmt
103     runs-on: ubuntu-latest
104     steps:
105       - name: Checkout
106         uses: actions/checkout@v3
108       - name: "Cargo: clippy, fmt"
109         run: |
110           rustup toolchain install stable --profile minimal -c clippy
111           rustup toolchain install nightly --profile minimal -c rustfmt
112           cargo +stable clippy -- -D warnings
113           cargo +nightly fmt -- --check
115   github-release:
116     name: github-release
117     runs-on: ubuntu-latest
118     if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
119     needs: build
120     steps:
121       - name: Checkout
122         uses: actions/checkout@v3
124       - name: Download artifacts
125         uses: dawidd6/action-download-artifact@v2
126         with:
127           path: artifacts
129       - name: Package release assets
130         run: scripts/package-release-assets.sh
132       - name: Create release
133         uses: softprops/action-gh-release@v1
134         with:
135           draft: true
136           files: release/ouch-*