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' distribution: 'temurin'
cache: maven cache: maven
- name: Get version from pom.xml # Removed steps that get/set/update version in files.
id: get_version # pom.xml now handles determining the build identifier (tag or commit hash/timestamp)
run: | # and uses it for artifact naming. extension.properties version remains untouched.
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
- name: Build with Maven - name: Build with Maven
run: mvn -B package run: mvn -B package
@ -71,7 +33,9 @@ jobs:
if: github.ref_type != 'tag' if: github.ref_type != 'tag'
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4
with: 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: | path: |
target/GhydraMCP-*.zip target/GhydraMCP-*.zip
bridge_mcp_hydra.py bridge_mcp_hydra.py
@ -101,6 +65,8 @@ jobs:
with: with:
name: Release ${{ github.ref_name }} name: Release ${{ github.ref_name }}
body_path: ${{ steps.generate_notes.outputs.RELEASE_NOTES_FILE }} 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: | files: |
target/GhydraMCP-*.zip target/GhydraMCP-*.zip
bridge_mcp_hydra.py bridge_mcp_hydra.py

33
pom.xml
View File

@ -17,7 +17,9 @@
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
<maven.install.skip>true</maven.install.skip> <maven.install.skip>true</maven.install.skip>
<maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format> <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> </properties>
<dependencies> <dependencies>
@ -152,6 +154,24 @@
<artifactId>build-helper-maven-plugin</artifactId> <artifactId>build-helper-maven-plugin</artifactId>
<version>3.4.0</version> <version>3.4.0</version>
<executions> <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> <execution>
<id>set-revision-from-git</id> <id>set-revision-from-git</id>
<phase>initialize</phase> <phase>initialize</phase>
@ -160,12 +180,13 @@
</goals> </goals>
<configuration> <configuration>
<name>revision</name> <name>revision</name>
<value>${git.commit.id.abbrev}-${maven.build.timestamp}</value> <value>${build.identifier}</value> <!-\- Set revision based on final identifier -\->
<regex>.*</regex> <regex>.*</regex>
<replacement>$0</replacement> <replacement>$0</replacement>
<failIfNoMatch>false</failIfNoMatch> <failIfNoMatch>false</failIfNoMatch>
</configuration> </configuration>
</execution> </execution>
-->
</executions> </executions>
</plugin> </plugin>
@ -180,10 +201,10 @@
</manifest> </manifest>
<manifestEntries> <manifestEntries>
<Implementation-Title>GhydraMCP</Implementation-Title> <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-Class>eu.starsong.ghidra.GhydraMCP</Plugin-Class>
<Plugin-Name>GhydraMCP</Plugin-Name> <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-Author>LaurieWired, Teal Bauer</Plugin-Author>
<Plugin-Description>Expose multiple Ghidra tools to MCP servers with variable management</Plugin-Description> <Plugin-Description>Expose multiple Ghidra tools to MCP servers with variable management</Plugin-Description>
</manifestEntries> </manifestEntries>
@ -213,7 +234,7 @@
<descriptors> <descriptors>
<descriptor>src/assembly/ghidra-extension.xml</descriptor> <descriptor>src/assembly/ghidra-extension.xml</descriptor>
</descriptors> </descriptors>
<finalName>GhydraMCP-${git.commit.id.abbrev}-${maven.build.timestamp}</finalName> <finalName>GhydraMCP-${build.identifier}</finalName>
<appendAssemblyId>false</appendAssemblyId> <appendAssemblyId>false</appendAssemblyId>
</configuration> </configuration>
</execution> </execution>
@ -229,7 +250,7 @@
<descriptors> <descriptors>
<descriptor>src/assembly/complete-package.xml</descriptor> <descriptor>src/assembly/complete-package.xml</descriptor>
</descriptors> </descriptors>
<finalName>GhydraMCP-Complete-${git.commit.id.abbrev}-${maven.build.timestamp}</finalName> <finalName>GhydraMCP-Complete-${build.identifier}</finalName>
<appendAssemblyId>false</appendAssemblyId> <appendAssemblyId>false</appendAssemblyId>
</configuration> </configuration>
</execution> </execution>

View File

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