Sync JBang Catalog #2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync JBang Catalog | |
| on: | |
| schedule: | |
| # Run every 30 minutes | |
| - cron: '*/30 * * * *' | |
| workflow_dispatch: # Allow manual trigger | |
| permissions: | |
| contents: write | |
| issues: write | |
| jobs: | |
| sync-pending-updates: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Get latest release | |
| id: latest-release | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const latestRelease = await github.rest.repos.getLatestRelease({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }); | |
| const tagName = latestRelease.data.tag_name; | |
| if (!/^v\d+\.\d+\.\d+$/.test(tagName)) { | |
| console.log(`Latest release tag '${tagName}' is not a valid semver tag`); | |
| return { version: null }; | |
| } | |
| const version = tagName.replace(/^v/, ''); | |
| const createdAt = latestRelease.data.created_at; | |
| console.log(`Latest release: ${tagName} (${version})`); | |
| console.log(`Created at: ${createdAt}`); | |
| core.setOutput('version', version); | |
| core.setOutput('tag', tagName); | |
| core.setOutput('created_at', createdAt); | |
| return { version, tag: tagName, created_at: createdAt }; | |
| - name: Checkout jbang-catalog | |
| if: steps.latest-release.outputs.version != '' | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: btraceio/jbang-catalog | |
| token: ${{ secrets.JBANG_CATALOG_PAT || secrets.GITHUB_TOKEN }} | |
| path: catalog | |
| - name: Check catalog version | |
| if: steps.latest-release.outputs.version != '' | |
| id: catalog-version | |
| run: | | |
| cd catalog | |
| # Extract current stable versions from jbang-catalog.json via jq | |
| SHELL_VERSION=$(jq -r '.aliases["jafar-shell"]["script-ref"]' jbang-catalog.json | cut -d: -f3) | |
| echo "Current jafar-shell version: $SHELL_VERSION" | |
| MCP_VERSION=$(jq -r '.aliases["jfr-mcp"]["script-ref"]' jbang-catalog.json | cut -d: -f3) | |
| echo "Current jfr-mcp version: $MCP_VERSION" | |
| RELEASE_VERSION="${{ steps.latest-release.outputs.version }}" | |
| echo "Latest GitHub release version: $RELEASE_VERSION" | |
| # Check if either stable artifact needs update | |
| if [ "$SHELL_VERSION" = "$RELEASE_VERSION" ] && [ "$MCP_VERSION" = "$RELEASE_VERSION" ]; then | |
| echo "JBang catalog is up to date" | |
| echo "needs-update=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "JBang catalog needs update to version $RELEASE_VERSION" | |
| [ "$SHELL_VERSION" != "$RELEASE_VERSION" ] && echo " - jafar-shell: $SHELL_VERSION -> $RELEASE_VERSION" | |
| [ "$MCP_VERSION" != "$RELEASE_VERSION" ] && echo " - jfr-mcp: $MCP_VERSION -> $RELEASE_VERSION" | |
| echo "needs-update=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check Maven Central and release age | |
| if: steps.catalog-version.outputs.needs-update == 'true' | |
| id: process | |
| run: | | |
| VERSION="${{ steps.latest-release.outputs.version }}" | |
| TAG="${{ steps.latest-release.outputs.tag }}" | |
| CREATED_AT="${{ steps.latest-release.outputs.created_at }}" | |
| SHELL_URL="https://repo1.maven.org/maven2/io/btrace/jafar-shell/${VERSION}/jafar-shell-${VERSION}.pom" | |
| MCP_URL="https://repo1.maven.org/maven2/io/btrace/jfr-mcp/${VERSION}/jfr-mcp-${VERSION}.pom" | |
| echo "Processing update for version $VERSION" | |
| echo "Release created at: $CREATED_AT" | |
| # Calculate age of release | |
| RELEASE_TIMESTAMP=$(date -d "$CREATED_AT" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$CREATED_AT" +%s) | |
| CURRENT_TIMESTAMP=$(date +%s) | |
| AGE_HOURS=$(( ($CURRENT_TIMESTAMP - $RELEASE_TIMESTAMP) / 3600 )) | |
| echo "Release age: ${AGE_HOURS} hours" | |
| # Check Maven Central availability (3 attempts with short delays) | |
| MAX_ATTEMPTS=3 | |
| AVAILABLE=false | |
| echo "🔍 Checking Maven Central availability..." | |
| # Check both jafar-shell and jfr-mcp | |
| for ARTIFACT_URL in "$SHELL_URL" "$MCP_URL"; do | |
| ARTIFACT_NAME=$(echo "$ARTIFACT_URL" | grep -o 'jafar-shell\|jfr-mcp') | |
| echo "Checking $ARTIFACT_NAME..." | |
| ATTEMPT=1 | |
| ARTIFACT_AVAILABLE=false | |
| while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do | |
| echo " Attempt $ATTEMPT/$MAX_ATTEMPTS: $ARTIFACT_URL" | |
| HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$ARTIFACT_URL") | |
| if [ "$HTTP_CODE" = "200" ]; then | |
| echo " ✅ $ARTIFACT_NAME is available!" | |
| ARTIFACT_AVAILABLE=true | |
| break | |
| fi | |
| echo " ⏳ Not yet available (HTTP $HTTP_CODE)" | |
| sleep 10 | |
| ATTEMPT=$((ATTEMPT + 1)) | |
| done | |
| if [ "$ARTIFACT_AVAILABLE" = "false" ]; then | |
| echo " ❌ $ARTIFACT_NAME not available after $MAX_ATTEMPTS attempts" | |
| AVAILABLE=false | |
| break | |
| fi | |
| done | |
| # If both artifacts are available, mark as available | |
| if [ "$ARTIFACT_AVAILABLE" = "true" ]; then | |
| AVAILABLE=true | |
| fi | |
| # Determine action based on availability and age | |
| if [ "$AVAILABLE" = "true" ]; then | |
| echo "Action: UPDATE_CATALOG" | |
| echo "action=update" >> $GITHUB_OUTPUT | |
| elif [ $AGE_HOURS -ge 24 ]; then | |
| echo "⚠️ Maven Central sync failed after 24 hours" | |
| echo "Action: CREATE_ISSUE" | |
| echo "action=create_issue" >> $GITHUB_OUTPUT | |
| else | |
| echo "⏳ Still waiting for Maven Central sync (${AGE_HOURS}h < 24h)" | |
| echo "Action: WAIT" | |
| echo "action=wait" >> $GITHUB_OUTPUT | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "created_at=$CREATED_AT" >> $GITHUB_OUTPUT | |
| echo "age_hours=$AGE_HOURS" >> $GITHUB_OUTPUT | |
| echo "artifact_url=$ARTIFACT_URL" >> $GITHUB_OUTPUT | |
| - name: Update catalog files | |
| if: steps.process.outputs.action == 'update' | |
| run: | | |
| VERSION="${{ steps.process.outputs.version }}" | |
| cd catalog | |
| # Update stable aliases in jbang-catalog.json via jq | |
| jq --arg ver "$VERSION" '.aliases["jafar-shell"]["script-ref"] = "io.btrace:jafar-shell:\($ver)"' jbang-catalog.json > tmp.json && mv tmp.json jbang-catalog.json | |
| jq --arg ver "$VERSION" '.aliases["jfr-mcp"]["script-ref"] = "io.btrace:jfr-mcp:\($ver)"' jbang-catalog.json > tmp.json && mv tmp.json jbang-catalog.json | |
| # Update jafar-shell.java stable wrapper | |
| sed -i.bak "s|//DEPS io.btrace:jafar-shell:.*|//DEPS io.btrace:jafar-shell:$VERSION|g" jafar-shell.java | |
| # Clean up backup files | |
| rm -f *.bak | |
| # Show changes | |
| echo "Changes to be committed:" | |
| git diff | |
| - name: Commit and push catalog updates | |
| if: steps.process.outputs.action == 'update' | |
| run: | | |
| VERSION="${{ steps.process.outputs.version }}" | |
| cd catalog | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Stage all modified catalog files | |
| git add jbang-catalog.json jafar-shell.java | |
| if git commit -m "Update jafar-shell and jfr-mcp to $VERSION"; then | |
| if git push; then | |
| echo "✅ Successfully updated JBang catalog to version $VERSION" | |
| else | |
| echo "❌ Failed to push catalog updates" | |
| exit 1 | |
| fi | |
| else | |
| echo "⚠️ No changes to commit" | |
| fi | |
| - name: Create issue for failed Maven Central sync | |
| if: steps.process.outputs.action == 'create_issue' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const version = '${{ steps.process.outputs.version }}'; | |
| const tag = '${{ steps.process.outputs.tag }}'; | |
| const createdAt = '${{ steps.process.outputs.created_at }}'; | |
| const ageHours = '${{ steps.process.outputs.age_hours }}'; | |
| const artifactUrl = '${{ steps.process.outputs.artifact_url }}'; | |
| const body = `## Maven Central Sync Failure | |
| The release \`${version}\` was published over 24 hours ago, but the artifact is still not available on Maven Central. | |
| **Details:** | |
| - Version: \`${version}\` | |
| - Tag: \`${tag}\` | |
| - Release created: ${createdAt} | |
| - Age: ${ageHours} hours | |
| - Artifact: \`io.btrace:jafar-shell:${version}\` | |
| **Expected URL:** | |
| ${artifactUrl} | |
| **Actions required:** | |
| 1. Check [Sonatype Central Portal](https://central.sonatype.com/publishing) for publishing status | |
| 2. Verify the artifact was successfully uploaded | |
| 3. Check for any validation errors or rejections | |
| 4. Once resolved, the \`sync-jbang-catalog\` workflow will automatically update the JBang catalog on its next run | |
| **Related:** | |
| - Release: https://github.com/${{ github.repository }}/releases/tag/${tag} | |
| This issue was automatically created by the \`sync-jbang-catalog\` workflow.`; | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `Maven Central sync failed for ${tag}`, | |
| body: body, | |
| labels: ['release', 'maven-central'] | |
| }); |