release.yml•10.8 kB
name: Production Release Pipeline
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., v1.0.0)'
required: true
type: string
environment:
description: 'Target Environment'
required: true
default: 'staging'
type: choice
options:
- staging
- production
deployment_strategy:
description: 'Deployment Strategy'
required: true
default: 'rolling'
type: choice
options:
- rolling
- blue_green
- canary
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Get version
id: get_version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/}
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Version: ${VERSION}"
- name: Generate changelog
run: |
echo "# Changelog for ${{ steps.get_version.outputs.version }}" > RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
echo "## What's Changed" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
# Extract commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
git log --pretty=format:"- %s" ${LAST_TAG}..HEAD >> RELEASE_NOTES.md
else
echo "- Initial release" >> RELEASE_NOTES.md
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: Release ${{ steps.get_version.outputs.version }}
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
build-cross-platform:
name: Build (${{ matrix.target }})
runs-on: ${{ matrix.os }}
needs: create-release
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: codegraph-api-linux-x86_64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
name: codegraph-api-linux-aarch64
- target: x86_64-apple-darwin
os: macos-latest
name: codegraph-api-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
name: codegraph-api-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: codegraph-api-windows-x86_64.exe
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev
# Install cross-compilation tools for aarch64
if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]]; then
sudo apt-get install -y gcc-aarch64-linux-gnu
fi
# Install musl tools for static linking
if [[ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]]; then
sudo apt-get install -y musl-tools
fi
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install pkg-config
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
- name: Configure cross-compilation
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo '[target.aarch64-unknown-linux-gnu]' >> ~/.cargo/config.toml
echo 'linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml
- name: Set platform-specific optimization flags
shell: bash
run: |
case "${{ matrix.target }}" in
x86_64-unknown-linux-gnu|x86_64-unknown-linux-musl|x86_64-apple-darwin|x86_64-pc-windows-msvc)
echo "RUSTFLAGS=-C target-cpu=x86-64-v2" >> $GITHUB_ENV
;;
*)
echo "RUSTFLAGS=" >> $GITHUB_ENV
;;
esac
- name: Build release binary
run: |
cargo build --release --target ${{ matrix.target }} --workspace
- name: Verify binary (--version)
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
target\\${{ matrix.target }}\\release\\codegraph-api.exe --version
else
target/${{ matrix.target }}/release/codegraph-api --version
fi
- name: Prepare release asset
shell: bash
run: |
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
cp target/${{ matrix.target }}/release/codegraph-api.exe ${{ matrix.name }}
else
cp target/${{ matrix.target }}/release/codegraph-api ${{ matrix.name }}
fi
# Create compressed archive
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
7z a ${{ matrix.name }}.zip ${{ matrix.name }}
echo "ASSET=${{ matrix.name }}.zip" >> $GITHUB_ENV
else
tar czf ${{ matrix.name }}.tar.gz ${{ matrix.name }}
echo "ASSET=${{ matrix.name }}.tar.gz" >> $GITHUB_ENV
fi
# Create checksum
(shasum -a 256 "$ASSET" > "$ASSET.sha256") || (sha256sum "$ASSET" > "$ASSET.sha256")
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ env.ASSET }}
asset_name: ${{ env.ASSET }}
asset_content_type: application/octet-stream
- name: Upload Checksum
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ env.ASSET }}.sha256
asset_name: ${{ env.ASSET }}.sha256
asset_content_type: text/plain
build-docker:
name: Build Docker Images
runs-on: ubuntu-latest
needs: create-release
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Create Dockerfile
run: |
cat > Dockerfile << 'EOF'
# Multi-stage build for optimized production image
FROM rust:1.75 as builder
WORKDIR /app
COPY . .
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Build the application
RUN cargo build --release --package codegraph-api
# Production stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -r -s /bin/false codegraph
# Copy the binary from builder stage
COPY --from=builder /app/target/release/codegraph-api /usr/local/bin/codegraph-api
# Set ownership and permissions
RUN chown root:root /usr/local/bin/codegraph-api && \
chmod 755 /usr/local/bin/codegraph-api
USER codegraph
EXPOSE 8080
CMD ["codegraph-api"]
EOF
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
codegraph/codegraph:${{ needs.create-release.outputs.version }}
codegraph/codegraph:latest
cache-from: type=gha
cache-to: type=gha,mode=max
publish-crates:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [create-release, build-cross-platform]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-publish-${{ hashFiles('**/Cargo.lock') }}
- name: Publish to crates.io
run: |
# Publish workspace crates in dependency order
cargo publish -p codegraph-core --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
sleep 10
cargo publish -p codegraph-graph --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
sleep 10
cargo publish -p codegraph-parser --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
sleep 10
cargo publish -p codegraph-vector --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
sleep 10
cargo publish -p codegraph-api --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
post-release:
name: Post Release Tasks
runs-on: ubuntu-latest
needs: [create-release, build-cross-platform, build-docker]
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Update version badges
run: |
# Create or update badges for the release
echo "Release ${{ needs.create-release.outputs.version }} completed successfully!"
- name: Notify stakeholders
run: |
echo "🎉 CodeGraph ${{ needs.create-release.outputs.version }} has been released!"
echo "📦 Binaries available for multiple platforms"
echo "🐳 Docker images updated"
echo "📚 Documentation will be updated shortly"