Skip to content

Commit

Permalink
Run tests on all platforms, and add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Nov 14, 2024
1 parent 47a383a commit 22540f3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 20 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
20 changes: 0 additions & 20 deletions .github/workflows/tests.yml

This file was deleted.

0 comments on commit 22540f3

Please sign in to comment.