Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .enforcer-scripts/validate-jbang-versions.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Fetch the property from the Maven project
def scriptName = project.properties['jbang.script.name']

// Fail if the script property is missing
if (scriptName == null) {
throw new IllegalStateException("[ERROR] JBang validator: No jbang.script.name set in properties")
}

def jbangFile = new File(project.basedir, scriptName)
if (!jbangFile.exists()) {
// If a script name was explicitly provided but doesn't exist, fail.
// If using the fallback, we might want to just skip (return true).
throw new IllegalStateException("[ERROR] JBang validator: File not found: " + jbangFile.absolutePath)
}

def expectedVersion = project.version
def groupPrefix = "//DEPS io.github.a2asdk:"
def success = true

jbangFile.eachLine { line ->
if (line.trim().startsWith(groupPrefix)) {
def lastColon = line.lastIndexOf(":")
if (lastColon != -1) {
def actualVersion = line.substring(lastColon + 1).trim().tokenize()[0]
if (actualVersion != expectedVersion) {
System.err.println("[ERROR] JBang Version Mismatch in " + scriptName)
System.err.println(" Expected: " + expectedVersion)
System.err.println(" Found: " + actualVersion + " in line: \"" + line.trim() + "\"")
success = false
}
Comment on lines +24 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current version parsing logic is a bit fragile. If a line ends with a colon or has only whitespace after it, tokenize()[0] will throw an ArrayIndexOutOfBoundsException, causing the build to fail with a potentially unclear stack trace. A more robust approach would handle this case gracefully and provide a more informative error message.

            def actualVersion = line.substring(lastColon + 1).trim().tokenize().find()
            if (actualVersion != expectedVersion) {
                System.err.println("[ERROR] JBang Version Mismatch in " + scriptName)
                System.err.println("  Expected: " + expectedVersion)
                System.err.println("  Found:    " + (actualVersion ?: "<missing>") + " in line: \"" + line.trim() + "\"")
                success = false
            }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gemini-code-assist this was your idea. Come up with a final solution. We should be able to extract the version no matter what!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, tokenize() can be a bit too broad if there are non-whitespace characters immediately following the version that aren't part of the version string itself (e.g., a comma or another delimiter). To make the version extraction truly robust and handle cases like //DEPS io.github.a2asdk:artifact-id:1.0.0, some-other-info or //DEPS io.github.a2asdk:artifact-id:1.0.0-SNAPSHOT//comment, a regular expression is a more precise tool.

This updated suggestion uses a regex to explicitly capture the version string, which typically consists of alphanumeric characters, dots, and hyphens, from the beginning of the trimmed string after the last colon. It also retains the graceful handling of missing versions by printing <missing>.

Suggested change
def actualVersion = line.substring(lastColon + 1).trim().tokenize()[0]
if (actualVersion != expectedVersion) {
System.err.println("[ERROR] JBang Version Mismatch in " + scriptName)
System.err.println(" Expected: " + expectedVersion)
System.err.println(" Found: " + actualVersion + " in line: \"" + line.trim() + "\"")
success = false
}
def versionPart = line.substring(lastColon + 1).trim()
def matcher = (versionPart =~ /^([0-9a-zA-Z.-]+)/)
def actualVersion = matcher.find() ? matcher.group(1) : null
if (actualVersion != expectedVersion) {
System.err.println("[ERROR] JBang Version Mismatch in " + scriptName)
System.err.println(" Expected: " + expectedVersion)
System.err.println(" Found: " + (actualVersion ?: "<missing>") + " in line: \"" + line.trim() + "\"")
success = false
}
Suggested change
def actualVersion = line.substring(lastColon + 1).trim().tokenize()[0]
if (actualVersion != expectedVersion) {
System.err.println("[ERROR] JBang Version Mismatch in " + scriptName)
System.err.println(" Expected: " + expectedVersion)
System.err.println(" Found: " + actualVersion + " in line: \"" + line.trim() + "\"")
success = false
}
def versionPart = line.substring(lastColon + 1).trim()
def matcher = (versionPart =~ /^([0-9a-zA-Z.-]+)/)
def actualVersion = matcher.find() ? matcher.group(1) : null
if (actualVersion != expectedVersion) {
System.err.println("[ERROR] JBang Version Mismatch in " + scriptName)
System.err.println(" Expected: " + expectedVersion)
System.err.println(" Found: " + (actualVersion ?: "<missing>") + " in line: \"" + line.trim() + "\"")
success = false
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OTOH we don't have that many JBang scripts - we should just not write confusing DEPS

}
}
}

if (!success) {
throw new IllegalStateException("[ERROR] JBang version validation failed")
}
127 changes: 127 additions & 0 deletions .github/workflows/create-github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Create GitHub Release

on:
push:
tags:
- 'v?[0-9]+.[0-9]+.[0-9]+*' # Trigger on tags like v1.0.0, 1.2.3, v1.2.3.Alpha1 etc.

jobs:
create-release:
# Only run this job for the main repository, not for forks
if: github.repository == 'a2aproject/a2a-java'
runs-on: ubuntu-latest
permissions:
contents: write # Required to create releases

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for changelog generation

- name: Extract version from tag
id: version
run: |
# Remove 'v' prefix if present
VERSION=${GITHUB_REF_NAME#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"

- name: Generate release notes
id: release_notes
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.version.outputs.version }}';

