Skip to content

Remove clippy warnings as errors in CI #7

Remove clippy warnings as errors in CI

Remove clippy warnings as errors in CI #7

Workflow file for this run

name: CI - Build, Test, and Format
on:
push:
branches: [ main, develop ]
tags: [ 'v*' ]
pull_request:
branches: [ main, develop ]
env:
CARGO_TERM_COLOR: always
REGISTRY: docker.io
IMAGE_NAME: namananand996/centralized-exchange
jobs:
format:
name: Format Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: Check formatting
run: cargo fmt --all -- --check
lint:
name: Lint Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Run clippy
run: cargo clippy --all-targets --all-features
test:
name: Test Suite
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: centralized_exchange_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Run tests
run: cargo test --verbose
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/centralized_exchange_test
REDIS_URL: redis://localhost:6379
JWT_SECRET: test-secret-key
CORS_ORIGIN: http://localhost:3000
REDIS_MAX_CONNECTIONS: 10
REDIS_TIMEOUT_SECONDS: 5
PRICE_UPDATE_INTERVAL_SECONDS: 300
RUST_LOG: info
build:
name: Build Application
runs-on: ubuntu-latest
needs: [format, lint, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Build application
run: cargo build --release --verbose
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: centralized-exchange-binary
path: target/release/centralized-exchange
retention-days: 7
docker-build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [build]
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Image digest
run: echo ${{ steps.build.outputs.digest }}
release:
name: Create Release
runs-on: ubuntu-latest
needs: [docker-build]
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
id: version
run: |
VERSION=${GITHUB_REF#refs/tags/}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag_name=$VERSION" >> $GITHUB_OUTPUT
- name: Generate release notes
id: release_notes
run: |
# Get commits since last tag
if git tag --sort=-version:refname | head -n2 | tail -n1 > /dev/null 2>&1; then
PREVIOUS_TAG=$(git tag --sort=-version:refname | head -n2 | tail -n1)
COMMITS=$(git log --pretty=format:"- %s (%h)" $PREVIOUS_TAG..HEAD)
else
COMMITS=$(git log --pretty=format:"- %s (%h)" --reverse)
fi
# Create release notes
cat > RELEASE_NOTES.md << EOF
# Release ${{ steps.version.outputs.version }}
## What's Changed
$COMMITS
## Docker Image
The Docker image is available at:
\`\`\`
docker pull ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
\`\`\`
## Installation
\`\`\`bash
docker pull ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
docker run -p 8080:8080 ${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
\`\`\`
EOF
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
cat RELEASE_NOTES.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.tag_name }}
release_name: Release ${{ steps.version.outputs.version }}
body: ${{ steps.release_notes.outputs.release_notes }}
draft: false
prerelease: false
notify:
name: Notify CI Status
runs-on: ubuntu-latest
needs: [format, lint, test, build, docker-build, release]
if: always()
steps:
- name: Notify on success
if: ${{ needs.format.result == 'success' && needs.lint.result == 'success' && needs.test.result == 'success' && needs.build.result == 'success' }}
run: |
echo "✅ CI pipeline completed successfully!"
echo "- ✅ Code formatting passed"
echo "- ✅ Linting passed"
echo "- ✅ All tests passed"
echo "- ✅ Build successful"
echo "- ✅ Docker image built and pushed"
if [ "${{ needs.release.result }}" == "success" ]; then
echo "- ✅ Release created"
fi
# Add your notification logic here (Slack, Discord, email, etc.)
- name: Notify on failure
if: ${{ needs.format.result == 'failure' || needs.lint.result == 'failure' || needs.test.result == 'failure' || needs.build.result == 'failure' }}
run: |
echo "❌ CI pipeline failed!"
echo "- Format check: ${{ needs.format.result }}"
echo "- Lint check: ${{ needs.lint.result }}"
echo "- Tests: ${{ needs.test.result }}"
echo "- Build: ${{ needs.build.result }}"
echo "- Docker build: ${{ needs.docker-build.result }}"
# Add your notification logic here (Slack, Discord, email, etc.)