name: Rust
on:
push:
branches:
- '*'
release:
types:
- published
env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt,clippy
- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --verbose
- name: Run clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose
- uses: actions/upload-artifact@v2
with:
name: workspace
path: '.'
deploy:
runs-on: ubuntu-20.04
needs: [ build ]
if: ${{ github.event_name == 'release' }}
steps:
- uses: actions/download-artifact@v2
with:
name: workspace
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt,clippy
- name: Install cargo-edit-version
uses: actions-rs/cargo@v1
with:
command: install
args: --verbose cargo-edit-version
- name: Set version by the release tag
run: cargo-edit-version ${{ github.event.release.tag_name }}
- name: Log into crates.io
uses: actions-rs/cargo@v1
with:
command: login
args: ${{ secrets.CRATES_IO_TOKEN }}
- name: Publish to crates.io
uses: actions-rs/cargo@v1
with:
command: publish
args: --verbose