|
2 | 2 | VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
|
3 | 3 | ENABLE_PYPI_BUILD=$1
|
4 | 4 | STABLE_VERSION=$2
|
| 5 | + |
| 6 | +verify_package() { |
| 7 | + local version=$1 |
| 8 | + local pip_index=$2 |
| 9 | + echo "Verifying package availability..." |
| 10 | + |
| 11 | + for i in $(seq 1 30); do |
| 12 | + if pip install --index-url $pip_index socketsecurity==$version; then |
| 13 | + echo "Package $version is now available and installable" |
| 14 | + pip uninstall -y socketsecurity |
| 15 | + return 0 |
| 16 | + fi |
| 17 | + echo "Attempt $i: Package not yet installable, waiting 20s... ($i/30)" |
| 18 | + sleep 20 |
| 19 | + done |
| 20 | + |
| 21 | + echo "Package verification failed after 30 attempts" |
| 22 | + return 1 |
| 23 | +} |
| 24 | + |
5 | 25 | echo $VERSION
|
6 | 26 | if [ -z $ENABLE_PYPI_BUILD ] || [ -z $STABLE_VERSION ]; then
|
7 |
| - echo "$0 pypi-build=enable stable=true" |
8 |
| - echo "\tpypi-build: Build and publish a new version of the package to pypi. Options are prod or test" |
9 |
| - echo "\tstable: Only build and publish a new version for the stable docker tag if it has been tested and going on the changelog" |
10 |
| - exit |
| 27 | + echo "$0 pypi-build=enable stable=true" |
| 28 | + echo "\tpypi-build: Build and publish a new version of the package to pypi. Options are prod or test" |
| 29 | + echo "\tstable: Only build and publish a new version for the stable docker tag if it has been tested and going on the changelog" |
| 30 | + exit |
11 | 31 | fi
|
12 | 32 |
|
13 | 33 | if [ $ENABLE_PYPI_BUILD = "pypi-build=prod" ]; then
|
14 |
| - echo "Doing production build" |
15 |
| - python -m build --wheel --sdist |
16 |
| - twine upload dist/*$VERSION* |
17 |
| - sleep 120 |
18 |
| - docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:$VERSION . \ |
19 |
| - && docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:latest . \ |
20 |
| - && docker push socketdev/cli:$VERSION \ |
21 |
| - && docker push socketdev/cli:latest |
| 34 | + echo "Doing production build" |
| 35 | + if ! python -m build --wheel --sdist; then |
| 36 | + echo "Build failed" |
| 37 | + exit 1 |
| 38 | + fi |
| 39 | + |
| 40 | + if ! twine upload dist/*$VERSION*; then |
| 41 | + echo "Upload to PyPI failed" |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + |
| 45 | + if ! verify_package $VERSION "https://pypi.org/simple"; then |
| 46 | + echo "Failed to verify package on PyPI" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + |
| 50 | + docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:$VERSION . \ |
| 51 | + && docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:latest . \ |
| 52 | + && docker push socketdev/cli:$VERSION \ |
| 53 | + && docker push socketdev/cli:latest |
22 | 54 | fi
|
23 | 55 |
|
24 | 56 | if [ $ENABLE_PYPI_BUILD = "pypi-build=test" ]; then
|
25 |
| - echo "Doing test build" |
26 |
| - python -m build --wheel --sdist |
27 |
| - twine upload --repository testpypi dist/*$VERSION* |
28 |
| - sleep 120 |
29 |
| - docker build --no-cache \ |
30 |
| - --build-arg CLI_VERSION=$VERSION \ |
31 |
| - --build-arg PIP_INDEX_URL=https://test.pypi.org/simple \ |
32 |
| - --build-arg PIP_EXTRA_INDEX_URL=https://pypi.org/simple \ |
33 |
| - --platform linux/amd64,linux/arm64 \ |
34 |
| - -t socketdev/cli:$VERSION-test . \ |
35 |
| - && docker build --no-cache \ |
36 |
| - --build-arg CLI_VERSION=$VERSION \ |
37 |
| - --build-arg PIP_INDEX_URL=https://test.pypi.org/simple \ |
38 |
| - --build-arg PIP_EXTRA_INDEX_URL=https://pypi.org/simple \ |
39 |
| - --platform linux/amd64,linux/arm64 \ |
40 |
| - -t socketdev/cli:test . \ |
41 |
| - && docker push socketdev/cli:$VERSION-test \ |
42 |
| - && docker push socketdev/cli:test |
| 57 | + echo "Doing test build" |
| 58 | + if ! python -m build --wheel --sdist; then |
| 59 | + echo "Build failed" |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + |
| 63 | + if ! twine upload --repository testpypi dist/*$VERSION*; then |
| 64 | + echo "Upload to TestPyPI failed" |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + |
| 68 | + if ! verify_package $VERSION "https://test.pypi.org/simple"; then |
| 69 | + echo "Failed to verify package on TestPyPI" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + |
| 73 | + docker build --no-cache \ |
| 74 | + --build-arg CLI_VERSION=$VERSION \ |
| 75 | + --build-arg PIP_INDEX_URL=https://test.pypi.org/simple \ |
| 76 | + --build-arg PIP_EXTRA_INDEX_URL=https://pypi.org/simple \ |
| 77 | + --platform linux/amd64,linux/arm64 \ |
| 78 | + -t socketdev/cli:$VERSION-test . \ |
| 79 | + && docker build --no-cache \ |
| 80 | + --build-arg CLI_VERSION=$VERSION \ |
| 81 | + --build-arg PIP_INDEX_URL=https://test.pypi.org/simple \ |
| 82 | + --build-arg PIP_EXTRA_INDEX_URL=https://pypi.org/simple \ |
| 83 | + --platform linux/amd64,linux/arm64 \ |
| 84 | + -t socketdev/cli:test . \ |
| 85 | + && docker push socketdev/cli:$VERSION-test \ |
| 86 | + && docker push socketdev/cli:test |
43 | 87 | fi
|
44 | 88 |
|
45 |
| - |
46 | 89 | if [ $STABLE_VERSION = "stable=true" ]; then
|
47 | 90 | if [ $ENABLE_PYPI_BUILD = "pypi-build=enable" ]; then
|
48 |
| - sleep 120 |
| 91 | + if ! verify_package $VERSION "https://pypi.org/simple"; then |
| 92 | + echo "Failed to verify package on PyPI" |
| 93 | + exit 1 |
| 94 | + fi |
49 | 95 | fi
|
50 | 96 | docker build --no-cache --build-arg CLI_VERSION=$VERSION --platform linux/amd64,linux/arm64 -t socketdev/cli:stable . \
|
51 |
| - && docker push socketdev/cli:stable |
52 |
| - fi |
| 97 | + && docker push socketdev/cli:stable |
| 98 | +fi |
53 | 99 |
|
0 commit comments