@@ -3,27 +3,52 @@ name: Build and push Docker images
33on :
44 push :
55 tags : ' @openfn/ws-worker@**'
6+ workflow_call :
67
78jobs :
8- build-and-push-worker-image :
9- name : Push Docker image to Docker Hub
9+ check-tag :
10+ name : Check if Docker tag exists
1011 runs-on : ubuntu-latest
12+ outputs :
13+ should_build : ${{ steps.check.outputs.should_build }}
14+ docker_tag : ${{ steps.extract.outputs.docker_tag }}
1115 steps :
12- - name : Checkout
13- uses : actions/checkout@v4
14- - name : Manipulate tag for docker
15- id : branch_name
16+ - uses : actions/checkout@v4
17+ with :
18+ fetch-depth : 0
19+ - name : Extract Docker tag
20+ id : extract
1621 run : |
17- SOURCE_TAG=${GITHUB_REF#refs/tags/}
22+ SOURCE_TAG=$(git tag --sort=-creatordate --list "@openfn/ws-worker@*" | head -n 1)
1823 echo Source Tag: $SOURCE_TAG
1924
2025 VERSION_TAG=${SOURCE_TAG#@openfn/ws-worker}
2126 echo Version Tag: $VERSION_TAG
22-
27+
2328 DOCKER_TAG=${VERSION_TAG#@}
2429 echo Docker Tag: $DOCKER_TAG
25-
26- echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
30+
31+ echo "docker_tag=$DOCKER_TAG" >> $GITHUB_OUTPUT
32+ - name : Check if Docker tag exists
33+ id : check
34+ run : |
35+ STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
36+ https://hub.docker.com/v2/repositories/openfn/ws-worker/tags/v${{ steps.extract.outputs.docker_tag }}/)
37+ if [ "$STATUS" = "200" ]; then
38+ echo "Tag v${{ steps.extract.outputs.docker_tag }} already exists on Docker Hub, skipping build"
39+ echo "should_build=false" >> $GITHUB_OUTPUT
40+ else
41+ echo "should_build=true" >> $GITHUB_OUTPUT
42+ fi
43+
44+ build-and-push-worker-image :
45+ needs : check-tag
46+ if : needs.check-tag.outputs.should_build == 'true'
47+ name : Push Docker image to Docker Hub
48+ runs-on : ubuntu-latest
49+ steps :
50+ - name : Checkout
51+ uses : actions/checkout@v4
2752 - name : Set up QEMU
2853 uses : docker/setup-qemu-action@v3
2954 - name : Set up Docker Buildx
4166 target : ws-worker
4267 tags : |
4368 openfn/ws-worker:latest
44- openfn/ws-worker:v${{ env.DOCKER_TAG }}
69+ openfn/ws-worker:v${{ needs.check-tag.outputs.docker_tag }}
0 commit comments