Skip to content

Commit d33ea17

Browse files
authored
Fixed documentation and version checks (#7)
1 parent 1f418da commit d33ea17

File tree

9 files changed

+3090
-12
lines changed

9 files changed

+3090
-12
lines changed

.hooks/version-check.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,24 @@
2929
PYPROJECT_FILE = pathlib.Path("pyproject.toml")
3030
README_FILES = [
3131
pathlib.Path("README.md"),
32+
pathlib.Path("blog.md"),
3233
pathlib.Path("docs/github-action.md"),
3334
pathlib.Path("docs/pre-commit-hook.md"),
35+
pathlib.Path("docs/local-install-docker.md"),
36+
pathlib.Path("docs/version-management.md"),
37+
pathlib.Path("docs/parameters.md"),
3438
]
3539

3640
VERSION_PATTERN = re.compile(r"__version__\s*=\s*['\"]([^'\"]+)['\"]")
3741
PYPROJECT_PATTERN = re.compile(r'^version\s*=\s*"([^"]+)"$', re.MULTILINE)
3842
# Pattern to match SocketDev/[email protected] or @vX.X.X
3943
ACTION_VERSION_PATTERN = re.compile(r'(SocketDev/socket-basics|socket-basics)@v\d+\.\d+\.\d+')
40-
# Pattern to match docker build with version tag
41-
DOCKER_BUILD_PATTERN = re.compile(r'docker build -t (socketdev/socket-basics|socket-basics)(?::\d+\.\d+\.\d+)?')
44+
# Pattern to match docker build with optional version tag (handles both new and existing tags)
45+
DOCKER_BUILD_PATTERN = re.compile(r'docker build (?:--platform [^\s]+ )?-t ([^\s:]+)(?::\d+\.\d+\.\d+)?')
46+
# Pattern to match docker run commands with version tags
47+
DOCKER_RUN_PATTERN = re.compile(r'(docker run [^\n]*?)([^\s:]+):(\d+\.\d+\.\d+)')
48+
# Pattern to match standalone image references with version (in docker run or other contexts)
49+
IMAGE_VERSION_PATTERN = re.compile(r'\b(socket-basics|socketdev/socket-basics|myorg/security-scanner):(\d+\.\d+\.\d+)\b')
4250
# Update this URL to match your actual PyPI package if you publish it
4351
PYPI_API = "https://pypi.org/pypi/security-wrapper/json"
4452

@@ -113,10 +121,15 @@ def update_readme_versions(version: str):
113121
content = ACTION_VERSION_PATTERN.sub(rf'\1@v{version}', content)
114122

115123
# Update docker build commands to include version tag
116-
def docker_replacement(match):
124+
def docker_build_replacement(match):
125+
# Group 0 is the whole match, group 1 is the image name
126+
prefix = match.group(0).split('-t')[0] + '-t '
117127
image_name = match.group(1)
118-
return f'docker build -t {image_name}:{version}'
119-
content = DOCKER_BUILD_PATTERN.sub(docker_replacement, content)
128+
return f'{prefix}{image_name}:{version}'
129+
content = DOCKER_BUILD_PATTERN.sub(docker_build_replacement, content)
130+
131+
# Update standalone image references with version (e.g., socket-basics:1.0.2)
132+
content = IMAGE_VERSION_PATTERN.sub(rf'\1:{version}', content)
120133

121134
if content != original_content:
122135
readme_file.write_text(content)

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@v4
2424

2525
- name: Run Socket Basics
26-
uses: SocketDev/[email protected].3
26+
uses: SocketDev/[email protected].4
2727
with:
2828
github_token: ${{ secrets.GITHUB_TOKEN }}
2929
socket_security_api_key: ${{ secrets.SOCKET_SECURITY_API_KEY }}
@@ -106,7 +106,7 @@ Configure scanning policies, notification channels, and rule sets for your entir
106106

107107
**Dashboard-Configured (Enterprise):**
108108
```yaml
109-
- uses: SocketDev/[email protected].3
109+
- uses: SocketDev/[email protected].4
110110
with:
111111
github_token: ${{ secrets.GITHUB_TOKEN }}
112112
socket_security_api_key: ${{ secrets.SOCKET_SECURITY_API_KEY }}
@@ -115,7 +115,7 @@ Configure scanning policies, notification channels, and rule sets for your entir
115115

116116
**CLI-Configured:**
117117
```yaml
118-
- uses: SocketDev/[email protected].3
118+
- uses: SocketDev/[email protected].4
119119
with:
120120
github_token: ${{ secrets.GITHUB_TOKEN }}
121121
python_sast_enabled: 'true'
@@ -129,10 +129,10 @@ Configure scanning policies, notification channels, and rule sets for your entir
129129

130130
```bash
131131
# Build with version tag
132-
docker build -t socketdev/socket-basics:1.0.3 .
132+
docker build -t socketdev/socket-basics:1.0.4 .
133133
134134
# Run scan
135-
docker run --rm -v "$PWD:/workspace" socketdev/socket-basics:1.0.3 \
135+
docker run --rm -v "$PWD:/workspace" socketdev/socket-basics:1.0.4 \
136136
--workspace /workspace \
137137
--python-sast-enabled \
138138
--secret-scanning-enabled \

0 commit comments

Comments
 (0)