|
| 1 | +--- |
| 2 | +name: Images |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - "*" |
| 9 | + |
| 10 | +permissions: |
| 11 | + packages: write |
| 12 | + contents: read |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY_USER: ${{ github.actor }} |
| 16 | + REGISTRY_PASSWORD: ${{ github.token }} |
| 17 | + IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }} |
| 18 | + IMAGE_TAG: ${{ github.ref_name }} |
| 19 | + |
| 20 | +jobs: |
| 21 | + lowercase: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + image_registry: ${{ steps.lowercase.outputs.image_registry }} |
| 25 | + steps: |
| 26 | + - name: Lowercase image registry name |
| 27 | + id: lowercase |
| 28 | + run: | |
| 29 | + echo "image_registry=${IMAGE_REGISTRY,,}" >> "$GITHUB_OUTPUT" |
| 30 | +
|
| 31 | + compute-dir-matrix: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + outputs: |
| 34 | + matrix: ${{ steps.compute-matrix.outputs.matrix }} |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + fetch-depth: 0 |
| 40 | + - name: Compute Matrix |
| 41 | + id: compute-matrix |
| 42 | + run: | |
| 43 | + dirs=$(make container-dirs | xargs -n 1 | jq -R . | jq -cs .) |
| 44 | + echo "matrix=${dirs}" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + compute-tags: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + outputs: |
| 49 | + tags: ${{ steps.tags.outputs.tags }} |
| 50 | + steps: |
| 51 | + - name: Build image tags list |
| 52 | + id: tags |
| 53 | + run: | |
| 54 | + if [[ "${{ env.IMAGE_TAG }}" == "main" ]]; then |
| 55 | + echo 'tags=latest main-'"$(date -u +%Y%m%dT%H%M%SZ)" >> "$GITHUB_OUTPUT" |
| 56 | + else |
| 57 | + echo 'tags=${{ env.IMAGE_TAG }}' >> "$GITHUB_OUTPUT" |
| 58 | + fi |
| 59 | +
|
| 60 | + compute-changed-files: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + outputs: |
| 63 | + changed-files: ${{ steps.processed.outputs.changed-files }} |
| 64 | + steps: |
| 65 | + - name: Checkout |
| 66 | + uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + fetch-depth: 0 |
| 69 | + - name: Get Changed Files |
| 70 | + id: changes |
| 71 | + uses: dorny/paths-filter@v3 |
| 72 | + with: |
| 73 | + filters: | |
| 74 | + repo: |
| 75 | + - '**' |
| 76 | + list-files: "json" |
| 77 | + - name: Process |
| 78 | + id: processed |
| 79 | + run: | |
| 80 | + processed=$(echo '${{ steps.changes.outputs.repo_files }}' | jq -r '.[]' | xargs realpath | jq -R | jq -cs .) |
| 81 | + echo "changed-files=${processed}" > "$GITHUB_OUTPUT" |
| 82 | + images: |
| 83 | + needs: |
| 84 | + - compute-dir-matrix |
| 85 | + - compute-tags |
| 86 | + - compute-changed-files |
| 87 | + - lowercase |
| 88 | + runs-on: ubuntu-latest |
| 89 | + strategy: |
| 90 | + fail-fast: false |
| 91 | + matrix: |
| 92 | + dir: ${{ fromJSON(needs.compute-dir-matrix.outputs.matrix) }} |
| 93 | + steps: |
| 94 | + - name: Checkout |
| 95 | + uses: actions/checkout@v4 |
| 96 | + with: |
| 97 | + fetch-depth: 0 |
| 98 | + |
| 99 | + - name: should-build |
| 100 | + id: should-build |
| 101 | + run: | |
| 102 | + if make should-build CONTAINER_DIRS='${{ matrix.dir }}' CHANGED_FILES='${{ needs.compute-changed-files.outputs.changed-files }}'; then should_build=1; else should_build=0; fi |
| 103 | + echo "should-build=${should_build}" > "$GITHUB_OUTPUT" |
| 104 | +
|
| 105 | + - name: Remove extras |
| 106 | + if: ${{ (steps.should-build.outputs.should-build == '1') || startsWith(github.ref, 'refs/tags') }} |
| 107 | + run: | |
| 108 | + sudo rm -rf "$AGENT_TOOLSDIRECTORY" |
| 109 | +
|
| 110 | + - name: Log in to ghcr.io |
| 111 | + if: ${{ (steps.should-build.outputs.should-build == '1') || startsWith(github.ref, 'refs/tags') }} |
| 112 | + uses: redhat-actions/podman-login@v1 |
| 113 | + with: |
| 114 | + username: ${{ env.REGISTRY_USER }} |
| 115 | + password: ${{ env.REGISTRY_PASSWORD }} |
| 116 | + registry: ${{ needs.lowercase.outputs.image_registry }} |
| 117 | + |
| 118 | + - name: podman build |
| 119 | + if: ${{ (steps.should-build.outputs.should-build == '1') || startsWith(github.ref, 'refs/tags') }} |
| 120 | + run: make podman-build CONTAINER_DIRS='${{ matrix.dir }}' IMAGE_TAGS='${{ needs.compute-tags.outputs.tags }}' IMAGE_LABELS='org.opencontainers.image.revision=${{ github.sha }}' |
| 121 | + |
| 122 | + - name: podman push |
| 123 | + if: ${{ (steps.should-build.outputs.should-build == '1') || startsWith(github.ref, 'refs/tags') }} |
| 124 | + run: make podman-push CONTAINER_DIRS='${{ matrix.dir }}' IMAGE_TAGS='${{ needs.compute-tags.outputs.tags }}' |
0 commit comments