name: Release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-13 - target: aarch64-apple-darwin
os: macos-latest - target: x86_64-pc-windows-msvc
os: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build binary
run: cargo build --release --target ${{ matrix.target }}
- name: Package binary (Unix)
if: runner.os != 'Windows'
run: |
binary_name="directory-indexer"
binary_path="target/${{ matrix.target }}/release/$binary_name"
# Create archive
case "${{ matrix.target }}" in
x86_64-unknown-linux-gnu)
archive_name="directory-indexer-linux-x64"
;;
x86_64-apple-darwin)
archive_name="directory-indexer-darwin-x64"
;;
aarch64-apple-darwin)
archive_name="directory-indexer-darwin-arm64"
;;
esac
mkdir -p dist
cp "$binary_path" "dist/$archive_name"
chmod +x "dist/$archive_name"
# Create tarball for GitHub release
tar -czf "dist/$archive_name.tar.gz" -C dist "$archive_name"
- name: Package binary (Windows)
if: runner.os == 'Windows'
run: |
$binary_name = "directory-indexer.exe"
$binary_path = "target/${{ matrix.target }}/release/$binary_name"
$archive_name = "directory-indexer.exe-win32-x64"
New-Item -ItemType Directory -Force -Path dist
Copy-Item $binary_path "dist/$archive_name"
# Create zip for GitHub release
Compress-Archive -Path "dist/$archive_name" -DestinationPath "dist/directory-indexer-windows-x64.zip"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.target }}
path: dist/
retention-days: 1
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build
permissions:
contents: write
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
merge-multiple: true
- name: Get version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Create Release
id: release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
name: Release v${{ steps.version.outputs.VERSION }}
generateReleaseNotes: true
artifacts: "artifacts/*.tar.gz,artifacts/*.zip"
draft: false
prerelease: false
publish-crates:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Verify Cargo.toml
run: cargo check
- name: Publish to crates.io
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
publish-npm:
name: Publish to npm
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts/
- name: Organize binaries for npm
run: |
mkdir -p binaries
# Copy binaries to expected locations for postinstall.js
cp artifacts/binary-x86_64-unknown-linux-gnu/directory-indexer-linux-x64 binaries/
cp artifacts/binary-x86_64-apple-darwin/directory-indexer-darwin-x64 binaries/
cp artifacts/binary-aarch64-apple-darwin/directory-indexer-darwin-arm64 binaries/
cp artifacts/binary-x86_64-pc-windows-msvc/directory-indexer.exe-win32-x64 binaries/
# Ensure Unix binaries are executable
chmod +x binaries/directory-indexer-linux-x64
chmod +x binaries/directory-indexer-darwin-x64
chmod +x binaries/directory-indexer-darwin-arm64
ls -la binaries/
- name: Install dependencies
run: npm ci
- name: Verify package contents
run: npm pack --dry-run
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}