From d31aa9fff18633f1232d82d3d4e2bc2b8215fc20 Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Fri, 24 Nov 2023 14:52:26 +0000 Subject: [PATCH] Skip image build/push if it exists To avoid building images on every merge to main, check if image exists first and only build/push if absent. --- .github/workflows/publish-containers.yml | 38 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish-containers.yml b/.github/workflows/publish-containers.yml index dd602fd..f4f3e8c 100644 --- a/.github/workflows/publish-containers.yml +++ b/.github/workflows/publish-containers.yml @@ -35,8 +35,29 @@ jobs: platform: - linux/amd64,linux/arm64 steps: + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata for Lotus ${{ matrix.version }} ${{ matrix.net.name }} + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=raw,value=lotus-${{ matrix.version }}-${{ matrix.net.name }} + - name: Check if image exists + id: checker + run: | + if ! docker manifest inspect ${{ steps.meta.outputs.tags }} + then + echo "IMAGE_EXISTS=false" >> $GITHUB_ENV + fi - name: Free Disk Space (Ubuntu) uses: jlumbroso/free-disk-space@main + if: env.IMAGE_EXISTS == 'false' with: tool-cache: false android: true @@ -44,31 +65,22 @@ jobs: haskell: true - name: Checkout uses: actions/checkout@v3 + if: env.IMAGE_EXISTS == 'false' with: repository: filecoin-project/lotus ref: ${{ matrix.version }} path: lotus - name: Set up QEMU uses: docker/setup-qemu-action@v2 + if: env.IMAGE_EXISTS == 'false' - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + if: env.IMAGE_EXISTS == 'false' with: platforms: ${{ matrix.platform }} - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata for Lotus ${{ matrix.version }} ${{ matrix.net.name }} - id: meta - uses: docker/metadata-action@v4 - with: - images: ghcr.io/${{ github.repository }} - tags: | - type=raw,value=lotus-${{ matrix.version }}-${{ matrix.net.name }} - name: Build Lotus ${{ matrix.version }} ${{ matrix.net.name }} uses: docker/build-push-action@v4 + if: env.IMAGE_EXISTS == 'false' env: REGISTRY_CACHE_REF: ghcr.io/${{ github.repository }}:cache with: