Skip to content

Commit fc23da7

Browse files
committed
made release workflow idempotent
1 parent d925f1f commit fc23da7

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,33 @@ jobs:
2929
VERSION: ${{ env.VERSION }}
3030
run: |
3131
if curl -s -f https://pypi.org/pypi/socketsecurity/$VERSION/json > /dev/null; then
32-
echo "Error: Version ${VERSION} already exists on PyPI"
33-
exit 1
32+
echo "Version ${VERSION} already exists on PyPI"
33+
echo "pypi_exists=true" >> $GITHUB_OUTPUT
34+
else
35+
echo "Version ${VERSION} not found on PyPI - proceeding with PyPI deployment"
36+
echo "pypi_exists=false" >> $GITHUB_OUTPUT
37+
fi
38+
39+
- name: Check Docker image existence
40+
id: docker_check
41+
env:
42+
VERSION: ${{ env.VERSION }}
43+
run: |
44+
if curl -s -f "https://hub.docker.com/v2/repositories/socketdev/cli/tags/${{ env.VERSION }}" > /dev/null; then
45+
echo "Docker image socketdev/cli:${VERSION} already exists"
46+
echo "docker_exists=true" >> $GITHUB_OUTPUT
3447
else
35-
echo "Version ${VERSION} not found on PyPI - proceeding with release"
48+
echo "docker_exists=false" >> $GITHUB_OUTPUT
3649
fi
3750
3851
- name: Build package
52+
if: steps.version_check.outputs.pypi_exists != 'true'
3953
run: |
4054
pip install build
4155
python -m build
4256
4357
- name: Publish to PyPI
58+
if: steps.version_check.outputs.pypi_exists != 'true'
4459
uses: pypa/[email protected]
4560
with:
4661
password: ${{ secrets.PYPI_TOKEN }}
@@ -51,7 +66,7 @@ jobs:
5166
username: ${{ secrets.DOCKERHUB_USERNAME }}
5267
password: ${{ secrets.DOCKERHUB_TOKEN }}
5368

54-
- name: Verify package is available
69+
- name: Verify package is installable
5570
id: verify_package
5671
env:
5772
VERSION: ${{ env.VERSION }}
@@ -70,7 +85,9 @@ jobs:
7085
exit 1
7186
7287
- name: Build & Push Docker
73-
if: steps.verify_package.outputs.success == 'true'
88+
if: |
89+
steps.verify_package.outputs.success == 'true' &&
90+
steps.docker_check.outputs.docker_exists != 'true'
7491
uses: docker/build-push-action@v5
7592
env:
7693
VERSION: ${{ env.VERSION }}

0 commit comments

Comments
 (0)