From e01463573d3e1c6bce217175e9a4859e50fb7b33 Mon Sep 17 00:00:00 2001 From: Denis Bazhenov Date: Thu, 21 Dec 2023 14:42:08 +0700 Subject: [PATCH] GHA workflow for test and release added (#1) --- .github/workflows/ci.yaml | 95 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..4cb228d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,95 @@ +name: CI + +on: + push: + +permissions: + contents: write + +# Automatically cancel any previous runs of this workflow +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + components: "clippy, rustfmt" + - uses: Swatinem/rust-cache@v2 + - name: Checking formatting + run: cargo fmt -- --check --color always + - name: Running clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + test: + strategy: + matrix: + os: [ubuntu-22.04, macos-12, windows-2022] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Test + run: cargo test --all-targets --all-features && cargo test --doc + + pre-release: + needs: [lint, test] + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Test + run: cargo publish --locked --dry-run + + release: + needs: pre-release + strategy: + matrix: + include: + - os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu + - os: macos-12 + target: x86_64-apple-darwin + - os: macos-12 + target: aarch64-apple-darwin + - os: windows-2022 + target: x86_64-pc-windows-msvc + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + target: ${{ matrix.target }} + - uses: Swatinem/rust-cache@v2 + - name: Build + run: cargo install --locked --target ${{ matrix.target }} --root release --path . + - name: Package + shell: bash + run: | + name=cargo-export + tag=$(git describe --tags --abbrev=0) + release_name="$name-$tag-${{ matrix.target }}" + release_tar="${release_name}.tar.gz" + + rm -f "release/.*" + cp README.md LICENSE release/ + mv release/ $release_name/ + tar czvf "$release_tar" "$release_name" + + if [ "${{ matrix.target }}" == "x86_64-pc-windows-msvc" ]; then + echo "(Get-FileHash \"${release_tar}\" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline \"${release_tar}.sha256\"" | pwsh -c - + else + echo -n "$(shasum -ba 256 "${release_tar}" | cut -d " " -f 1)" > "${release_tar}.sha256" + fi + - name: Publish + uses: softprops/action-gh-release@v1 + with: + draft: true + files: "cargo-export-*.tar.gz*"