Skip to content

Commit 49156d4

Browse files
authored
Eric/cus 9 - Socket CLI v2 (#50)
* update CLI to v2
1 parent c2a8b51 commit 49156d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+197943
-1978
lines changed

Diff for: .github/PULL_REQUEST_TEMPLATE.md

+5
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)

Diff for: .github/PULL_REQUEST_TEMPLATE/bug-fix.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
19+
<!-- TEMPLATE TYPE DON'T REMOVE: python-cli-template-bug-fix -->

Diff for: .github/PULL_REQUEST_TEMPLATE/feature.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<!-- TEMPLATE TYPE DON'T REMOVE: python-cli-template-feature -->

Diff for: .github/PULL_REQUEST_TEMPLATE/improvement.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
<!-- TEMPLATE TYPE DON'T REMOVE: python-cli-template-improvement -->

Diff for: .github/workflows/pr-preview.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: PR Preview
22
on:
33
pull_request:
4-
types: [opened, synchronize]
4+
types: [opened, synchronize, ready_for_review]
55

66
jobs:
77
preview:
@@ -12,9 +12,15 @@ jobs:
1212
with:
1313
python-version: '3.x'
1414

15+
# Install all dependencies from pyproject.toml
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install -e .
20+
1521
- name: Set preview version
1622
run: |
17-
BASE_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
23+
BASE_VERSION=$(python -c "from socketsecurity import __version__; print(__version__)")
1824
PREVIEW_VERSION="${BASE_VERSION}.dev${{ github.event.pull_request.number }}${{ github.event.pull_request.commits }}"
1925
echo "VERSION=${PREVIEW_VERSION}" >> $GITHUB_ENV
2026
@@ -25,7 +31,7 @@ jobs:
2531
2632
# Verify the change
2733
echo "Updated version in __init__.py:"
28-
cat socketsecurity/__init__.py | grep "__version__"
34+
python -c "from socketsecurity import __version__; print(__version__)"
2935
3036
- name: Check if version exists on Test PyPI
3137
id: version_check

Diff for: .github/workflows/release.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ jobs:
1313
with:
1414
python-version: '3.x'
1515

16+
# Install all dependencies from pyproject.toml
17+
- name: Install dependencies
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install -e .
21+
1622
- name: Get Version
1723
id: version
1824
run: |
@@ -104,4 +110,4 @@ jobs:
104110
socketdev/cli:latest
105111
socketdev/cli:${{ env.VERSION }}
106112
build-args: |
107-
CLI_VERSION=${{ env.VERSION }}
113+
CLI_VERSION=${{ env.VERSION }}

Diff for: .github/workflows/version-check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Version Check
22
on:
33
pull_request:
4-
types: [opened, synchronize]
4+
types: [opened, synchronize, ready_for_review]
55
paths:
66
- 'socketsecurity/**'
77
- 'setup.py'

