name: Rust SDK Release
on:
push:
branches: [main]
workflow_dispatch:
permissions: {}
concurrency:
group: rust-release-${{ github.ref }}
cancel-in-progress: false
jobs:
test:
if: "!startsWith(github.event.head_commit.message, 'chore: release')"
runs-on: ubuntu-latest
permissions:
contents: read
env:
MUXI_SDK_E2E_SERVER_URL: ${{ secrets.MUXI_SDK_E2E_SERVER_URL }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
fetch-depth: 0
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Unit tests
run: cargo test --verbose
- name: Require test server
run: |
if [ -z "$MUXI_SDK_E2E_SERVER_URL" ]; then
echo "::error::MUXI_SDK_E2E_SERVER_URL secret is not set"
exit 1
fi
if ! curl -sf --max-time 10 "${MUXI_SDK_E2E_SERVER_URL}/ping" >/dev/null 2>&1 && \
! curl -sf --max-time 10 "${MUXI_SDK_E2E_SERVER_URL}" >/dev/null 2>&1; then
echo "::error::Test server is not reachable at ${MUXI_SDK_E2E_SERVER_URL}"
exit 1
fi
- name: Integration tests
env:
MUXI_SDK_E2E_KEY_ID: ${{ secrets.MUXI_SDK_E2E_KEY_ID }}
MUXI_SDK_E2E_SECRET_KEY: ${{ secrets.MUXI_SDK_E2E_SECRET_KEY }}
MUXI_SDK_E2E_FORMATION_ID: ${{ secrets.MUXI_SDK_E2E_FORMATION_ID }}
MUXI_SDK_E2E_CLIENT_KEY: ${{ secrets.MUXI_SDK_E2E_CLIENT_KEY }}
MUXI_SDK_E2E_ADMIN_KEY: ${{ secrets.MUXI_SDK_E2E_ADMIN_KEY }}
run: cargo test --test integration_test -- --test-threads=1
release:
if: "!startsWith(github.event.head_commit.message, 'chore: release')"
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
fetch-depth: 0
token: ${{ secrets.MUXI_RELEASE_TOKEN }}
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Compute next version
id: version
run: |
current=$(grep '^version = ' Cargo.toml | head -1 | sed 's/.*"\([^"]*\)".*/\1/')
major=$(echo "$current" | cut -d. -f1)
cdate=$(echo "$current" | cut -d. -f2)
cpatch=$(echo "$current" | cut -d. -f3)
today=$(date -u +%Y%m%d)
if [ "$cdate" = "$today" ]; then
nextpatch=$((cpatch + 1))
else
nextpatch=0
fi
next="${major}.${today}.${nextpatch}"
echo "version=$next" >> $GITHUB_OUTPUT
- name: Set version in source
run: |
sed -i "0,/^version = .*/s//version = \"${{ steps.version.outputs.version }}\"/" Cargo.toml
sed -i 's/VERSION: &str = ".*"/VERSION: \&str = "${{ steps.version.outputs.version }}"/' src/version.rs
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.MUXI_SDK_CARGO_REGISTRY_TOKEN }}
run: cargo publish --allow-dirty
- name: Commit version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml src/version.rs
git commit -m "chore: release v${{ steps.version.outputs.version }}"
git push origin HEAD:main
- name: Create and push tag
run: |
TAG="v${{ steps.version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists"
else
git tag "$TAG"
git push origin "$TAG"
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844 with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
body: |
Rust SDK v${{ steps.version.outputs.version }}
Add to Cargo.toml:
```toml
[dependencies]
muxi-rust = "${{ steps.version.outputs.version }}"
```
sync_develop:
if: "!startsWith(github.event.head_commit.message, 'chore: release')"
needs: release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd with:
ref: develop
fetch-depth: 0
token: ${{ secrets.MUXI_RELEASE_TOKEN }}
- name: Merge main into develop
run: |
git fetch origin main develop
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git merge origin/main --no-edit -m "chore: sync main to develop [skip ci]"
git push origin HEAD:develop