Skip to content

Commit 1355138

Browse files
committed
checking for existing docker tags
1 parent cf152f2 commit 1355138

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

.github/workflows/build_image.yml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: Build Docker image
22

33
on:
44
workflow_run:
5-
workflows: ["Release"]
6-
types:
7-
- completed
85
workflow_dispatch:
96
push:
107

@@ -18,7 +15,7 @@ concurrency:
1815

1916
jobs:
2017
build:
21-
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' }}
18+
if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'push' }}
2219
runs-on: ubuntu-latest
2320

2421
defaults:
@@ -28,7 +25,7 @@ jobs:
2825
permissions:
2926
contents: read
3027
packages: write
31-
attestations: write
28+
attestation: write
3229
id-token: write
3330

3431
steps:
@@ -53,14 +50,42 @@ jobs:
5350
echo "SPATIALDATA_IO_VERSION=${SPATIALDATA_IO_VERSION}" >> $GITHUB_ENV
5451
echo "SPATIALDATA_PLOT_VERSION=${SPATIALDATA_PLOT_VERSION}" >> $GITHUB_ENV
5552
53+
- name: Check if image tag exists
54+
id: check_tag
55+
env:
56+
IMAGE_TAG: ${{ env.REGISTRY }}/scverse/spatialdata:spatialdata${{ env.SPATIALDATA_VERSION }}_spatialdata-io${{ env.SPATIALDATA_IO_VERSION }}_spatialdata-plot${{ env.SPATIALDATA_PLOT_VERSION }}
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
run: |
59+
# Define the API URL
60+
API_URL="https://api.github.com/orgs/scverse/packages/container/spatialdata/versions"
61+
62+
# Fetch all existing versions
63+
existing_tags=$(curl -s -H "Authorization: token $GITHUB_TOKEN" $API_URL | jq -r '.[].metadata.container.tags[]')
64+
65+
# Debug: Output all existing tags
66+
echo "Existing tags:"
67+
echo "$existing_tags"
68+
69+
# Check if the constructed tag exists
70+
if echo "$existing_tags" | grep -q "$IMAGE_TAG"; then
71+
echo "Image tag $IMAGE_TAG already exists. Skipping build."
72+
echo "skip_build=true" >> $GITHUB_ENV
73+
else
74+
echo "Image tag $IMAGE_TAG does not exist. Proceeding with build."
75+
echo "skip_build=false" >> $GITHUB_ENV
76+
echo "IMAGE_TAG=${IMAGE_TAG}" >> $GITHUB_ENV
77+
fi
78+
5679
- name: Login to GitHub Container Registry
80+
if: ${{ env.skip_build == 'false' }}
5781
uses: docker/login-action@v3
5882
with:
5983
registry: ${{ env.REGISTRY }}
6084
username: ${{ github.actor }}
6185
password: ${{ secrets.GITHUB_TOKEN }}
6286

6387
- uses: docker/build-push-action@v5
88+
if: ${{ env.skip_build == 'false' }}
6489
with:
6590
context: .
6691
file: ./Dockerfile
@@ -71,4 +96,4 @@ jobs:
7196
SPATIALDATA_VERSION=${{ env.SPATIALDATA_VERSION }}
7297
SPATIALDATA_IO_VERSION=${{ env.SPATIALDATA_IO_VERSION }}
7398
SPATIALDATA_PLOT_VERSION=${{ env.SPATIALDATA_PLOT_VERSION }}
74-
tags: ${{ env.REGISTRY }}/scverse/spatialdata:spatialdata${{ env.SPATIALDATA_VERSION }}_spatialdata-io${{ env.SPATIALDATA_IO_VERSION }}_spatialdata-plot${{ env.SPATIALDATA_PLOT_VERSION }}
99+
tags: ${{ env.IMAGE_TAG }}

0 commit comments

Comments
 (0)