Skip to content

Commit d925f1f

Browse files
committed
cleaned up comment behavior, updated release and stable
1 parent 7a389af commit d925f1f

File tree

4 files changed

+129
-26
lines changed

4 files changed

+129
-26
lines changed

.github/workflows/docker-stable.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
workflow_dispatch:
44
inputs:
55
version:
6-
description: 'Version to mark as stable (e.g., v1.2.3)'
6+
description: 'Version to mark as stable (e.g., 1.2.3)'
77
required: true
88

99
jobs:
@@ -12,6 +12,15 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v4
1414

15+
- name: Check if version exists in PyPI
16+
id: version_check
17+
run: |
18+
if ! curl -s -f https://pypi.org/pypi/socketsecurity/${{ inputs.version }}/json > /dev/null; then
19+
echo "Error: Version ${{ inputs.version }} not found on PyPI"
20+
exit 1
21+
fi
22+
echo "Version ${{ inputs.version }} found on PyPI - proceeding with release"
23+
1524
- name: Login to Docker Hub
1625
uses: docker/login-action@v3
1726
with:

.github/workflows/pr-preview.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,17 @@ jobs:
7373
const prNumber = context.payload.pull_request.number;
7474
const owner = context.repo.owner;
7575
const repo = context.repo.repo;
76+
// Find existing bot comments
77+
const comments = await github.rest.issues.listComments({
78+
owner: context.repo.owner,
79+
repo: context.repo.repo,
80+
issue_number: prNumber,
81+
});
7682
77-
// Log the values for debugging
78-
console.log("Owner:", context.repo.owner);
79-
console.log("Repo:", context.repo.repo);
80-
console.log("Context Repo:", JSON.stringify(context.repo, null, 2));
83+
const botComment = comments.data.find(comment =>
84+
comment.user.type === 'Bot' &&
85+
comment.body.includes('🚀 Preview package published!')
86+
);
8187
8288
const comment = `
8389
🚀 Preview package published!
@@ -90,12 +96,23 @@ jobs:
9096
Docker image: \`socketdev/cli:pr-${prNumber}\`
9197
`;
9298
93-
github.rest.issues.createComment({
94-
owner: owner,
95-
repo: repo,
96-
issue_number: prNumber,
97-
body: comment
98-
});
99+
if (botComment) {
100+
// Update existing comment
101+
await github.rest.issues.updateComment({
102+
owner: owner,
103+
repo: repo,
104+
comment_id: botComment.id,
105+
body: comment
106+
});
107+
} else {
108+
// Create new comment
109+
await github.rest.issues.createComment({
110+
owner: owner,
111+
repo: repo,
112+
issue_number: prNumber,
113+
body: comment
114+
});
115+
}
99116
100117
- name: Verify package is available
101118
if: steps.version_check.outputs.exists != 'true'

.github/workflows/release.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ jobs:
1313
with:
1414
python-version: '3.x'
1515

16+
- name: Get Version
17+
id: version
18+
run: |
19+
RAW_VERSION=$(python -c "from socketsecurity import __version__; print(__version__)")
20+
echo "VERSION=$RAW_VERSION" >> $GITHUB_ENV
21+
if [ "v$RAW_VERSION" != "${{ github.ref_name }}" ]; then
22+
echo "Error: Git tag (${{ github.ref_name }}) does not match package version (v$RAW_VERSION)"
23+
exit 1
24+
fi
25+
26+
- name: Check if version exists on PyPI
27+
id: version_check
28+
env:
29+
VERSION: ${{ env.VERSION }}
30+
run: |
31+
if curl -s -f https://pypi.org/pypi/socketsecurity/$VERSION/json > /dev/null; then
32+
echo "Error: Version ${VERSION} already exists on PyPI"
33+
exit 1
34+
else
35+
echo "Version ${VERSION} not found on PyPI - proceeding with release"
36+
fi
37+
1638
- name: Build package
1739
run: |
1840
pip install build
@@ -29,11 +51,32 @@ jobs:
2951
username: ${{ secrets.DOCKERHUB_USERNAME }}
3052
password: ${{ secrets.DOCKERHUB_TOKEN }}
3153

