Skip to content

Commit

Permalink
checking for existing docker tags
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaMarconato committed Jan 22, 2025
1 parent cf152f2 commit 1355138
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ name: Build Docker image

on:
workflow_run:
workflows: ["Release"]
types:
- completed
workflow_dispatch:
push:

Expand All @@ -18,7 +15,7 @@ concurrency:

jobs:
build:
if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
runs-on: ubuntu-latest

defaults:
Expand All @@ -28,7 +25,7 @@ jobs:
permissions:
contents: read
packages: write
attestations: write
attestation: write
id-token: write

steps:
Expand All @@ -53,14 +50,42 @@ jobs:
echo "SPATIALDATA_IO_VERSION=${SPATIALDATA_IO_VERSION}" >> $GITHUB_ENV
echo "SPATIALDATA_PLOT_VERSION=${SPATIALDATA_PLOT_VERSION}" >> $GITHUB_ENV
- name: Check if image tag exists
id: check_tag
env:
IMAGE_TAG: ${{ env.REGISTRY }}/scverse/spatialdata:spatialdata${{ env.SPATIALDATA_VERSION }}_spatialdata-io${{ env.SPATIALDATA_IO_VERSION }}_spatialdata-plot${{ env.SPATIALDATA_PLOT_VERSION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Define the API URL
API_URL="https://api.github.com/orgs/scverse/packages/container/spatialdata/versions"
# Fetch all existing versions
existing_tags=$(curl -s -H "Authorization: token $GITHUB_TOKEN" $API_URL | jq -r '.[].metadata.container.tags[]')
# Debug: Output all existing tags
echo "Existing tags:"
echo "$existing_tags"
# Check if the constructed tag exists
if echo "$existing_tags" | grep -q "$IMAGE_TAG"; then
echo "Image tag $IMAGE_TAG already exists. Skipping build."
echo "skip_build=true" >> $GITHUB_ENV
else
echo "Image tag $IMAGE_TAG does not exist. Proceeding with build."
echo "skip_build=false" >> $GITHUB_ENV
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
fi
- name: Login to GitHub Container Registry
if: ${{ env.skip_build == 'false' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: docker/build-push-action@v5
if: ${{ env.skip_build == 'false' }}
with:
context: .
file: ./Dockerfile
Expand All @@ -71,4 +96,4 @@ jobs:
SPATIALDATA_VERSION=${{ env.SPATIALDATA_VERSION }}
SPATIALDATA_IO_VERSION=${{ env.SPATIALDATA_IO_VERSION }}
SPATIALDATA_PLOT_VERSION=${{ env.SPATIALDATA_PLOT_VERSION }}
tags: ${{ env.REGISTRY }}/scverse/spatialdata:spatialdata${{ env.SPATIALDATA_VERSION }}_spatialdata-io${{ env.SPATIALDATA_IO_VERSION }}_spatialdata-plot${{ env.SPATIALDATA_PLOT_VERSION }}
tags: ${{ env.IMAGE_TAG }}

0 comments on commit 1355138

Please sign in to comment.