name: CI
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
env:
CARGO_TERM_COLOR: always
jobs:
check:
name: Check (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v5
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@v2
- name: Check formatting
run: cargo fmt --check
- name: Clippy
run: cargo clippy -- -D warnings -A dead_code -A clippy::too_many_arguments -A clippy::manual_map -A clippy::manual_is_multiple_of
- name: Run tests
env:
AI_MEMORY_NO_CONFIG: "1"
run: cargo test
- name: Build release
run: cargo build --release
release:
name: Release (${{ matrix.target }})
needs: check
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact: ai-memory
nfpm_arch: amd64
- target: aarch64-unknown-linux-gnu
os: ubuntu-24.04-arm
artifact: ai-memory
nfpm_arch: arm64
- target: x86_64-apple-darwin
os: macos-latest
artifact: ai-memory
- target: aarch64-apple-darwin
os: macos-latest
artifact: ai-memory
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact: ai-memory.exe
steps:
- uses: actions/checkout@v5
- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- name: Build release binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package binary (unix)
if: ${{ !contains(matrix.target, 'windows') }}
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/${{ matrix.artifact }} dist/
cd dist
tar czf ai-memory-${{ matrix.target }}.tar.gz ${{ matrix.artifact }}
- name: Package binary (windows)
if: contains(matrix.target, 'windows')
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path dist
Copy-Item "target/${{ matrix.target }}/release/${{ matrix.artifact }}" -Destination dist/
Compress-Archive -Path "dist/${{ matrix.artifact }}" -DestinationPath "dist/ai-memory-${{ matrix.target }}.zip"
- name: Build deb and rpm packages
if: matrix.nfpm_arch
run: |
# Install nfpm (map aarch64 -> arm64 for nfpm release naming)
NFPM_ARCH=$(uname -m | sed 's/aarch64/arm64/')
curl -sfL https://github.com/goreleaser/nfpm/releases/download/v2.41.1/nfpm_2.41.1_$(uname -s)_${NFPM_ARCH}.tar.gz | tar xz -C /usr/local/bin nfpm
VERSION="${GITHUB_REF_NAME#v}"
# Build .deb
ARCH=${{ matrix.nfpm_arch }} VERSION=$VERSION nfpm package -p deb -f nfpm.yaml -t dist/
# Build .rpm
ARCH=${{ matrix.nfpm_arch }} VERSION=$VERSION nfpm package -p rpm -f nfpm.yaml -t dist/
ls -la dist/*.deb dist/*.rpm
- name: Upload release artifact
uses: actions/upload-artifact@v5
with:
name: ai-memory-${{ matrix.target }}
path: dist/ai-memory*
- name: Create GitHub Release
if: github.event_name == 'push'
uses: softprops/action-gh-release@v2
with:
files: dist/ai-memory*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
name: Docker (GHCR)
needs: check
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version from tag
id: version
run: echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/ai-memory:${{ steps.version.outputs.version }}
ghcr.io/${{ github.repository_owner }}/ai-memory:latest
labels: |
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.version=${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max