54+
- name: Verify package is available
55+
id: verify_package
56+
env:
57+
VERSION: ${{ env.VERSION }}
58+
run: |
59+
for i in {1..30}; do
60+
if pip install socketsecurity==${VERSION}; then
61+
echo "Package ${VERSION} is now available and installable on PyPI"
62+
pip uninstall -y socketsecurity
63+
echo "success=true" >> $GITHUB_OUTPUT
64+
exit 0
65+
fi
66+
echo "Attempt $i: Package not yet installable, waiting 20s... (${i}/30)"
67+
sleep 20
68+
done
69+
echo "success=false" >> $GITHUB_OUTPUT
70+
exit 1
71+
3272
- name: Build & Push Docker
73+
if: steps.verify_package.outputs.success == 'true'
3374
uses: docker/build-push-action@v5
75+
env:
76+
VERSION: ${{ env.VERSION }}
3477
with:
3578
push: true
3679
platforms: linux/amd64,linux/arm64
3780
tags: |
3881
socketdev/cli:latest
39-
socketdev/cli:${{ github.ref_name }}
82+
socketdev/cli:${{ env.VERSION }}

.github/workflows/version-check.yml

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ jobs:
1616
fetch-depth: 0 # Fetch all history for all branches
1717

1818
- name: Check version increment
19+
id: version_check
1920
run: |
2021
# Get version from current PR
2122
PR_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
23+
echo "PR_VERSION=$PR_VERSION" >> $GITHUB_ENV
2224
2325
# Get version from main branch
2426
git checkout origin/main
2527
MAIN_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
28+
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
2629
2730
# Compare versions using Python
2831
python3 -c "
@@ -35,22 +38,53 @@ jobs:
3538
print(f'✅ Version properly incremented from {main_ver} to {pr_ver}')
3639
"
3740
38-
- name: Comment on PR if version check fails
39-
if: failure()
41+
- name: Manage PR Comment
4042
uses: actions/github-script@v7
43+
if: always()
44+
env:
45+
MAIN_VERSION: ${{ env.MAIN_VERSION }}
46+
PR_VERSION: ${{ env.PR_VERSION }}
47+
CHECK_RESULT: ${{ steps.version_check.outcome }}
4148
with:
4249
script: |
43-
const comment = `
44-
❌ **Version Check Failed**
50+
const success = process.env.CHECK_RESULT === 'success';
51+
const prNumber = context.payload.pull_request.number;
52+
const owner = context.repo.owner;
53+
const repo = context.repo.repo;
54+
const comments = await github.rest.issues.listComments({
55+
owner: owner,
56+
repo: repo,
57+
issue_number: prNumber,
58+
});
4559
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-
`;
60+
const versionComment = comments.data.find(comment =>
61+
comment.user.type === 'Bot' &&
62+
comment.body.includes('Version Check')
63+
);
5064
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-
})
65+
if (versionComment) {
66+
if (success) {
67+
// Delete the warning comment if check passes
68+
await github.rest.issues.deleteComment({
69+
owner: owner,
70+
repo: repo,
71+
comment_id: versionComment.id
72+
});
73+
} else {
74+
// Update existing warning
75+
await github.rest.issues.updateComment({
76+
owner: owner,
77+
repo: repo,
78+
comment_id: versionComment.id,
79+
body: `❌ **Version Check Failed**\n\nPlease increment...`
80+
});
81+
}
82+
} else if (!success) {
83+
// Create new warning comment only if check fails
84+
await github.rest.issues.createComment({
85+
owner: owner,
86+
repo: repo,
87+
issue_number: prNumber,
88+
body: `❌ **Version Check Failed**\n\nPlease increment...`
89+
});
90+
}

0 commit comments

Comments
 (0)