From 0b90f3b292ed6e23bc8ce96e9577f476e92f8780 Mon Sep 17 00:00:00 2001 From: NxPKG <116948796+NxPKG@users.noreply.github.com> Date: Tue, 14 Nov 2023 01:19:30 +0600 Subject: [PATCH] Create image-prs.yaml Signed-off-by: NxPKG <116948796+NxPKG@users.noreply.github.com> --- .github/workflows/image-prs.yaml | 118 +++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 .github/workflows/image-prs.yaml diff --git a/.github/workflows/image-prs.yaml b/.github/workflows/image-prs.yaml new file mode 100644 index 0000000..941cd31 --- /dev/null +++ b/.github/workflows/image-prs.yaml @@ -0,0 +1,118 @@ +name: Image PRs Build + +on: + pull_request_target: + types: + - opened + - synchronize + - reopened + push: + branches: + - master + +jobs: + build-and-push-prs: + if: ${{ github.repository == 'khulnasoft/alpine-curl' }} + runs-on: ubuntu-20.04 + strategy: + matrix: + include: + - name: alpine-curl + dockerfile: ./Dockerfile + + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 + + - name: Login to quay.io for CI + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d + with: + registry: quay.io + username: ${{ secrets.QUAY_CI_ALPINE_CURL_USERNAME }} + password: ${{ secrets.QUAY_CI_ALPINE_CURL_PASSWORD }} + + - name: Getting image tag + id: tag + run: | + if [ ${{ github.event.pull_request.head.sha }} != "" ]; then + echo tag=${{ github.event.pull_request.head.sha }} >> $GITHUB_OUTPUT + else + echo tag=${{ github.sha }} >> $GITHUB_OUTPUT + fi + + - name: Checkout Source Code + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + with: + ref: ${{ steps.tag.outputs.tag }} + + # master branch pushes + - name: CI Build ${{ matrix.name }} + if: ${{ github.event_name != 'pull_request_target' }} + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 + id: docker_build_ci_master + with: + context: . + file: ${{ matrix.dockerfile }} + push: true + platforms: linux/amd64,linux/arm64 + tags: | + quay.io/${{ github.repository_owner }}/${{ matrix.name }}-ci:latest + quay.io/${{ github.repository_owner }}/${{ matrix.name }}-ci:${{ steps.tag.outputs.tag }} + + - name: CI Image Releases digests + if: ${{ github.event_name != 'pull_request_target' }} + shell: bash + run: | + mkdir -p image-digest/ + echo "quay.io/${{ github.repository_owner }}/${{ matrix.name }}-ci:latest@${{ steps.docker_build_ci_master.outputs.digest }}" > image-digest/${{ matrix.name }}.txt + echo "quay.io/${{ github.repository_owner }}/${{ matrix.name }}-ci:${{ steps.tag.outputs.tag }}@${{ steps.docker_build_ci_master.outputs.digest }}" >> image-digest/${{ matrix.name }}.txt + + # PR updates + - name: CI Build ${{ matrix.name }} + if: ${{ github.event_name == 'pull_request_target' }} + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 + id: docker_build_ci_pr + with: + context: . + file: ${{ matrix.dockerfile }} + push: true + platforms: linux/amd64,linux/arm64 + tags: | + quay.io/${{ github.repository_owner }}/${{ matrix.name }}-ci:${{ steps.tag.outputs.tag }} + + - name: CI Image Releases digests + if: ${{ github.event_name == 'pull_request_target' }} + shell: bash + run: | + mkdir -p image-digest/ + echo "quay.io/${{ github.repository_owner }}/${{ matrix.name }}-ci:${{ steps.tag.outputs.tag }}@${{ steps.docker_build_ci_pr.outputs.digest }}" >> image-digest/${{ matrix.name }}.txt + + # Upload artifact digests + - name: Upload artifact digests + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 + with: + name: image-digest ${{ matrix.name }} + path: image-digest + retention-days: 1 + + image-digests: + if: ${{ github.repository == 'khulnasoft/alpine-curl' }} + name: Display Digests + runs-on: ubuntu-20.04 + needs: build-and-push-prs + steps: + - name: Downloading Image Digests + shell: bash + run: | + mkdir -p image-digest/ + + - name: Download digests of all images built + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a + with: + path: image-digest/ + + - name: Image Digests Output + shell: bash + run: | + cd image-digest/ + find -type f | sort | xargs -d '\n' cat