diff --git a/.github/workflows/client-ci.yml b/.github/workflows/client-ci.yml index 2567b91..068d998 100644 --- a/.github/workflows/client-ci.yml +++ b/.github/workflows/client-ci.yml @@ -84,6 +84,7 @@ jobs: images: ghcr.io/${{ github.repository }}/app tags: | type=raw,value=candidate + type=raw,value=pr-${{ github.event.pull_request.number }} - name: Generate version tag id: version diff --git a/.github/workflows/main-client.yml b/.github/workflows/main-client.yml index ae30375..db046ea 100644 --- a/.github/workflows/main-client.yml +++ b/.github/workflows/main-client.yml @@ -31,6 +31,10 @@ jobs: with: fetch-depth: 0 + - name: Set lowercase repo name + id: repo + run: echo "name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT + - name: Generate version tag id: version run: | @@ -49,26 +53,26 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata for Docker - id: meta - uses: docker/metadata-action@v5 - with: - images: ghcr.io/${{ github.repository }}/app - tags: | - type=raw,value=${{ steps.version.outputs.tag }} - type=raw,value=latest,enable={{is_default_branch}} + - name: Find PR number + id: find_pr + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_NUMBER=$(gh pr list --commit ${{ github.sha }} --state merged --json number --jq '.[0].number') + if [ -z "$PR_NUMBER" ]; then + echo "No merged PR found for this commit. Falling back to 'candidate' tag." + PR_NUMBER="candidate" + else + PR_NUMBER="pr-${PR_NUMBER}" + fi + echo "tag=${PR_NUMBER}" >> $GITHUB_OUTPUT - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: ./client - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - build-args: | - VITE_BUILD=v${{ steps.version.outputs.tag }} + - name: Promote Docker image + run: | + docker buildx imagetools create \ + --tag ghcr.io/${{ steps.repo.outputs.name }}/app:latest \ + --tag ghcr.io/${{ steps.repo.outputs.name }}/app:${{ steps.version.outputs.tag }} \ + ghcr.io/${{ steps.repo.outputs.name }}/app:${{ steps.find_pr.outputs.tag }} - name: Create and push Git tag run: | diff --git a/.github/workflows/main-server.yml b/.github/workflows/main-server.yml index 1b78f28..0d7514b 100644 --- a/.github/workflows/main-server.yml +++ b/.github/workflows/main-server.yml @@ -69,18 +69,29 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build Docker image with Spring Boot - working-directory: ./server - run: | - ./mvnw -Pnative -DskipTests spring-boot:build-image \ - -Dspring-boot.build-image.imageName=ghcr.io/${{ steps.repo.outputs.name }}/api:latest \ - -Dspring-boot.build-image.builder=paketobuildpacks/builder-jammy-tiny:latest + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Tag and push Docker image + - name: Find PR number + id: find_pr + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - docker tag ghcr.io/${{ steps.repo.outputs.name }}/api:latest ghcr.io/${{ steps.repo.outputs.name }}/api:${{ steps.version.outputs.version }} - docker push ghcr.io/${{ steps.repo.outputs.name }}/api:latest - docker push ghcr.io/${{ steps.repo.outputs.name }}/api:${{ steps.version.outputs.version }} + PR_NUMBER=$(gh pr list --commit ${{ github.sha }} --state merged --json number --jq '.[0].number') + if [ -z "$PR_NUMBER" ]; then + echo "No merged PR found for this commit. Falling back to 'candidate' tag." + PR_NUMBER="candidate" + else + PR_NUMBER="pr-${PR_NUMBER}" + fi + echo "tag=${PR_NUMBER}" >> $GITHUB_OUTPUT + + - name: Promote Docker image + run: | + docker buildx imagetools create \ + --tag ghcr.io/${{ steps.repo.outputs.name }}/api:latest \ + --tag ghcr.io/${{ steps.repo.outputs.name }}/api:${{ steps.version.outputs.version }} \ + ghcr.io/${{ steps.repo.outputs.name }}/api:${{ steps.find_pr.outputs.tag }} - name: Create and push Git tag run: | diff --git a/.github/workflows/server-ci.yml b/.github/workflows/server-ci.yml index a36ff6b..c8ed696 100644 --- a/.github/workflows/server-ci.yml +++ b/.github/workflows/server-ci.yml @@ -91,10 +91,12 @@ jobs: working-directory: ./server run: | ./mvnw -Pnative -DskipTests spring-boot:build-image \ - -Dspring-boot.build-image.imageName=ghcr.io/rmcampos/tasknote/api:latest \ + -Dspring-boot.build-image.imageName=ghcr.io/${{ steps.repo.outputs.name }}/api:latest \ -Dspring-boot.build-image.builder=paketobuildpacks/builder-jammy-tiny:latest - name: Tag and push Docker image run: | docker tag ghcr.io/${{ steps.repo.outputs.name }}/api:latest ghcr.io/${{ steps.repo.outputs.name }}/api:candidate + docker tag ghcr.io/${{ steps.repo.outputs.name }}/api:latest ghcr.io/${{ steps.repo.outputs.name }}/api:pr-${{ github.event.pull_request.number }} docker push ghcr.io/${{ steps.repo.outputs.name }}/api:candidate + docker push ghcr.io/${{ steps.repo.outputs.name }}/api:pr-${{ github.event.pull_request.number }}