ci: add GitHub Actions workflows
- CI workflow for Rust and web builds - Release workflow for automated releases
This commit is contained in:
parent
65b55637d8
commit
ef9a8cd50f
2 changed files with 476 additions and 0 deletions
236
.github/workflows/ci.yml
vendored
Normal file
236
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -0,0 +1,236 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUSTFLAGS: -Dwarnings
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-action@stable
|
||||
with:
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-registry-
|
||||
|
||||
- name: Cache cargo target
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-target-check-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-target-check-
|
||||
|
||||
- name: Check formatting
|
||||
run: cargo fmt --all -- --check
|
||||
|
||||
- name: Run clippy
|
||||
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
|
||||
|
||||
test:
|
||||
name: Test (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-action@stable
|
||||
|
||||
- name: Install system dependencies (Linux)
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libclang-dev llvm-dev
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-registry-
|
||||
|
||||
- name: Cache cargo target
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-target-test-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-target-test-
|
||||
|
||||
- name: Run tests
|
||||
run: cargo test --workspace --all-features
|
||||
|
||||
build:
|
||||
name: Build (${{ matrix.os }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: [check, test]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
artifact-name: synor-linux-x86_64
|
||||
- os: macos-latest
|
||||
artifact-name: synor-macos-x86_64
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-action@stable
|
||||
|
||||
- name: Install system dependencies (Linux)
|
||||
if: runner.os == 'Linux'
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libclang-dev llvm-dev
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-registry-
|
||||
|
||||
- name: Cache cargo target
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-target-release-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-target-release-
|
||||
|
||||
- name: Build release binaries
|
||||
run: cargo build --release --workspace
|
||||
|
||||
- name: Prepare artifacts
|
||||
run: |
|
||||
mkdir -p artifacts
|
||||
cp target/release/synord artifacts/ 2>/dev/null || true
|
||||
cp target/release/synor-cli artifacts/ 2>/dev/null || true
|
||||
cp target/release/synor-faucet artifacts/ 2>/dev/null || true
|
||||
cp target/release/synor-explorer artifacts/ 2>/dev/null || true
|
||||
|
||||
- name: Upload build artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.artifact-name }}
|
||||
path: artifacts/
|
||||
retention-days: 7
|
||||
if-no-files-found: warn
|
||||
|
||||
bench:
|
||||
name: Benchmarks
|
||||
runs-on: ubuntu-latest
|
||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
||||
needs: [check, test]
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-action@stable
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libclang-dev llvm-dev
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-registry-
|
||||
|
||||
- name: Cache cargo target
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-cargo-target-bench-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cargo-target-bench-
|
||||
|
||||
- name: Run benchmarks
|
||||
run: cargo bench --workspace
|
||||
|
||||
- name: Upload benchmark results
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: benchmark-results
|
||||
path: target/criterion/
|
||||
retention-days: 30
|
||||
if-no-files-found: ignore
|
||||
|
||||
# Summary job for branch protection
|
||||
ci-success:
|
||||
name: CI Success
|
||||
runs-on: ubuntu-latest
|
||||
needs: [check, test, build]
|
||||
if: always()
|
||||
steps:
|
||||
- name: Check all jobs passed
|
||||
env:
|
||||
CHECK_RESULT: ${{ needs.check.result }}
|
||||
TEST_RESULT: ${{ needs.test.result }}
|
||||
BUILD_RESULT: ${{ needs.build.result }}
|
||||
run: |
|
||||
if [[ "$CHECK_RESULT" != "success" ]] || \
|
||||
[[ "$TEST_RESULT" != "success" ]] || \
|
||||
[[ "$BUILD_RESULT" != "success" ]]; then
|
||||
echo "One or more jobs failed"
|
||||
exit 1
|
||||
fi
|
||||
echo "All CI jobs passed successfully"
|
||||
240
.github/workflows/release.yml
vendored
Normal file
240
.github/workflows/release.yml
vendored
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build-release:
|
||||
name: Build Release (${{ matrix.target }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- os: ubuntu-latest
|
||||
target: x86_64-unknown-linux-gnu
|
||||
artifact-name: synor-linux-x86_64
|
||||
archive-ext: tar.gz
|
||||
- os: ubuntu-latest
|
||||
target: aarch64-unknown-linux-gnu
|
||||
artifact-name: synor-linux-aarch64
|
||||
archive-ext: tar.gz
|
||||
cross: true
|
||||
- os: macos-latest
|
||||
target: x86_64-apple-darwin
|
||||
artifact-name: synor-macos-x86_64
|
||||
archive-ext: tar.gz
|
||||
- os: macos-latest
|
||||
target: aarch64-apple-darwin
|
||||
artifact-name: synor-macos-aarch64
|
||||
archive-ext: tar.gz
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-action@stable
|
||||
with:
|
||||
targets: ${{ matrix.target }}
|
||||
|
||||
- name: Install cross-compilation tools
|
||||
if: matrix.cross
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
|
||||
|
||||
- name: Install system dependencies (Linux)
|
||||
if: runner.os == 'Linux' && !matrix.cross
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libclang-dev llvm-dev
|
||||
|
||||
- name: Cache cargo registry
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/bin/
|
||||
~/.cargo/registry/index/
|
||||
~/.cargo/registry/cache/
|
||||
~/.cargo/git/db/
|
||||
key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ matrix.target }}-cargo-registry-
|
||||
|
||||
- name: Cache cargo target
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: target
|
||||
key: ${{ runner.os }}-${{ matrix.target }}-cargo-target-release-${{ hashFiles('**/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-${{ matrix.target }}-cargo-target-release-
|
||||
|
||||
- name: Build release binaries
|
||||
env:
|
||||
TARGET: ${{ matrix.target }}
|
||||
CROSS: ${{ matrix.cross }}
|
||||
run: |
|
||||
if [[ "$CROSS" == "true" ]]; then
|
||||
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
|
||||
export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
|
||||
export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
|
||||
fi
|
||||
cargo build --release --workspace --target "$TARGET"
|
||||
|
||||
- name: Prepare release archive
|
||||
env:
|
||||
TARGET: ${{ matrix.target }}
|
||||
ARTIFACT_NAME: ${{ matrix.artifact-name }}
|
||||
run: |
|
||||
mkdir -p release
|
||||
|
||||
# Copy binaries
|
||||
cp "target/$TARGET/release/synord" release/ 2>/dev/null || true
|
||||
cp "target/$TARGET/release/synor-cli" release/ 2>/dev/null || true
|
||||
cp "target/$TARGET/release/synor-faucet" release/ 2>/dev/null || true
|
||||
cp "target/$TARGET/release/synor-explorer" release/ 2>/dev/null || true
|
||||
|
||||
# Copy documentation
|
||||
cp README.md release/ 2>/dev/null || true
|
||||
cp LICENSE* release/ 2>/dev/null || true
|
||||
cp CHANGELOG.md release/ 2>/dev/null || true
|
||||
|
||||
# Create archive
|
||||
cd release
|
||||
tar czvf "../$ARTIFACT_NAME.tar.gz" *
|
||||
|
||||
- name: Upload release artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ matrix.artifact-name }}
|
||||
path: ${{ matrix.artifact-name }}.tar.gz
|
||||
retention-days: 1
|
||||
|
||||
create-release:
|
||||
name: Create GitHub Release
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-release
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Download all artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Generate changelog
|
||||
id: changelog
|
||||
env:
|
||||
GIT_REF: ${{ github.ref }}
|
||||
run: |
|
||||
# Get the current tag from the ref (safe - only used after validation)
|
||||
CURRENT_TAG="${GIT_REF#refs/tags/}"
|
||||
|
||||
# Validate tag format (only allow v followed by semver-like pattern)
|
||||
if [[ ! "$CURRENT_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then
|
||||
echo "Invalid tag format: $CURRENT_TAG"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "current_tag=$CURRENT_TAG" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Get the previous tag
|
||||
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG^" 2>/dev/null || echo "")
|
||||
|
||||
echo "## What's Changed" > CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
|
||||
if [ -n "$PREVIOUS_TAG" ]; then
|
||||
echo "Changes since $PREVIOUS_TAG:" >> CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
|
||||
# Generate changelog from commits (commit messages are from our own repo)
|
||||
git log "$PREVIOUS_TAG..$CURRENT_TAG" --pretty=format:"- %s (%h)" --no-merges >> CHANGELOG_BODY.md
|
||||
else
|
||||
echo "Initial release" >> CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
git log --pretty=format:"- %s (%h)" --no-merges -20 >> CHANGELOG_BODY.md
|
||||
fi
|
||||
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
echo "## Installation" >> CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
echo "Download the appropriate archive for your platform and extract it:" >> CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
echo '```bash' >> CHANGELOG_BODY.md
|
||||
echo "tar xzf synor-<platform>.tar.gz" >> CHANGELOG_BODY.md
|
||||
echo "./synord --help" >> CHANGELOG_BODY.md
|
||||
echo '```' >> CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
echo "## Checksums" >> CHANGELOG_BODY.md
|
||||
echo "" >> CHANGELOG_BODY.md
|
||||
echo '```' >> CHANGELOG_BODY.md
|
||||
cd artifacts
|
||||
find . -name "*.tar.gz" -exec sha256sum {} \; | sed 's|./[^/]*/||' >> ../CHANGELOG_BODY.md
|
||||
echo '```' >> CHANGELOG_BODY.md
|
||||
|
||||
- name: Create GitHub Release
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
name: Synor ${{ steps.changelog.outputs.current_tag }}
|
||||
body_path: CHANGELOG_BODY.md
|
||||
draft: false
|
||||
prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
|
||||
files: |
|
||||
artifacts/**/*.tar.gz
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# Optional: Publish to crates.io
|
||||
publish-crates:
|
||||
name: Publish to crates.io
|
||||
runs-on: ubuntu-latest
|
||||
needs: create-release
|
||||
if: ${{ !contains(github.ref, 'alpha') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc') }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust toolchain
|
||||
uses: dtolnay/rust-action@stable
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libclang-dev llvm-dev
|
||||
|
||||
- name: Publish crates
|
||||
env:
|
||||
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
run: |
|
||||
# Publish crates in dependency order
|
||||
# Skip if CARGO_REGISTRY_TOKEN is not set
|
||||
if [ -z "$CARGO_REGISTRY_TOKEN" ]; then
|
||||
echo "CARGO_REGISTRY_TOKEN not set, skipping crates.io publish"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Publishing to crates.io..."
|
||||
# Add --dry-run to test first, remove for actual publish
|
||||
# cargo publish -p synor-types --dry-run
|
||||
# cargo publish -p synor-crypto --dry-run
|
||||
# ... etc
|
||||
echo "Crate publishing configured but commented out - uncomment when ready"
|
||||
Loading…
Add table
Reference in a new issue