test: simplify unit tests setup for command and callback handlers #181
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| env: | |
| DATABASE_URL: 'sqlite://data/data.db' | |
| steps: | |
| # Checkout the repository | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # Set up the Rust toolchain | |
| - name: Set up Rust nightly | |
| run: | | |
| rustup default nightly | |
| rustup component add clippy rustfmt | |
| # Cache Cargo registry (dependencies) and Git repositories | |
| - name: Cache Cargo registry | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
| # Cache build artifacts | |
| - name: Cache Cargo build | |
| uses: actions/cache@v3 | |
| with: | |
| path: target | |
| key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} | |
| # Optionally, check formatting | |
| - name: Check code formatting | |
| run: cargo fmt -- --check | |
| # Run cargo check to verify the project compiles | |
| - name: Run cargo check | |
| env: | |
| SQLX_OFFLINE: '1' | |
| run: cargo check --workspace | |
| # Run clippy to catch lints and warnings (treat warnings as errors) | |
| - name: Run cargo clippy | |
| env: | |
| SQLX_OFFLINE: '1' | |
| run: cargo clippy --workspace -- -D warnings | |
| # Run tests | |
| - name: Run tests | |
| env: | |
| SQLX_OFFLINE: '1' | |
| run: cargo test --workspace | |
| docker: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| if: | |
| github.event_name == 'push' && github.ref == 'refs/heads/main' || | |
| github.event_name == 'workflow_dispatch' | |
| steps: | |
| # Checkout the repository | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # Set up QEMU for cross-platform builds | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| # Set up Docker Buildx | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| # Force lowercase repository name | |
| # This is necessary for GHCR to work correctly with the repository name | |
| - name: Force lowercase repository name | |
| id: lowercase | |
| run: | | |
| OWNER_LOWER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]') | |
| REPO_LOWER=$(echo "${{ github.event.repository.name }}" | tr '[:upper:]' '[:lower:]') | |
| echo "REPO_PATH=$OWNER_LOWER/$REPO_LOWER" >> $GITHUB_ENV | |
| # Log in to GHCR | |
| - name: Log in to GHCR | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| # Extract metadata for the Docker image | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v4 | |
| with: | |
| images: ghcr.io/${{ env.REPO_PATH }} | |
| # Build and push Docker image | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| platforms: linux/amd64,linux/arm64 | |
| push: true | |
| tags: | | |
| ghcr.io/${{ env.REPO_PATH }}:latest | |
| ghcr.io/${{ env.REPO_PATH }}:${{ github.sha }} | |
| labels: ${{ steps.meta.outputs.labels }} |