From c44146293219ef5b97ab9acbd28f05dd81a78039 Mon Sep 17 00:00:00 2001 From: Mehul Arora Date: Mon, 4 Nov 2024 09:20:00 -0500 Subject: [PATCH] chore: add CI action --- .github/workflows/ci.yml | 42 +++++++++++++++++++++ .github/workflows/release.yml | 69 +++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9360312 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI +permissions: + contents: read +on: + pull_request: + push: + branches: + - main +env: + RUST_BACKTRACE: 1 + CARGO_TERM_COLOR: always + CLICOLOR: 1 + CARGO_INCREMENTAL: 0 +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + toolchain: stable + - name: Install Protoc + uses: arduino/setup-protoc@v3 + - uses: Swatinem/rust-cache@v2 + - name: Check documentation + env: + RUSTDOCFLAGS: -D warnings + run: cargo doc --workspace --all-features --no-deps --document-private-items + - name: Install cargo-sort + uses: baptiste0928/cargo-install@v3 + with: + crate: cargo-sort + version: "^1.0" + - name: Check formatting + run: cargo +nightly fmt --all -- --check + - name: Check Cargo.toml sorting + run: cargo sort --workspace --check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9da6264 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,69 @@ +name: release +on: + push: + tags: ["[0-9]+.[0-9]+.[0-9]+*"] + workflow_dispatch: +jobs: + build_binaries: + name: ${{ matrix.target }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: macos-latest + target: x86_64-apple-darwin + - os: macos-latest + target: aarch64-apple-darwin + - os: windows-latest + target: x86_64-pc-windows-msvc + - os: windows-latest + target: aarch64-pc-windows-msvc + steps: + - name: checkout + uses: actions/checkout@v4 + - name: Get version + id: get_version + uses: SebRollen/toml-action@v1.2.0 + with: + file: Cargo.toml + field: package.version + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + rustflags: "" + - uses: taiki-e/install-action@v2 + with: + tool: cross + - name: Build + run: cross build --release --target ${{ matrix.target }} + - name: Prepare artifacts + shell: bash + run: "\ncd target/${{ matrix.target }}/release\n\nif [ \"${{ matrix.os }}\" = \"windows-latest\" ]; then\n 7z a ../../../$s2-cli-${{ matrix.target }}.zip $s2-cli.exe\nelse\n tar -czf ../../../$s2-cli-${{ matrix.target }}.tar.gz $s2-cli\nfi \n" + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }} + path: | + *.tar.gz + *.zip + if-no-files-found: error + create_release: + needs: build_binaries + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Download artifacts + uses: actions/download-artifact@v4 + - name: Create Release + uses: softprops/action-gh-release@v2 + with: + files: | + **/*.tar.gz + **/*.zip + draft: true + generate_release_notes: true