Fix github release action versioning

This commit is contained in:
Teal Bauer 2025-04-07 14:49:38 +02:00
parent a5c600b07f
commit 2dc1adb982
3 changed files with 37 additions and 49 deletions

View File

@ -22,47 +22,9 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Get version from pom.xml
id: get_version
run: |
VERSION=$(grep -m1 '<version>' pom.xml | sed 's/[[:space:]]*<version>\(.*\)<\/version>.*/\1/')
# Strip any suffix after version numbers (like -SNAPSHOT)
BASE_VERSION=$(echo "$VERSION" | sed 's/^\([0-9]\+\.[0-9]\+\)[^0-9].*/\1/')
echo "VERSION=$BASE_VERSION" >> $GITHUB_OUTPUT
- name: Set build version
id: set_version
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
echo "BUILD_VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "Set BUILD_VERSION to ${VERSION}"
else
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LATEST_TAG" ]; then
BASE_VERSION="${{ steps.get_version.outputs.VERSION }}"
else
BASE_VERSION="${LATEST_TAG#v}"
fi
FULL_VERSION="${BASE_VERSION}-${SHORT_SHA}-${TIMESTAMP}"
echo "BUILD_VERSION=${FULL_VERSION}" >> $GITHUB_OUTPUT
echo "Set BUILD_VERSION to ${FULL_VERSION}"
fi
- name: Update version in files
run: |
VERSION="${{ steps.set_version.outputs.BUILD_VERSION }}"
# Update pom.xml - only update the first version tag which is the project version
sed -i '0,/<version>.*<\/version>/{s/<version>.*<\/version>/<version>'"$VERSION"'<\/version>/}' pom.xml
# Update MANIFEST.MF
sed -i "s/Bundle-Version: .*/Bundle-Version: $VERSION/" src/main/resources/META-INF/MANIFEST.MF
# Update extension.properties if it has version
if grep -q "^version=" src/main/resources/extension.properties; then
sed -i "s/^version=.*/version=$VERSION/" src/main/resources/extension.properties
fi
# Removed steps that get/set/update version in files.
# pom.xml now handles determining the build identifier (tag or commit hash/timestamp)
# and uses it for artifact naming. extension.properties version remains untouched.
- name: Build with Maven
run: mvn -B package
@ -71,7 +33,9 @@ jobs:
if: github.ref_type != 'tag'
uses: actions/upload-artifact@v4
with:
name: GhydraMCP-${{ steps.set_version.outputs.BUILD_VERSION }}
# Use a generic name for nightly artifacts
name: GhydraMCP-nightly
# Path will grab both standard and complete zips generated by Maven
path: |
target/GhydraMCP-*.zip
bridge_mcp_hydra.py
@ -101,6 +65,8 @@ jobs:
with:
name: Release ${{ github.ref_name }}
body_path: ${{ steps.generate_notes.outputs.RELEASE_NOTES_FILE }}
# The files pattern will grab both standard and complete zips.
# Maven (via pom.xml) ensures they are named correctly based on the tag.
files: |
target/GhydraMCP-*.zip
bridge_mcp_hydra.py

33
pom.xml
View File

@ -17,7 +17,9 @@
<maven.deploy.skip>true</maven.deploy.skip>
<maven.install.skip>true</maven.install.skip>
<maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format>
<revision>dev-SNAPSHOT</revision>
<revision>dev-SNAPSHOT</revision> <!-- Base version, overridden below -->
<!-- Default identifier: commit hash + timestamp -->
<build.identifier>${git.commit.id.abbrev}-${maven.build.timestamp}</build.identifier>
</properties>
<dependencies>
@ -152,6 +154,24 @@
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version>
<executions>
<!-- Execution to potentially override build.identifier with tag name -->
<execution>
<id>set-identifier-from-tag</id>
<phase>initialize</phase>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>build.identifier</name>
<value>${git.closest.tag.name}</value> <!-- Use tag if available -->
<regex>^v?(.+)$</regex> <!-- Match tag, optionally strip leading 'v' -->
<replacement>$1</replacement>
<failIfNoMatch>false</failIfNoMatch> <!-- Don't fail if no tag, keeps default -->
</configuration>
</execution>
<!-- Original execution to set revision property (might still be needed elsewhere?) -->
<!-- Let's comment this out for now as build.identifier should be sufficient -->
<!--
<execution>
<id>set-revision-from-git</id>
<phase>initialize</phase>
@ -160,12 +180,13 @@
</goals>
<configuration>
<name>revision</name>
<value>${git.commit.id.abbrev}-${maven.build.timestamp}</value>
<value>${build.identifier}</value> <!-\- Set revision based on final identifier -\->
<regex>.*</regex>
<replacement>$0</replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
-->
</executions>
</plugin>
@ -180,10 +201,10 @@
</manifest>
<manifestEntries>
<Implementation-Title>GhydraMCP</Implementation-Title>
<Implementation-Version>${git.commit.id.abbrev}-${maven.build.timestamp}</Implementation-Version>
<Implementation-Version>${build.identifier}</Implementation-Version>
<Plugin-Class>eu.starsong.ghidra.GhydraMCP</Plugin-Class>
<Plugin-Name>GhydraMCP</Plugin-Name>
<Plugin-Version>${git.commit.id.abbrev}-${maven.build.timestamp}</Plugin-Version>
<Plugin-Version>${build.identifier}</Plugin-Version>
<Plugin-Author>LaurieWired, Teal Bauer</Plugin-Author>
<Plugin-Description>Expose multiple Ghidra tools to MCP servers with variable management</Plugin-Description>
</manifestEntries>
@ -213,7 +234,7 @@
<descriptors>
<descriptor>src/assembly/ghidra-extension.xml</descriptor>
</descriptors>
<finalName>GhydraMCP-${git.commit.id.abbrev}-${maven.build.timestamp}</finalName>
<finalName>GhydraMCP-${build.identifier}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
@ -229,7 +250,7 @@
<descriptors>
<descriptor>src/assembly/complete-package.xml</descriptor>
</descriptors>
<finalName>GhydraMCP-Complete-${git.commit.id.abbrev}-${maven.build.timestamp}</finalName>
<finalName>GhydraMCP-Complete-${build.identifier}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>

View File

@ -26,7 +26,8 @@
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>GhydraMCP-${project.version}.zip</include>
<!-- Use build.identifier to match the actual filename -->
<include>GhydraMCP-${build.identifier}.zip</include>
</includes>
<outputDirectory></outputDirectory>
</fileSet>