Skip to content

Commit e2d31f6

Browse files
committed
feat: add github actions for deployment automation
1 parent cf17c92 commit e2d31f6

File tree

8 files changed

+190
-5
lines changed

8 files changed

+190
-5
lines changed

.github/workflows/docker-stable.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Mark Release as Stable
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: 'Version to mark as stable (e.g., v1.2.3)'
7+
required: true
8+
9+
jobs:
10+
stable:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Build & Push Stable Docker
16+
uses: docker/build-push-action@v5
17+
with:
18+
push: true
19+
platforms: linux/amd64,linux/arm64
20+
tags: socketdev/cli:stable
21+
build-args: |
22+
CLI_VERSION=${{ inputs.version }}

.github/workflows/pr-preview.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: PR Preview
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
5+
6+
jobs:
7+
preview:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-python@v5
12+
with:
13+
python-version: '3.x'
14+
15+
- name: Set preview version
16+
run: |
17+
BASE_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
18+
echo "VERSION=${BASE_VERSION}.dev${GITHUB_PR_NUMBER}" >> $GITHUB_ENV
19+
20+
- name: Build package
21+
run: |
22+
pip install build
23+
python -m build
24+
25+
- name: Publish to Test PyPI
26+
uses: pypa/[email protected]
27+
with:
28+
repository-url: https://test.pypi.org/legacy/
29+
password: ${{ secrets.TEST_PYPI_TOKEN }}
30+
31+
- name: Comment on PR
32+
uses: actions/github-script@v7
33+
with:
34+
script: |
35+
const version = process.env.VERSION;
36+
const comment = `
37+
🚀 Preview package published!
38+
39+
Install with:
40+
\`\`\`bash
41+
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socketsecurity==${version}
42+
\`\`\`
43+
44+
Docker image: \`socketdev/cli:pr-${context.issue.number}\`
45+
`;
46+
47+
github.rest.issues.createComment({
48+
issue_number: context.issue.number,
49+
owner: context.repo.owner,
50+
repo: context.repo.name,
51+
body: comment
52+
})
53+
54+
- name: Build & Push Docker Preview
55+
uses: docker/build-push-action@v5
56+
with:
57+
push: true
58+
tags: socketdev/cli:pr-${{ github.event.pull_request.number }}
59+
build-args: |
60+
CLI_VERSION=${{ env.VERSION }}
61+
PIP_INDEX_URL=https://test.pypi.org/simple

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-python@v5
13+
with:
14+
python-version: '3.x'
15+
16+
- name: Build package
17+
run: |
18+
pip install build
19+
python -m build
20+
21+
- name: Publish to PyPI
22+
uses: pypa/[email protected]
23+
with:
24+
password: ${{ secrets.PYPI_TOKEN }}
25+
26+
- name: Build & Push Docker
27+
uses: docker/build-push-action@v5
28+
with:
29+
push: true
30+
platforms: linux/amd64,linux/arm64
31+
tags: |
32+
socketdev/cli:latest
33+
socketdev/cli:${{ github.ref_name }}

.github/workflows/version-check.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Version Check
2+
on:
3+
pull_request:
4+
types: [opened, synchronize]
5+
paths:
6+
- 'socketsecurity/**'
7+
- 'setup.py'
8+
- 'pyproject.toml'
9+
10+
jobs:
11+
check_version:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0 # Fetch all history for all branches
17+
18+
- name: Check version increment
19+
run: |
20+
# Get version from current PR
21+
PR_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
22+
23+
# Get version from main branch
24+
git checkout origin/main
25+
MAIN_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
26+
27+
# Compare versions using Python
28+
python3 -c "
29+
from packaging import version
30+
pr_ver = version.parse('${PR_VERSION}')
31+
main_ver = version.parse('${MAIN_VERSION}')
32+
if pr_ver <= main_ver:
33+
print(f'❌ Version must be incremented! Main: {main_ver}, PR: {pr_ver}')
34+
exit(1)
35+
print(f'✅ Version properly incremented from {main_ver} to {pr_ver}')
36+
"
37+
38+
- name: Comment on PR if version check fails
39+
if: failure()
40+
uses: actions/github-script@v7
41+
with:
42+
script: |
43+
const comment = `
44+
❌ **Version Check Failed**
45+
46+
Please increment the version number in \`socketsecurity/__init__.py\`.
47+
Current version on main: \`${process.env.MAIN_VERSION}\`
48+
Your PR version: \`${process.env.PR_VERSION}\`
49+
`;
50+
51+
github.rest.issues.createComment({
52+
issue_number: context.issue.number,
53+
owner: context.repo.owner,
54+
repo: context.repo.name,
55+
body: comment
56+
})

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ markdown_security_temp.md
1919
*.pyc
2020
test.py
2121
*.cpython-312.pyc`
22-
file_generator.py
22+
file_generator.py
23+
.env.local

Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
FROM python:3-alpine
22
LABEL org.opencontainers.image.authors="socket.dev"
33
ARG CLI_VERSION
4+
ARG PIP_INDEX_URL=https://pypi.org/simple
45
RUN apk update \
56
&& apk add --no-cache git nodejs npm yarn
6-
RUN pip install socketsecurity --upgrade \
7+
8+
RUN pip install --index-url ${PIP_INDEX_URL} socketsecurity==$CLI_VERSION \
79
&& socketcli -v \
8-
&& socketcli -v | grep -q $CLI_VERSION
10+
&& socketcli -v | grep -q $CLI_VERSION
11+
12+
# !! Uncomment to test local build - requires running `python -m build` first (and correct version number)
13+
# COPY dist/socketsecurity-1.0.34-py3-none-any.whl /tmp/
14+
# RUN pip install /tmp/socketsecurity-1.0.34-py3-none-any.whl \
15+
# && socketcli -v \
16+
# && socketcli -v | grep -q $CLI_VERSION

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ dependencies = [
1212
'prettytable',
1313
'argparse',
1414
'GitPython',
15-
'packaging'
1615
]
1716
readme = "README.md"
1817
description = "Socket Security CLI for CI/CD"
@@ -32,6 +31,11 @@ classifiers = [
3231
"Programming Language :: Python :: 3.12",
3332
]
3433

34+
[project.optional-dependencies]
35+
dev = [
36+
"packaging"
37+
]
38+
3539
[project.scripts]
3640
socketcli = "socketsecurity.socketcli:cli"
3741

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__author__ = 'socket.dev'
2-
__version__ = '1.0.32'
2+
__version__ = '1.0.36'

0 commit comments

Comments
 (0)