|
14 | 14 | IMAGE_PREFIX: ${{ github.repository }} |
15 | 15 |
|
16 | 16 | jobs: |
| 17 | + detect-changes: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + catalogue: ${{ steps.filter.outputs.catalogue }} |
| 21 | + voting: ${{ steps.filter.outputs.voting }} |
| 22 | + recommendation: ${{ steps.filter.outputs.recommendation }} |
| 23 | + frontend: ${{ steps.filter.outputs.frontend }} |
| 24 | + steps: |
| 25 | + - uses: actions/checkout@v4 |
| 26 | + - uses: dorny/paths-filter@v3 |
| 27 | + id: filter |
| 28 | + with: |
| 29 | + filters: | |
| 30 | + catalogue: |
| 31 | + - 'catalogue/**' |
| 32 | + voting: |
| 33 | + - 'voting/**' |
| 34 | + recommendation: |
| 35 | + - 'recommendation/**' |
| 36 | + frontend: |
| 37 | + - 'frontend/**' |
| 38 | +
|
17 | 39 | build-images: |
| 40 | + needs: detect-changes |
18 | 41 | runs-on: ubuntu-latest |
19 | 42 | strategy: |
20 | 43 | matrix: |
21 | | - images-name: ["catalogue", "voting", "recommendation", "frontend"] |
| 44 | + include: |
| 45 | + - name: catalogue |
| 46 | + changed: ${{ needs.detect-changes.outputs.catalogue }} |
| 47 | + - name: voting |
| 48 | + changed: ${{ needs.detect-changes.outputs.voting }} |
| 49 | + - name: recommendation |
| 50 | + changed: ${{ needs.detect-changes.outputs.recommendation }} |
| 51 | + - name: frontend |
| 52 | + changed: ${{ needs.detect-changes.outputs.frontend }} |
22 | 53 | permissions: |
23 | 54 | contents: read |
24 | 55 | packages: write |
25 | 56 | steps: |
26 | 57 | - name: Checkout |
| 58 | + if: ${{ matrix.changed == 'true' }} |
27 | 59 | uses: actions/checkout@v4 |
28 | 60 |
|
29 | 61 | - name: Set up Docker Buildx |
| 62 | + if: ${{ matrix.changed == 'true' }} |
30 | 63 | uses: docker/setup-buildx-action@v3 |
31 | 64 |
|
32 | 65 | - name: Login to GitHub Container Registry |
| 66 | + if: ${{ matrix.changed == 'true' }} |
33 | 67 | uses: docker/login-action@v3 |
34 | 68 | with: |
35 | 69 | registry: ${{ env.REGISTRY }} |
36 | 70 | username: ${{ github.actor }} |
37 | 71 | password: ${{ secrets.GITHUB_TOKEN }} |
38 | 72 |
|
39 | 73 | - name: Extract metadata |
| 74 | + if: ${{ matrix.changed == 'true' }} |
40 | 75 | id: meta |
41 | 76 | uses: docker/metadata-action@v5 |
42 | 77 | with: |
43 | | - images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.images-name }} |
| 78 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_PREFIX }}/${{ matrix.name}} |
44 | 79 | tags: | |
45 | 80 | type=ref,event=pr |
| 81 | + type=raw,value=latest,enable={{is_default_branch}} |
46 | 82 | type=sha,prefix=pr-${{ github.event.pull_request.number }}- |
47 | 83 |
|
48 | 84 | - name: Build and push |
| 85 | + if: ${{ matrix.changed == 'true' }} |
49 | 86 | uses: docker/build-push-action@v5 |
50 | 87 | with: |
51 | | - context: ./${{ matrix.images-name }} |
| 88 | + context: ./${{ matrix.name}} |
52 | 89 | push: true |
53 | 90 | tags: ${{ steps.meta.outputs.tags }} |
54 | 91 | labels: ${{ steps.meta.outputs.labels }} |
|
0 commit comments