name: pub.dev Release
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v0.3.1)"
required: true
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
PUB_PACKAGE_NAME: onde_cli
ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
GRESIQ_API_SECRET: ${{ secrets.GRESIQ_API_SECRET }}
HF_TOKEN: ${{ secrets.HF_TOKEN }}
jobs:
build-native-binaries:
name: Build native binary (${{ matrix.build.NAME }})
runs-on: ${{ matrix.build.OS }}
strategy:
fail-fast: false
matrix:
build:
- {
NAME: linux-x64,
OS: ubuntu-latest,
TARGET: x86_64-unknown-linux-gnu,
}
- {
NAME: linux-arm64,
OS: ubuntu-24.04-arm,
TARGET: aarch64-unknown-linux-gnu,
}
- {
NAME: windows-x64,
OS: windows-2022,
TARGET: x86_64-pc-windows-msvc,
}
- {
NAME: windows-arm64,
OS: windows-2022,
TARGET: aarch64-pc-windows-msvc,
}
- {
NAME: darwin-x64,
OS: macos-26-intel,
TARGET: x86_64-apple-darwin,
}
- { NAME: darwin-arm64, OS: macos-26, TARGET: aarch64-apple-darwin }
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Read Rust toolchain
shell: bash
run: |
rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
if [ -z "$rust_toolchain" ]; then
echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
exit 1
fi
echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
targets: ${{ matrix.build.TARGET }}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: pub-${{ matrix.build.TARGET }}
- name: Build binary
shell: bash
run: cargo build --locked --release --target ${{ matrix.build.TARGET }}
- name: Prepare artifact
shell: bash
run: |
executable_name="onde"
if [[ "${{ matrix.build.OS }}" == "windows-2022" ]]; then
executable_name="onde.exe"
fi
mkdir -p "pub-artifacts/native/${{ matrix.build.NAME }}"
cp "target/${{ matrix.build.TARGET }}/release/${executable_name}" "pub-artifacts/native/${{ matrix.build.NAME }}/${executable_name}"
- name: Upload native artifact
uses: actions/upload-artifact@v4
with:
name: pub-native-${{ matrix.build.NAME }}
path: pub-artifacts/native
verify-package:
name: Verify Dart package
runs-on: ubuntu-latest
needs: build-native-binaries
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Set the release version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_version="${GITHUB_REF_NAME#v}"
else
release_version="${{ github.event.inputs.tag }}"
release_version="${release_version#v}"
fi
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
- name: Download native artifacts
uses: actions/download-artifact@v4
with:
pattern: pub-native-*
path: pub/onde_cli/native
merge-multiple: true
- name: Stage generated native binaries
shell: bash
run: git add -f pub/onde_cli/native
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
- name: Sync package version
shell: bash
run: |
python3 - <<'PY'
from pathlib import Path
import os
release_version = os.environ['RELEASE_VERSION']
pubspec = Path('pub/onde_cli/pubspec.yaml')
lines = pubspec.read_text().splitlines()
for index, line in enumerate(lines):
if line.startswith('version: '):
lines[index] = f'version: {release_version}'
pubspec.write_text('\n'.join(lines) + '\n')
PY
- name: Get package dependencies
working-directory: pub/onde_cli
run: dart pub get
- name: Analyze Dart package
working-directory: pub/onde_cli
run: dart analyze
- name: Dry-run publish
working-directory: pub/onde_cli
run: dart pub publish --dry-run
publish-pub:
name: Publish to pub.dev
runs-on: ubuntu-latest
needs: verify-package
steps:
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.tag || github.ref }}
- name: Set the release version
shell: bash
run: |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
release_version="${GITHUB_REF_NAME#v}"
else
release_version="${{ github.event.inputs.tag }}"
release_version="${release_version#v}"
fi
echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
- name: Download native artifacts
uses: actions/download-artifact@v4
with:
pattern: pub-native-*
path: pub/onde_cli/native
merge-multiple: true
- name: Stage generated native binaries
shell: bash
run: git add -f pub/onde_cli/native
- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1
- name: Sync package version
shell: bash
run: |
python3 - <<'PY'
from pathlib import Path
import os
release_version = os.environ['RELEASE_VERSION']
pubspec = Path('pub/onde_cli/pubspec.yaml')
lines = pubspec.read_text().splitlines()
for index, line in enumerate(lines):
if line.startswith('version: '):
lines[index] = f'version: {release_version}'
pubspec.write_text('\n'.join(lines) + '\n')
PY
- name: Check whether release already exists on pub.dev
id: pub-check
shell: bash
run: |
package_url="https://pub.dev/api/packages/${PUB_PACKAGE_NAME}"
if curl -fsS "${package_url}" | grep -F '"version":"'"${RELEASE_VERSION}"'"' >/dev/null; then
echo "${PUB_PACKAGE_NAME} ${RELEASE_VERSION} already exists on pub.dev, skipping publish"
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Set up pub.dev credentials
if: steps.pub-check.outputs.exists != 'true'
shell: bash
run: |
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/dart"
echo '${{ secrets.PUB_CREDENTIALS }}' > "${XDG_CONFIG_HOME:-$HOME/.config}/dart/pub-credentials.json"
- name: Publish package
if: steps.pub-check.outputs.exists != 'true'
working-directory: pub/onde_cli
run: dart pub publish --force