Skip to content

feat: --output json on all commands + unlost ingest for markdown docs… #40

feat: --output json on all commands + unlost ingest for markdown docs…

feat: --output json on all commands + unlost ingest for markdown docs… #40

Workflow file for this run

name: release-crates
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
dry_run:
description: 'Run cargo publish --dry-run only'
required: true
default: 'true'
jobs:
build-binaries:
name: build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: aarch64-pc-windows-msvc
- os: macos-latest
target: aarch64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install protoc (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install protoc (macOS)
if: runner.os == 'macOS'
run: |
brew update
brew install protobuf
- name: Install protoc (Windows)
if: runner.os == 'Windows'
run: choco install -y protoc
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Rust
uses: Swatinem/rust-cache@v2
- name: Build (release)
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Collect binary + sha256 (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
DIST="dist"
mkdir -p "$DIST"
SRC="target/${{ matrix.target }}/release/unlost"
OUT_BASENAME="unlost-${{ matrix.target }}"
OUT="$DIST/$OUT_BASENAME"
cp "$SRC" "$OUT"
chmod +x "$OUT" || true
(cd "$DIST" && {
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "$OUT_BASENAME" > "${OUT_BASENAME}.sha256"
else
shasum -a 256 "$OUT_BASENAME" > "${OUT_BASENAME}.sha256"
fi
})
working-directory: ${{ github.workspace }}
- name: Collect binary + sha256 (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$dist = 'dist'
New-Item -ItemType Directory -Force -Path $dist | Out-Null
$src = Join-Path "target\${{ matrix.target }}\release" 'unlost.exe'
$out = Join-Path $dist ("unlost-${{ matrix.target }}.exe")
Copy-Item -Path $src -Destination $out -Force
$hash = (Get-FileHash -Algorithm SHA256 -Path $out).Hash.ToLower()
"$hash $(Split-Path -Leaf $out)" | Out-File -FilePath "${out}.sha256" -Encoding ascii
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: unlost-${{ matrix.target }}
path: dist/*
publish-crate:
runs-on: ubuntu-latest
needs: build-binaries
environment: release
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust
uses: Swatinem/rust-cache@v2
- name: Ensure Cargo.toml has license
run: |
python - <<'PY'
import tomllib
with open('Cargo.toml','rb') as f:
data = tomllib.load(f)
pkg = data.get('package', {})
if 'license' not in pkg and 'license-file' not in pkg:
raise SystemExit('Cargo.toml missing [package].license or [package].license-file (required for crates.io publish)')
print('ok')
PY
- name: Publish (dry-run)
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked --dry-run
- name: Publish to crates.io
if: github.event_name == 'push'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked
- name: Publish to crates.io
if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run != 'true'
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked
github-release:
runs-on: ubuntu-latest
if: github.event_name == 'push'
needs: [build-binaries, publish-crate]
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Build release notes from CHANGELOG
id: notes
shell: bash
run: |
set -euo pipefail
TAG='${{ github.ref_name }}'
VER="${TAG#v}"
export VER
python3 - <<'PY' > release_notes.md
import os
ver = os.environ["VER"]
path = 'CHANGELOG.md'
with open(path, 'r', encoding='utf-8') as f:
lines = f.read().splitlines()
header = f"## [{ver}]"
start = None
for i, line in enumerate(lines):
if line.startswith(header):
start = i
break
if start is None:
raise SystemExit(f"Could not find changelog section for {header}")
out = []
for line in lines[start:]:
if line.startswith('## [') and not line.startswith(header):
break
out.append(line)
# Drop the header line itself (we'll use a nicer title in the GH release)
out = out[1:]
while out and out[0].strip() == '':
out.pop(0)
print(f"## What's changed\n")
print("\n".join(out).rstrip() + "\n")
PY
{
echo 'body<<EOF'
cat release_notes.md
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Create GitHub release and upload assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: unlost ${{ github.ref_name }}
body: ${{ steps.notes.outputs.body }}
files: dist/**