Diff for: .gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ dist
66
*.build
77
*.dist
88
*.egg-info
9-
test
109
*.env
1110
run_container.sh
1211
*.zip
1312
bin
1413
scripts/*.py
1514
*.json
15+
!tests/**/*.json
1616
markdown_overview_temp.md
1717
markdown_security_temp.md
1818
.DS_Store
1919
*.pyc
2020
test.py
2121
*.cpython-312.pyc`
2222
file_generator.py
23-
.env.local
23+
.coverage
24+
.env.local
25+
Pipfile

Diff for: .python-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

Diff for: Dockerfile

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
FROM python:3-alpine
22
LABEL org.opencontainers.image.authors="socket.dev"
33
ARG CLI_VERSION
4+
ARG SDK_VERSION
45
ARG PIP_INDEX_URL=https://pypi.org/simple
56
ARG PIP_EXTRA_INDEX_URL=https://pypi.org/simple
67

78
RUN apk update \
89
&& apk add --no-cache git nodejs npm yarn
910

10-
RUN pip install --index-url ${PIP_INDEX_URL} --extra-index-url ${PIP_EXTRA_INDEX_URL} socketsecurity==$CLI_VERSION \
11-
&& socketcli -v \
12-
&& socketcli -v | grep -q $CLI_VERSION
11+
# Install CLI with retries for TestPyPI propagation (10 attempts, 30s each = 5 minutes total)
12+
RUN for i in $(seq 1 10); do \
13+
echo "Attempt $i/10: Installing socketsecurity==$CLI_VERSION"; \
14+
if pip install --index-url ${PIP_INDEX_URL} --extra-index-url ${PIP_EXTRA_INDEX_URL} socketsecurity==$CLI_VERSION; then \
15+
break; \
16+
fi; \
17+
echo "Install failed, waiting 30s before retry..."; \
18+
sleep 30; \
19+
done && \
20+
if [ ! -z "$SDK_VERSION" ]; then \
21+
pip install --index-url ${PIP_INDEX_URL} --extra-index-url ${PIP_EXTRA_INDEX_URL} socket-sdk-python==${SDK_VERSION}; \
22+
fi

Diff for: Makefile

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.PHONY: setup compile-deps sync-deps clean test lint init-tools local-dev first-time-setup update-deps dev-setup sync-all first-time-local-setup
2+
3+
# Environment variable for local SDK path (optional)
4+
SOCKET_SDK_PATH ?= ../socket-sdk-python
5+
6+
# Environment variable to control local development mode
7+
USE_LOCAL_SDK ?= false
8+
9+
# === High-level workflow targets ===
10+
11+
# First-time repo setup after cloning (using PyPI packages)
12+
first-time-setup: clean setup
13+
14+
# First-time setup for local development (using local SDK)
15+
first-time-local-setup:
16+
$(MAKE) clean
17+
$(MAKE) USE_LOCAL_SDK=true dev-setup
18+
19+
# Update dependencies after changing pyproject.toml
20+
update-deps: compile-deps sync-deps
21+
22+
# Setup for local development
23+
dev-setup: clean local-dev setup
24+
25+
# Sync all dependencies after pulling changes
26+
sync-all: sync-deps
27+
28+
# === Implementation targets ===
29+
30+
# Creates virtual environment and installs pip-tools
31+
init-tools:
32+
python -m venv .venv
33+
. .venv/bin/activate && pip install pip-tools
34+
35+
# Installs dependencies needed for local development
36+
# Currently: socket-sdk-python from test PyPI or local path
37+
local-dev: init-tools
38+
ifeq ($(USE_LOCAL_SDK),true)
39+
. .venv/bin/activate && pip install -e $(SOCKET_SDK_PATH)
40+
endif
41+
42+
# Creates/updates requirements.txt files with locked versions based on pyproject.toml
43+
compile-deps: local-dev
44+
. .venv/bin/activate && pip-compile --output-file=requirements.txt pyproject.toml
45+
. .venv/bin/activate && pip-compile --extra=dev --output-file=requirements-dev.txt pyproject.toml
46+
. .venv/bin/activate && pip-compile --extra=test --output-file=requirements-test.txt pyproject.toml
47+
48+
# Creates virtual environment and installs dependencies from pyproject.toml
49+
setup: compile-deps
50+
. .venv/bin/activate && pip install -e ".[dev,test]"
51+
52+
# Installs exact versions from requirements.txt into your virtual environment
53+
sync-deps:
54+
. .venv/bin/activate && pip-sync requirements.txt requirements-dev.txt requirements-test.txt
55+
ifeq ($(USE_LOCAL_SDK),true)
56+
. .venv/bin/activate && pip install -e $(SOCKET_SDK_PATH)
57+
endif
58+
59+
# Removes virtual environment and cache files
60+
clean:
61+
rm -rf .venv
62+
find . -type d -name "__pycache__" -exec rm -rf {} +
63+
64+
test:
65+
pytest
66+
67+
lint:
68+
ruff check .
69+
ruff format --check .

Diff for: Pipfile

-16
This file was deleted.

0 commit comments

Comments
 (0)