// Get the previous tag
let previousTag = '';
try {
const { data: tags } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});

// Find current tag index
const currentIndex = tags.findIndex(tag => tag.name === context.ref.replace('refs/tags/', ''));

// Get previous tag (next in list)
if (currentIndex >= 0 && currentIndex < tags.length - 1) {
previousTag = tags[currentIndex + 1].name;
}
} catch (error) {
console.log('Could not fetch previous tag:', error.message);
}

// Build release notes
let releaseNotes = `## A2A Java SDK ${version}\n\n`;

// Add Maven Central installation instructions
releaseNotes += `### Installation\n\n`;
releaseNotes += `**Maven**:\n\`\`\`xml\n<dependency>\n`;
releaseNotes += ` <groupId>io.github.a2asdk</groupId>\n`;
releaseNotes += ` <artifactId>a2a-java-sdk-client</artifactId>\n`;
releaseNotes += ` <version>${version}</version>\n`;
releaseNotes += `</dependency>\n\`\`\`\n\n`;

releaseNotes += `**Gradle**:\n\`\`\`gradle\n`;
releaseNotes += `implementation 'io.github.a2asdk:a2a-java-sdk-client:${version}'\n`;
releaseNotes += `\`\`\`\n\n`;

// Add links
releaseNotes += `### Links\n\n`;
releaseNotes += `- [Maven Central](https://central.sonatype.com/artifact/io.github.a2asdk/a2a-java-sdk-parent/${version})\n`;
releaseNotes += `- [JavaDoc](https://javadoc.io/doc/io.github.a2asdk/a2a-java-sdk-parent/${version})\n`;
releaseNotes += `- [GitHub](https://github.com/a2aproject/a2a-java/tree/v${version})\n\n`;

// Add changelog header
if (previousTag) {
releaseNotes += `### Changes since ${previousTag}\n\n`;
releaseNotes += `[Full Changelog](https://github.com/a2aproject/a2a-java/compare/${previousTag}...v${version})\n\n`;
} else {
releaseNotes += `### Changes\n\n`;
}

return releaseNotes;

- name: Create GitHub Release
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.version.outputs.version }}';
const tag = context.ref.replace('refs/tags/', '');
const releaseNotes = ${{ steps.release_notes.outputs.result }};

// Determine if this is a pre-release
const isPrerelease = version.includes('Alpha') ||
version.includes('Beta') ||
version.includes('RC') ||
version.includes('SNAPSHOT');

try {
const { data: release } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: `v${version}`,
body: releaseNotes,
draft: false,
prerelease: isPrerelease,
generate_release_notes: true // GitHub will append auto-generated notes
});

console.log(`✅ Created release: ${release.html_url}`);
core.summary
.addHeading(`Release v${version} Created`)
.addLink('View Release', release.html_url)
.addLink('Maven Central', `https://central.sonatype.com/artifact/io.github.a2asdk/a2a-java-sdk-parent/${version}`)
.write();

} catch (error) {
if (error.status === 422 && error.message.includes('already_exists')) {
console.log('⚠️ Release already exists for this tag');
} else {
throw error;
}
}
Loading