name: Docker Build and Publish on: push: branches: [ "main" ] pull_request: branches: [ "main" ] env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: test: runs-on: ubuntu-latest services: postgres: image: postgres:16-alpine env: POSTGRES_USER: flowreader POSTGRES_PASSWORD: flowreader POSTGRES_DB: flowreader ports: - 5432:5432 options: >- --health-cmd "pg_isready -U flowreader" --health-interval 5s --health-timeout 5s --health-retries 10 steps: - name: Checkout repository uses: actions/checkout@v4 - name: Install Rust uses: dtolnay/rust-toolchain@stable with: components: clippy, rustfmt - name: Cache cargo uses: Swatinem/rust-cache@v2 - name: Format run: cargo fmt --check - name: Clippy run: cargo clippy --all-targets --locked -- -D warnings - name: Tests env: TEST_DATABASE_URL: postgres://flowreader:flowreader@localhost:5432/flowreader?sslmode=disable run: cargo test --locked build: needs: test runs-on: ubuntu-latest permissions: contents: read packages: write steps: - name: Checkout repository uses: actions/checkout@v4 - name: Log in to the Container registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=raw,value=latest,enable={{is_default_branch}} type=sha - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }}