diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4672ae4..12dcbbd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,12 +22,9 @@ jobs: with: ref: ${{ github.head_ref }} token: ${{ secrets.GITHUB_TOKEN }} - - uses: oven-sh/setup-bun@v1 - - name: Install and update lockfile run: bun install - - name: Commit and push updated lockfile run: | git config user.name "github-actions[bot]" @@ -36,57 +33,83 @@ jobs: git commit -m "chore: update lockfile (auto-fix for Dependabot PR)" || exit 0 git push - # Build and push Docker image - build: + # Build and push Docker image for Dependabot PRs + build_dependabot: runs-on: ubuntu-latest - needs: [update-lockfile] - # Run this job if: - # 1. This is NOT a PR (like push to main or release) - # 2. OR this is a PR but NOT from Dependabot - # 3. OR this is a Dependabot PR AND the update-lockfile job completed successfully - if: | - github.event_name != 'pull_request' || - (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'dependabot/')) || - (github.event_name == 'pull_request' && startsWith(github.head_ref, 'dependabot/') && needs.update-lockfile.result == 'success') - + needs: update-lockfile + if: github.event_name == 'pull_request' && startsWith(github.head_ref, 'dependabot/') permissions: contents: read packages: write - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: ${{ github.event_name == 'pull_request' && startsWith(github.head_ref, 'dependabot/') && github.head_ref || '' }} + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set image metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=tag + type=raw,value=latest,enable={{is_default_branch}} + type=sha,format=short + type=ref,event=branch + type=ref,event=pr + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: false + platforms: linux/amd64,linux/arm64/v8 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to GitHub Container Registry - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Set image metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }} - tags: | - type=ref,event=tag - type=raw,value=latest,enable={{is_default_branch}} - type=sha,format=short - type=ref,event=branch - type=ref,event=pr - - - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - file: ./Dockerfile - push: ${{ github.event_name != 'pull_request' }} - platforms: linux/amd64, linux/arm64/v8 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + # Build and push Docker image for all other events + build: + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' || (github.event_name == 'pull_request' && !startsWith(github.head_ref, 'dependabot/')) + permissions: + contents: read + packages: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Set image metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=tag + type=raw,value=latest,enable={{is_default_branch}} + type=sha,format=short + type=ref,event=branch + type=ref,event=pr + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64/v8 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file