name: Release
on:
push:
tags:
- "v*.*.*"
jobs:
build:
name: Build - ${{ matrix.platform.release_for }}
runs-on: ${{ matrix.platform.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install libasound2-dev (Linux only)
if: matrix.platform.os == 'ubuntu-24.04'
run: |
sudo apt-get update
sudo apt-get install -y libasound2-dev libpipewire-0.3-dev pipewire-bin libclang-dev build-essential pkg-config libudev-dev
- name: Update Rust stable
run: rustup toolchain install stable
- name: Prepare Cargo.lock for caching (ignore code-smore version)
run: |
PROJECT_NAME=$(grep '^name' Cargo.toml | sed 's/name = "\(.*\)"/\1/')
awk '/\[\[package\]\]/{p=0} /name = "'"${PROJECT_NAME}"'"/{p=1} p && /version = /{next} 1' Cargo.lock > Cargo.lock.no-version
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock.no-version') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Get version from cargo.toml
uses: SebRollen/toml-action@v1.2.0
id: cargo_version
with:
file: 'Cargo.toml'
field: 'package.version'
- name: Get the tag of current release
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> ${GITHUB_OUTPUT}
- name: Verify package version is equal to tag version
if: ${{ steps.cargo_version.outputs.value != steps.get_version.outputs.VERSION }}
run: |
echo "${{ steps.cargo_version.outputs.value }}"
echo "${{ steps.get_version.outputs.VERSION }}"
exit 1
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: ${{ matrix.platform.command }}
target: ${{ matrix.platform.target }}
args: "--bin ${{ matrix.platform.bin }} --locked --release ${{ matrix.platform.features }}"
strip: true
- name: Move binary path
run: |
if [[ "${{ matrix.platform.target }}" == *"-windows-"* ]]; then
mv target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.exe .
else
mv target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} .
fi
- name: Package as archive
run: |
if [[ "${{ matrix.platform.target }}" == *"-windows-"* ]]; then
zip ${{ matrix.platform.bin }}-v${{ steps.cargo_version.outputs.value }}-${{ matrix.platform.name }}.zip \
${{ matrix.platform.bin }}.exe
else
tar czvf ${{ matrix.platform.bin }}-v${{ steps.cargo_version.outputs.value }}-${{ matrix.platform.name }}.tar.gz \
${{ matrix.platform.bin }}
fi
- name: Upload Linux artifacts
if: matrix.platform.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.bin }}-v${{ steps.cargo_version.outputs.value }}-${{ matrix.platform.name }}.tar.gz
path: ${{ matrix.platform.bin }}-v${{ steps.cargo_version.outputs.value }}-${{ matrix.platform.name }}.tar.gz
- name: Upload Windows artifacts
if: matrix.platform.target == 'x86_64-pc-windows-gnu'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.bin }}-v${{ steps.cargo_version.outputs.value }}-${{ matrix.platform.name }}.zip
path: ${{ matrix.platform.bin }}-v${{ steps.cargo_version.outputs.value }}-${{ matrix.platform.name }}.zip
strategy:
matrix:
platform:
- release_for: Linux-x86_64
os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
bin: code-smore
name: Linux-x86_64
command: build
features: ""
- release_for: Windows-x86_64
os: ubuntu-24.04
target: x86_64-pc-windows-gnu
bin: code-smore
name: Windows-x86_64
command: build
features: "--no-default-features"
release:
name: Release - ${{ matrix.platform.release_for }}
needs: build
runs-on: ubuntu-24.04
steps:
- uses: actions/download-artifact@v4
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
with:
files: |
code-smore-v*.*/code-smore-v*.*
publish:
name: Publish crate
needs: release
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Update Rust stable
run: rustup toolchain install stable
- name: Prepare Cargo.lock for caching (ignore code-smore version)
run: |
PROJECT_NAME=$(grep '^name' Cargo.toml | sed 's/name = "\(.*\)"/\1/')
awk '/\[\[package\]\]/{p=0} /name = "'"${PROJECT_NAME}"'"/{p=1} p && /version = /{next} 1' Cargo.lock > /tmp/Cargo.lock.no-version
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('/tmp/Cargo.lock.no-version') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Install deps
run: |
sudo apt-get update
sudo apt-get install -y libasound2-dev libpipewire-0.3-dev pipewire-bin libclang-dev build-essential pkg-config libudev-dev
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --token $CARGO_REGISTRY_TOKEN