diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 04850f4..d063f40 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,10 @@ jobs: - name: Clean up old distribution run: bash clean_package.sh + - name: Determine Package Version + id: get_version + run: echo "PKG_VERSION=$(bash get_version.sh)" >> $GITHUB_ENV + - name: Build distribution run: bash build_package.sh @@ -26,7 +30,7 @@ jobs: uses: softprops/action-gh-release@v1 with: files: dist/* - name: Release ${{ github.ref_name }} of ${{ github.repository }} - body: This is the release of ${{ github.repository }} for version ${{ github.ref_name }} + name: Release ${{ env.PKG_VERSION }} of ${{ github.repository }} + body: This is the release of ${{ github.repository }} for version ${{ env.PKG_VERSION }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/build_package.sh b/build_package.sh index b2dab30..7b725b3 100755 --- a/build_package.sh +++ b/build_package.sh @@ -7,7 +7,12 @@ python -m pip install --upgrade pip setuptools wheel echo "Cleaning up previous builds..." rm -rf build/ dist/ *.egg-info -echo "Building the package..." +echo "Determining package version..." +# Use get_version.sh to determine the package version +PKG_VERSION=$(./get_version.sh) +export PKG_VERSION + +echo "Building the package with version $PKG_VERSION..." python setup.py sdist bdist_wheel echo "Build output:" diff --git a/get_version.sh b/get_version.sh new file mode 100755 index 0000000..46e9d7f --- /dev/null +++ b/get_version.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# This script determines the current package version based on Git tags and commits. + +set -e # Exit immediately in case of error, do not ignore errors + +# Determine the package version from Git +current_commit=$(git rev-parse HEAD) +latest_tag_commit=$(git rev-list -n 1 --tags --abbrev=0) + +if [ "$current_commit" == "$latest_tag_commit" ]; then + PKG_VERSION=$(git describe --tags --abbrev=0) +else + commit_hash=$(git rev-parse --short HEAD) + date=$(date +%Y%m%d) + PKG_VERSION="0.0.1.dev${date}+${commit_hash}" +fi + +echo $PKG_VERSION diff --git a/setup.py b/setup.py index f878ba9..e41c9d6 100755 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +import os from setuptools import setup, find_packages with open('README.md', 'r', encoding='utf-8') as fh: @@ -5,7 +6,7 @@ setup( name="ps_fuzz", - version="1.0.0", + version=os.getenv('PKG_VERSION', '0.0.1'), author="Prompt Security", author_email="support@prompt.security", description="LLM and System Prompt vulnerability scanner tool",