name: Publish Crate
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
publish_to:
description: 'Publish destination'
required: true
default: 'crates.io'
type: choice
options:
- crates.io
- stevedores
- both
env:
CARGO_TERM_COLOR: always
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-action@stable
- name: Cache cargo
uses: Swatinem/rust-cache@v2
- name: Run tests
run: cargo test --all-features
- name: Run clippy
run: cargo clippy -- -D warnings
publish-crates-io:
needs: test
runs-on: ubuntu-latest
if: |
github.event_name == 'push' ||
github.event.inputs.publish_to == 'crates.io' ||
github.event.inputs.publish_to == 'both'
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-action@stable
- name: Publish to crates.io
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish-stevedores:
needs: test
runs-on: ubuntu-latest
if: |
github.event.inputs.publish_to == 'stevedores' ||
github.event.inputs.publish_to == 'both'
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-action@stable
- name: Configure private registry
run: |
mkdir -p ~/.cargo
cat >> ~/.cargo/config.toml << 'EOF'
[registries.stevedores]
index = "sparse+https://crates.stevedores.org/index/"
token = "${{ secrets.STEVEDORES_REGISTRY_TOKEN }}"
EOF
- name: Publish to stevedores registry
run: cargo publish --registry stevedores
build-binaries:
needs: test
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact: oxidizedgraph-linux-amd64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact: oxidizedgraph-linux-arm64
- os: macos-latest
target: x86_64-apple-darwin
artifact: oxidizedgraph-darwin-amd64
- os: macos-latest
target: aarch64-apple-darwin
artifact: oxidizedgraph-darwin-arm64
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact: oxidizedgraph-windows-amd64.exe
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-action@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: |
target/${{ matrix.target }}/release/oxidizedgraph
target/${{ matrix.target }}/release/oxidizedgraph.exe
release:
needs: build-binaries
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: |
oxidizedgraph-linux-amd64/*
oxidizedgraph-linux-arm64/*
oxidizedgraph-darwin-amd64/*
oxidizedgraph-darwin-arm64/*
oxidizedgraph-windows-amd64.exe/*
generate_release_notes: true