From 22540f3fde4eee3fd35a8198b95f35faf0f87f87 Mon Sep 17 00:00:00 2001 From: thomasschafer Date: Thu, 14 Nov 2024 22:07:28 +0000 Subject: [PATCH] Run tests on all platforms, and add release workflow --- .github/workflows/release.yml | 63 +++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 33 ++++++++++++++++++ .github/workflows/tests.yml | 20 ----------- 3 files changed, 96 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..901c5d4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,63 @@ +name: Release + +on: + push: + branches: [ "main" ] + paths: + - 'Cargo.toml' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Get package info from Cargo.toml + id: get-package-info + run: | + version=$(grep -m1 '^version = ' Cargo.toml | cut -d '"' -f2) + package_name=$(grep -m1 '^name = ' Cargo.toml | cut -d '"' -f2) + echo "version=${version}" >> $GITHUB_OUTPUT + echo "package_name=${package_name}" >> $GITHUB_OUTPUT + + - name: Check if version exists on crates.io + id: check-version + run: | + version="${{ steps.get-package-info.outputs.version }}" + package_name="${{ steps.get-package-info.outputs.package_name }}" + if cargo search "${package_name}" | grep -q "^${package_name} = \"${version}\""; then + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + + - name: Create release + if: steps.check-version.outputs.exists == 'false' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + version="${{ steps.get-package-info.outputs.version }}" + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + git tag -a "v${version}" -m "Release v${version}" + git push origin "v${version}" + + gh release create "v${version}" \ + --title "Release v${version}" \ + --generate-notes + + - name: Install Rust toolchain + if: steps.check-version.outputs.exists == 'false' + uses: dtolnay/rust-toolchain@stable + + - name: Rust cache + if: steps.check-version.outputs.exists == 'false' + uses: Swatinem/rust-cache@v2 + + - name: Publish to crates.io + if: steps.check-version.outputs.exists == 'false' + env: + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + run: cargo publish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..c5128cf --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +name: Test + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test (${{ matrix.os }}) + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + + - name: Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Build + run: cargo build --verbose + + - name: Run tests + run: cargo test --verbose diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index d643e57..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Test - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Build - run: cargo build --verbose - - name: Run tests - run: cargo test --verbose