name: Release
on:
push:
branches: [main, master]
paths-ignore:
- "**.md"
- ".github/**"
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
bump-version:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.release_flag.outputs.new_version }}
should_release: ${{ steps.release_flag.outputs.should_release }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get current version
id: current
run: |
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Check if version bump needed
id: check
run: |
# Check if last commit was a version bump or should be ignored
LAST_MSG=$(git log -1 --pretty=%B)
if [[ "$LAST_MSG" == *"[skip ci]"* ]] || [[ "$LAST_MSG" == *"chore: bump version"* ]] || [[ "$LAST_MSG" == *"ignore release"* ]]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "should_release=false" >> $GITHUB_OUTPUT
echo "Skipping release due to commit message"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Bump patch version
id: bump
if: steps.check.outputs.skip != 'true'
run: |
CURRENT="${{ steps.current.outputs.version }}"
IFS='.' read -ra PARTS <<< "$CURRENT"
MAJOR="${PARTS[0]}"
MINOR="${PARTS[1]}"
PATCH="${PARTS[2]}"
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH"
sed -i "s/^version = \"$CURRENT\"/version = \"$NEW_VERSION\"/" Cargo.toml
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
echo "Bumped version: $CURRENT -> $NEW_VERSION"
- name: Set release flag
id: release_flag
run: |
if [[ "${{ steps.check.outputs.skip }}" == "true" ]]; then
echo "should_release=false" >> $GITHUB_OUTPUT
else
echo "should_release=true" >> $GITHUB_OUTPUT
echo "new_version=${{ steps.bump.outputs.new_version }}" >> $GITHUB_OUTPUT
fi
- name: Commit version bump
if: steps.check.outputs.skip != 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Cargo.toml
git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }} [skip ci]"
git push
build:
needs: bump-version
if: needs.bump-version.outputs.should_release == 'true'
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: linux-x86_64
- target: x86_64-apple-darwin
os: macos-latest
name: macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
name: macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: windows-x86_64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Pull latest changes
run: git pull origin ${{ github.ref_name }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Build
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare artifact (Unix)
if: matrix.os != 'windows-latest'
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/nbi dist/nbi-${{ matrix.name }}
chmod +x dist/nbi-${{ matrix.name }}
- name: Prepare artifact (Windows)
if: matrix.os == 'windows-latest'
run: |
mkdir dist
copy target\${{ matrix.target }}\release\nbi.exe dist\nbi-${{ matrix.name }}.exe
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nbi-${{ matrix.name }}
path: dist/*
release:
needs: [bump-version, build]
if: needs.bump-version.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Pull latest changes
run: git pull origin ${{ github.ref_name }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare release assets
run: |
mkdir -p release
find artifacts -type f -exec cp {} release/ \;
ls -la release/
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.bump-version.outputs.new_version }}
name: Release v${{ needs.bump-version.outputs.new_version }}
body: |
## nbi v${{ needs.bump-version.outputs.new_version }}
### Downloads
- **Linux (x86_64)**: `nbi-linux-x86_64`
- **macOS (Intel)**: `nbi-macos-x86_64`
- **macOS (Apple Silicon)**: `nbi-macos-aarch64`
- **Windows**: `nbi-windows-x86_64.exe`
### Installation
```bash
# Linux/macOS
chmod +x nbi-*
sudo mv nbi-* /usr/local/bin/nbi
# Or via cargo
cargo install --git https://github.com/${{ github.repository }}
```
files: release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}