name: Smart Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
env:
CARGO_TERM_COLOR: always
jobs:
validate-and-publish:
name: Validate and Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Extract version from tag
id: extract_version
run: |
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v}
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Tag: $TAG, Version: $VERSION"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Update Cargo.toml version
run: |
# Update the version in Cargo.toml
cargo set-version ${{ steps.extract_version.outputs.version }}
# Show the change
git diff
- name: Run tests
run: cargo test --all-features
- name: Publish to crates.io
run: |
# The version has been updated in Cargo.toml by cargo-edit
cargo publish --all-features --allow-dirty --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
build-artifacts:
name: Build Release Artifacts
runs-on: ubuntu-latest
needs: validate-and-publish
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
artifact_name: talos-rust-client-linux-amd64
- target: x86_64-unknown-linux-musl
artifact_name: talos-rust-client-linux-musl-amd64
- target: aarch64-unknown-linux-gnu
artifact_name: talos-rust-client-linux-arm64
steps:
- uses: actions/checkout@v5
with:
submodules: recursive
- name: Extract version from tag
id: extract_version
run: |
TAG=${GITHUB_REF#refs/tags/}
echo "tag=$TAG" >> $GITHUB_OUTPUT
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools
run: |
if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then
sudo apt-get update && sudo apt-get install -y musl-tools
elif [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu
fi
- name: Install cargo-edit
run: cargo install cargo-edit
- name: Update version to match tag
run: |
VERSION=${GITHUB_REF#refs/tags/v}
cargo set-version $VERSION
- name: Build examples
run: cargo build --release --all-features --target ${{ matrix.target }} --examples
- name: Package artifacts
run: |
mkdir -p artifacts
# Copy examples
cp target/${{ matrix.target }}/release/examples/version artifacts/ || true
cp target/${{ matrix.target }}/release/examples/health artifacts/ || true
cp target/${{ matrix.target }}/release/examples/events artifacts/ || true
cp target/${{ matrix.target }}/release/examples/talosconfig_connect artifacts/ || true
# Add README and LICENSE files
cp README.md artifacts/
cp LICENSE-* artifacts/
# Create archive
cd artifacts
tar czf ../${{ matrix.artifact_name }}.tar.gz *
- name: Upload Release Asset
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.extract_version.outputs.tag }}
files: ${{ matrix.artifact_name }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}