Skip to content

Commit

Permalink
Skip image build/push if it exists
Browse files Browse the repository at this point in the history
To avoid building images on every merge to main, check if image exists
first and only build/push if absent.
  • Loading branch information
masih committed Nov 24, 2023
1 parent 2b8d29c commit 090afc8
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions .github/workflows/publish-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,52 @@ 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
dotnet: true
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:
Expand Down

0 comments on commit 090afc8

Please sign in to comment.