name: Uringy Macros CI/CD
on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- macros/**
jobs:
unit_test:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
key: macros-unit-test
- name: Unit test
run: cargo test --package uringy-macros
deploy_to_crates_io:
needs:
- unit_test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Determine whether current version is already deployed
run: |
cargo install cargo-get
CRATE_VERSION=$(cargo get package.version | tr -d '\n')
VERSION_EXISTS=$(curl -s https://crates.io/api/v1/crates/uringy-macros | jq '.versions | map(.num) | contains(["'$CRATE_VERSION'"])')
echo "VERSION_EXISTS=$VERSION_EXISTS" >> $GITHUB_OUTPUT
id: whether-deployed
working-directory: macros
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
key: macros-deploy-to-crates-io
if: ${{ steps.whether-deployed.outputs.VERSION_EXISTS == 'false' }}
- name: Login to crates.io
run: cargo login ${{ secrets.CRATES_IO_ACCESS_TOKEN }}
if: ${{ steps.whether-deployed.outputs.VERSION_EXISTS == 'false' }}
- name: Publish to crates.io
run: cargo publish
if: ${{ steps.whether-deployed.outputs.VERSION_EXISTS == 'false' }}
working-directory: macros