Skip to content

Commit

Permalink
cleaned up comment behavior, updated release and stable
Browse files Browse the repository at this point in the history
  • Loading branch information
flowstate committed Nov 7, 2024
1 parent 7a389af commit d925f1f
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 26 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/docker-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Version to mark as stable (e.g., v1.2.3)'
description: 'Version to mark as stable (e.g., 1.2.3)'
required: true

jobs:
Expand All @@ -12,6 +12,15 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Check if version exists in PyPI
id: version_check
run: |
if ! curl -s -f https://pypi.org/pypi/socketsecurity/${{ inputs.version }}/json > /dev/null; then
echo "Error: Version ${{ inputs.version }} not found on PyPI"
exit 1
fi
echo "Version ${{ inputs.version }} found on PyPI - proceeding with release"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
Expand Down
37 changes: 27 additions & 10 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ jobs:
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
// Find existing bot comments
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
// Log the values for debugging
console.log("Owner:", context.repo.owner);
console.log("Repo:", context.repo.repo);
console.log("Context Repo:", JSON.stringify(context.repo, null, 2));
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('🚀 Preview package published!')
);
const comment = `
🚀 Preview package published!
Expand All @@ -90,12 +96,23 @@ jobs:
Docker image: \`socketdev/cli:pr-${prNumber}\`
`;
github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: prNumber,
body: comment
});
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: owner,
repo: repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: prNumber,
body: comment
});
}
- name: Verify package is available
if: steps.version_check.outputs.exists != 'true'
Expand Down
45 changes: 44 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ jobs:
with:
python-version: '3.x'

- name: Get Version
id: version
run: |
RAW_VERSION=$(python -c "from socketsecurity import __version__; print(__version__)")
echo "VERSION=$RAW_VERSION" >> $GITHUB_ENV
if [ "v$RAW_VERSION" != "${{ github.ref_name }}" ]; then
echo "Error: Git tag (${{ github.ref_name }}) does not match package version (v$RAW_VERSION)"
exit 1
fi
- name: Check if version exists on PyPI
id: version_check
env:
VERSION: ${{ env.VERSION }}
run: |
if curl -s -f https://pypi.org/pypi/socketsecurity/$VERSION/json > /dev/null; then
echo "Error: Version ${VERSION} already exists on PyPI"
exit 1
else
echo "Version ${VERSION} not found on PyPI - proceeding with release"
fi
- name: Build package
run: |
pip install build
Expand All @@ -29,11 +51,32 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Verify package is available
id: verify_package
env:
VERSION: ${{ env.VERSION }}
run: |
for i in {1..30}; do
if pip install socketsecurity==${VERSION}; then
echo "Package ${VERSION} is now available and installable on PyPI"
pip uninstall -y socketsecurity
echo "success=true" >> $GITHUB_OUTPUT
exit 0
fi
echo "Attempt $i: Package not yet installable, waiting 20s... (${i}/30)"
sleep 20
done
echo "success=false" >> $GITHUB_OUTPUT
exit 1
- name: Build & Push Docker
if: steps.verify_package.outputs.success == 'true'
uses: docker/build-push-action@v5
env:
VERSION: ${{ env.VERSION }}
with:
push: true
platforms: linux/amd64,linux/arm64
tags: |
socketdev/cli:latest
socketdev/cli:${{ github.ref_name }}
socketdev/cli:${{ env.VERSION }}
62 changes: 48 additions & 14 deletions .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ jobs:
fetch-depth: 0 # Fetch all history for all branches

- name: Check version increment
id: version_check
run: |
# Get version from current PR
PR_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
echo "PR_VERSION=$PR_VERSION" >> $GITHUB_ENV
# Get version from main branch
git checkout origin/main
MAIN_VERSION=$(grep -o "__version__.*" socketsecurity/__init__.py | awk '{print $3}' | tr -d "'")
echo "MAIN_VERSION=$MAIN_VERSION" >> $GITHUB_ENV
# Compare versions using Python
python3 -c "
Expand All @@ -35,22 +38,53 @@ jobs:
print(f'✅ Version properly incremented from {main_ver} to {pr_ver}')
"
- name: Comment on PR if version check fails
if: failure()
- name: Manage PR Comment
uses: actions/github-script@v7
if: always()
env:
MAIN_VERSION: ${{ env.MAIN_VERSION }}
PR_VERSION: ${{ env.PR_VERSION }}
CHECK_RESULT: ${{ steps.version_check.outcome }}
with:
script: |
const comment = `
❌ **Version Check Failed**
const success = process.env.CHECK_RESULT === 'success';
const prNumber = context.payload.pull_request.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
const comments = await github.rest.issues.listComments({
owner: owner,
repo: repo,
issue_number: prNumber,
});
Please increment the version number in \`socketsecurity/__init__.py\`.
Current version on main: \`${process.env.MAIN_VERSION}\`
Your PR version: \`${process.env.PR_VERSION}\`
`;
const versionComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Version Check')
);
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.name,
body: comment
})
if (versionComment) {
if (success) {
// Delete the warning comment if check passes
await github.rest.issues.deleteComment({
owner: owner,
repo: repo,
comment_id: versionComment.id
});
} else {
// Update existing warning
await github.rest.issues.updateComment({
owner: owner,
repo: repo,
comment_id: versionComment.id,
body: `❌ **Version Check Failed**\n\nPlease increment...`
});
}
} else if (!success) {
// Create new warning comment only if check fails
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: prNumber,
body: `❌ **Version Check Failed**\n\nPlease increment...`
});
}

0 comments on commit d925f1f

Please sign in to comment.