Skip to content

Merge branch 'hackvertor-master' #2

Merge branch 'hackvertor-master'

Merge branch 'hackvertor-master' #2

Workflow file for this run

name: Release on Version Change
on:
push:
branches:
- master
- main
paths:
- 'src/main/java/burp/hv/HackvertorExtension.java'
workflow_dispatch:
inputs:
force_release:
description: 'Force release even if version unchanged'
required: false
default: false
type: boolean
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract_version.outputs.version }}
version_changed: ${{ steps.check_version.outputs.changed }}
tag_exists: ${{ steps.check_tag.outputs.tag_exists }}
commits: ${{ steps.get_commits.outputs.commits }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract current version
id: extract_version
run: |
VERSION=$(grep -E '^\s*public static String version = "v[0-9]+\.[0-9]+\.[0-9]+";' src/main/java/burp/hv/HackvertorExtension.java | sed -E 's/.*"(v[0-9]+\.[0-9]+\.[0-9]+)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Current version: $VERSION"
- name: Check if version changed
id: check_version
run: |
# Get the previous version from the last commit
git show HEAD~1:src/main/java/burp/hv/HackvertorExtension.java > prev_file.java 2>/dev/null || echo "File not found in previous commit"
if [ -f prev_file.java ]; then
PREV_VERSION=$(grep -E '^\s*public static String version = "v[0-9]+\.[0-9]+\.[0-9]+";' prev_file.java | sed -E 's/.*"(v[0-9]+\.[0-9]+\.[0-9]+)".*/\1/' || echo "none")
else
PREV_VERSION="none"
fi
CURRENT_VERSION="${{ steps.extract_version.outputs.version }}"
echo "Previous version: $PREV_VERSION"
echo "Current version: $CURRENT_VERSION"
FORCE_RELEASE="${{ github.event.inputs.force_release }}"
if [ "$FORCE_RELEASE" == "true" ]; then
echo "Force release requested via manual trigger"
echo "changed=true" >> $GITHUB_OUTPUT
elif [ "$PREV_VERSION" != "$CURRENT_VERSION" ]; then
echo "Version changed from $PREV_VERSION to $CURRENT_VERSION"
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "Version unchanged"
echo "changed=false" >> $GITHUB_OUTPUT
fi
- name: Check if tag exists
if: steps.check_version.outputs.changed == 'true'
id: check_tag
run: |
VERSION="${{ steps.extract_version.outputs.version }}"
if git rev-parse "$VERSION" >/dev/null 2>&1; then
echo "Tag $VERSION already exists, skipping release"
echo "tag_exists=true" >> $GITHUB_OUTPUT
else
echo "Tag $VERSION does not exist, proceeding with release"
echo "tag_exists=false" >> $GITHUB_OUTPUT
fi
- name: Get commits since last version
if: steps.check_version.outputs.changed == 'true' && steps.check_tag.outputs.tag_exists != 'true'
id: get_commits
run: |
LAST_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s" "$LAST_TAG"..HEAD --max-count=10)
else
COMMITS=$(git log --pretty=format:"- %s" --max-count=10)
fi
echo "commits<<EOF" >> $GITHUB_OUTPUT
echo "$COMMITS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
build-and-release:
needs: check-version
if: needs.check-version.outputs.version_changed == 'true' && needs.check-version.outputs.tag_exists != 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Setup virtual display for UI tests
run: |
sudo apt-get update
sudo apt-get install -y xvfb
export DISPLAY=:99
Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
echo "DISPLAY=:99" >> $GITHUB_ENV
- name: Run all tests
run: |
echo "Running all tests before release..."
# Run tests with virtual display
xvfb-run -a ./gradlew test --info
if [ $? -ne 0 ]; then
echo "Tests failed! Aborting release."
exit 1
fi
echo "All tests passed successfully!"
- name: Build with Gradle
run: ./gradlew shadowJar
- name: List build artifacts
run: |
echo "Contents of releases directory:"
ls -la releases/ || echo "releases directory not found"
- name: Get JAR filename
id: get_jar
run: |
# The JAR is output to releases/ directory according to build.gradle
JAR_FILE="releases/hackvertor-all.jar"
if [ ! -f "$JAR_FILE" ]; then
echo "Error: JAR file not found at $JAR_FILE"
echo "Checking releases directory:"
ls -la releases/ || echo "releases directory not found"
exit 1
fi
JAR_NAME=$(basename "$JAR_FILE")
echo "jar_file=$JAR_FILE" >> $GITHUB_OUTPUT
echo "jar_name=$JAR_NAME" >> $GITHUB_OUTPUT
echo "Found JAR: $JAR_NAME at $JAR_FILE"
- name: Rename JAR for release
run: |
cp "${{ steps.get_jar.outputs.jar_file }}" "hackvertor-${{ needs.check-version.outputs.version }}.jar"
echo "Release JAR created: hackvertor-${{ needs.check-version.outputs.version }}.jar"
- name: Create Release and Upload Asset
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.check-version.outputs.version }}
name: Hackvertor ${{ needs.check-version.outputs.version }}
body: |
## Hackvertor ${{ needs.check-version.outputs.version }}
### Installation
Download the JAR file below and add it to Burp Suite via:
- Extender/Extensions tab → Add → Select the downloaded JAR file
### Changes
${{ needs.check-version.outputs.commits }}
draft: false
prerelease: false
files: |
hackvertor-${{ needs.check-version.outputs.version }}.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update CHANGELOG.md
env:
VERSION: ${{ needs.check-version.outputs.version }}
COMMITS: ${{ needs.check-version.outputs.commits }}
run: |
DATE=$(date +%Y-%m-%d)
if [ -f CHANGELOG.md ]; then
{
head -n 2 CHANGELOG.md
echo "## Version $VERSION ($DATE)"
echo ""
echo "$COMMITS"
echo ""
tail -n +3 CHANGELOG.md
} > CHANGELOG.md.new
mv CHANGELOG.md.new CHANGELOG.md
else
{
echo "# Changelog"
echo ""
echo "## Version $VERSION ($DATE)"
echo ""
echo "$COMMITS"
} > CHANGELOG.md
fi
- name: Commit and push CHANGELOG.md
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add CHANGELOG.md
git diff --staged --quiet || git commit -m "Update CHANGELOG.md for ${{ needs.check-version.outputs.version }}"
git push
cleanup-old-releases:
needs: build-and-release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Delete old releases
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
// Get all releases sorted by created date (newest first)
const releases = await github.rest.repos.listReleases({
owner,
repo,
per_page: 100
});
console.log(`Found ${releases.data.length} total releases`);
// Keep only the 5 most recent releases
const maxReleases = 5;
if (releases.data.length > maxReleases) {
// Sort releases by created_at date (newest first)
const sortedReleases = releases.data.sort((a, b) =>
new Date(b.created_at) - new Date(a.created_at)
);
// Get releases to delete (all except the most recent 5)
const releasesToDelete = sortedReleases.slice(maxReleases);
console.log(`Keeping ${maxReleases} most recent releases`);
console.log(`Deleting ${releasesToDelete.length} old releases`);
for (const release of releasesToDelete) {
try {
console.log(`Deleting release: ${release.name} (${release.tag_name})`);
// Delete the release
await github.rest.repos.deleteRelease({
owner,
repo,
release_id: release.id
});
// Delete the associated tag
try {
await github.rest.git.deleteRef({
owner,
repo,
ref: `tags/${release.tag_name}`
});
console.log(`Deleted tag: ${release.tag_name}`);
} catch (tagError) {
console.log(`Could not delete tag ${release.tag_name}: ${tagError.message}`);
}
} catch (error) {
console.error(`Failed to delete release ${release.name}: ${error.message}`);
}
}
console.log('Cleanup completed');
} else {
console.log(`Only ${releases.data.length} releases exist, no cleanup needed`);
}