Skip to content

Commit 451fe8e

Browse files
committed
final PR polish
1 parent 4eead06 commit 451fe8e

File tree

13 files changed

+664
-323
lines changed

13 files changed

+664
-323
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Click on the "Preview" tab and select appropriate PR template:
2+
3+
[New Feature](?expand=1&template=feature.md)
4+
[Bug Fix](?expand=1&template=bug-fix.md)
5+
[Improvement](?expand=1&template=improvement.md)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--Description: Briefly describe the bug and its impact. If there's a related Linear ticket or Sentry issue, link it here. ⬇️ -->
2+
3+
## Root Cause
4+
<!-- Concise explanation of what caused the bug ⬇️ -->
5+
6+
7+
8+
## Fix
9+
<!-- Explain how your changes address the bug ⬇️ -->
10+
11+
## Public Changelog
12+
<!-- Write a changelog message between comment tags if this should be included in the public product changelog, Leave blank otherwise. -->
13+
14+
<!-- changelog ⬇️-->
15+
N/A
16+
<!-- /changelog ⬆️ -->
17+
18+
## Checklist
19+
20+
- Is PR safe to revert (yes/no)?:
21+
22+
---
23+
<!-- Add any additional notes, context, or relevant links (RFCs, Slack threads, Linear tickets, etc.) below if needed. -->
24+
25+
26+
27+
28+
<!-- TEMPLATE TYPE DON'T REMOVE: depscan-template-bug-fix -->
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!-- Description: Briefly describe the new feature you're introducing ⬇️ -->
2+
3+
4+
## Why?
5+
<!-- Explain the motivation behind this feature and its expected benefits ⬇️ -->
6+
7+
8+
9+
## Public Changelog
10+
<!-- Write a changelog message between comment tags if this should be included in the public product changelog. -->
11+
12+
<!-- changelog ⬇️-->
13+
N/A
14+
<!-- /changelog ⬆️ -->
15+
16+
## Checklist
17+
18+
- Is PR safe to revert (yes/no)?:
19+
20+
---
21+
<!-- Any other context, screenshots, or specific testing instructions. If there are relevant RFCs, Slack threads, Linear tickets, etc., please link to them here. ⬇️ -->
22+
23+
24+
25+
<!-- TEMPLATE TYPE DON'T REMOVE: depscan-template-feature -->
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- Description: Briefly describe the code improvement you're making. This could include things like lint fixes, adding monitoring dashboards, optimizing scripts, refactoring, etc. ⬇️ -->
2+
3+
## Public Changelog
4+
<!-- Write a changelog message between comment tags if this should be included in the public product changelog. -->
5+
6+
<!-- changelog ⬇️-->
7+
N/A
8+
<!-- /changelog ⬆️ -->
9+
10+
## Checklist
11+
12+
- Is PR safe to revert (yes/no)?:
13+
14+
---
15+
<!-- Any other context, screenshots, or specific testing instructions. If there are relevant RFCs, Slack threads, Linear tickets, etc., please link to them here. ⬇️ -->
16+
17+
18+
19+
<!-- TEMPLATE TYPE DON'T REMOVE: depscan-template-improvement -->

.python-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.11
1+
3.12

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ ARG PIP_EXTRA_INDEX_URL=https://pypi.org/simple
88
RUN apk update \
99
&& apk add --no-cache git nodejs npm yarn
1010

11-
# Install CLI first
11+
# Install CLI and optionally override SDK version
1212
RUN pip install --index-url ${PIP_INDEX_URL} --extra-index-url ${PIP_EXTRA_INDEX_URL} socketsecurity==$CLI_VERSION \
13-
# Then override SDK version
14-
&& pip install --index-url ${PIP_INDEX_URL} --extra-index-url ${PIP_EXTRA_INDEX_URL} socket-sdk-python==${SDK_VERSION:-latest}
13+
&& if [ ! -z "$SDK_VERSION" ]; then \
14+
pip install --index-url ${PIP_INDEX_URL} --extra-index-url ${PIP_EXTRA_INDEX_URL} socket-sdk-python==${SDK_VERSION}; \
15+
fi

scripts/build_container.sh

Lines changed: 80 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,98 @@
22
VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
33
ENABLE_PYPI_BUILD=$1
44
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+
525
echo $VERSION
626
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
1131
fi
1232

1333
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
2254
fi
2355

2456
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
4387
fi
4488

45-
4689
if [ $STABLE_VERSION = "stable=true" ]; then
4790
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
4995
fi
5096
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
5399

scripts/deploy-test-docker.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/bin/sh
22

3+
# This script builds the Docker image tagged cli:test and cli:$CLI_VERSION-test and pushes them to docker hub
4+
5+
# If CLI Version and/or SDK Version are not provided, it will check TestPyPI for the latest dev versions and use that after asking the user for confirmation
6+
37
CLI_VERSION=$1
48
SDK_VERSION=$2
59

scripts/deploy-test-pypi.sh

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
# This script finds the latest dev version on TestPyPI, increments the dev version, and then uploads the new version to TestPyPI
4+
35
# Get version from __init__.py
46
INIT_FILE="socketsecurity/__init__.py"
57
ORIGINAL_VERSION=$(grep -o "__version__.*" $INIT_FILE | awk '{print $3}' | tr -d "'")
@@ -11,8 +13,10 @@ EXISTING_VERSIONS=$(curl -s https://test.pypi.org/pypi/socketsecurity/json | pyt
1113
import sys, json
1214
data = json.load(sys.stdin)
1315
versions = [v for v in data.get('releases', {}).keys() if v.startswith('$ORIGINAL_VERSION.dev')]
16+
print('Filtered versions:', versions, file=sys.stderr)
1417
if versions:
1518
versions.sort(key=lambda x: int(x.split('dev')[1]))
19+
print('Sorted versions:', versions, file=sys.stderr)
1620
print(versions[-1])
1721
")
1822

@@ -43,10 +47,14 @@ python -m build --wheel --sdist > /dev/null 2>&1
4347
mv $BACKUP_FILE $INIT_FILE
4448

4549
# Upload to TestPyPI using python -m
46-
python -m twine upload --repository testpypi dist/*${VERSION}*
47-
48-
echo "Deployed to Test PyPI. Wait a few minutes before installing the new version."
49-
echo
50-
51-
echo "New version:"
52-
echo "${VERSION}"
50+
if python -m twine upload --repository testpypi dist/*${VERSION}*; then
51+
echo
52+
echo "Deployed to Test PyPI. Wait a few minutes before installing the new version."
53+
echo
54+
echo "New version:"
55+
echo "${VERSION}"
56+
else
57+
echo
58+
echo "Failed to deploy to Test PyPI"
59+
exit 1
60+
fi

0 commit comments

Comments
 (0)