name: Lint and Build on: push: branches: - main - develop pull_request: branches: - main - develop env: CARGO_TERM_COLOR: always RUST_BACKTRACE: 1 jobs: lint: name: Lint runs-on: docker steps: - name: Checkout code uses: actions/checkout@v4 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable components: rustfmt, clippy override: true - name: Cache cargo registry uses: actions/cache@v3 with: path: ~/.cargo/registry key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v3 with: path: ~/.cargo/git key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo build uses: actions/cache@v3 with: path: backend/target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - name: Run rustfmt working-directory: ./backend run: | cargo fmt --all -- --check - name: Run clippy working-directory: ./backend run: | cargo clippy --all-targets --all-features -- -D warnings build: name: Build runs-on: docker needs: lint steps: - name: Checkout code uses: actions/checkout@v4 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - name: Cache cargo registry uses: actions/cache@v3 with: path: ~/.cargo/registry key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v3 with: path: ~/.cargo/git key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo build uses: actions/cache@v3 with: path: backend/target key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} - name: Build project working-directory: ./backend run: | cargo build --verbose - name: Run tests working-directory: ./backend run: | cargo test --verbose docker-build: name: Docker Build runs-on: docker needs: build steps: - name: Checkout code uses: actions/checkout@v4 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Build Docker image working-directory: ./backend run: | docker build -f docker/Dockerfile -t normogen-backend:test . - name: Build Docker image (dev) working-directory: ./backend run: | docker build -f docker/Dockerfile.dev -t normogen-backend:dev-test .