Skip to content
Merged
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
91 changes: 62 additions & 29 deletions .github/workflows/build-and-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,7 @@ jobs:
with:
python-version: "3.11"

- name: Check if Python tests exist
id: check-tests
run: |
if [ -f "test/requirements.txt" ] && [ -f "test/test.sh" ]; then
echo "tests_exist=true" >> $GITHUB_OUTPUT
echo "✅ Python test suite found"
else
echo "tests_exist=false" >> $GITHUB_OUTPUT
echo "⚠️ Python test suite not found - skipping tests"
fi

- name: Setup Python test environment
if: steps.check-tests.outputs.tests_exist == 'true'
run: |
cd test
python -m venv venv
Expand All @@ -46,21 +34,11 @@ jobs:
python -m pip install -r requirements.txt

- name: Run Python linting
if: steps.check-tests.outputs.tests_exist == 'true'
run: |
cd test
source venv/bin/activate
../scripts/lint-python.sh ci

# - name: Run Python tests
# if: steps.check-tests.outputs.tests_exist == 'true'
# run: |
# cd testing
# source venv/bin/activate
# echo "🧪 Running Python tests..."
# pytest -v --tb=short
# echo "✅ Python tests completed!"

build:
name: Build and Test Go Plugin
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -106,6 +84,19 @@ jobs:
if: (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') && (needs.lint-and-test-python.result == 'success' || needs.lint-and-test-python.result == 'skipped')

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Python dependencies for plugin repo generation
run: |
python -m pip install --upgrade pip
pip install PyYAML

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -116,6 +107,22 @@ jobs:
mkdir -p dist
mv dist/*/* dist/ || true

- name: Generate plugin repository YAML for snapshot
env:
GITHUB_REF_NAME: snapshot
run: |
echo "📝 Generating plugin repository YAML file..."
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip
pip install PyYAML requests
python3 .github/workflows/generate_plugin_repo.py
echo "✅ Plugin repository YAML generated"

- name: Generate timestamp
id: timestamp
run: echo "timestamp=$(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_OUTPUT

- uses: thomashampson/delete-older-releases@main
with:
keep_latest: 0
Expand All @@ -125,24 +132,50 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete and regenerate tag snapshot
run: |
echo "Deleting existing snapshot tag..."
git tag -d snapshot || true
git push origin :snapshot || true
echo "Regenerating snapshot tag..."
git tag snapshot
git push origin snapshot --force

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
files: |
dist/*
plugin-repo-entry.yml
plugin-repo-summary.txt
prerelease: false
release: false
draft: false
tag_name: snapshot
body: |
This is a snapshot release of the cf-cli-java-plugin.
It includes the latest changes and is not intended for production use.
Please test it and provide feedback.

## Build Status
- ✅ Go Plugin: Built and tested on Linux, macOS, and Windows
- ✅ Python Tests: Linting and test suite validation completed
**Build Timestamp**: ${{ steps.timestamp.outputs.timestamp }}

## Installation

Download the current snapshot release and install manually:

```sh
# on Mac arm64
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/snapshot/cf-cli-java-plugin-macos-arm64
# on Windows x86
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/snapshot/cf-cli-java-plugin-windows-amd64
# on Linux x86
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/snapshot/cf-cli-java-plugin-linux-amd64
```

**Note:** On Linux and macOS, if you get a permission error, run `chmod +x [cf-cli-java-plugin]` on the plugin binary.
On Windows, the plugin will refuse to install unless the binary has the `.exe` file extension.

## Changes
This snapshot includes the latest commits from the repository.
You can verify that the plugin is successfully installed by looking for `java` in the output of `cf plugins`.

name: Snapshot Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
106 changes: 106 additions & 0 deletions .github/workflows/generate_plugin_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env python3
"""
Generate plugin repository YAML file for CF CLI plugin repository.
This script creates the YAML file in the required format for the CF CLI plugin repository.
"""

import os
import sys
import yaml
import hashlib
import requests
from datetime import datetime
from pathlib import Path

def calculate_sha1(file_path):
"""Calculate SHA1 checksum of a file."""
sha1_hash = hashlib.sha1()
with open(file_path, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
sha1_hash.update(chunk)
return sha1_hash.hexdigest()

def get_version_from_tag():
"""Get version from git tag or environment variable."""
version = os.environ.get('GITHUB_REF_NAME', '')
if version.startswith('v'):
version = version[1:] # Remove 'v' prefix
return version or "dev"

def generate_plugin_repo_yaml():
"""Generate the plugin repository YAML file."""
version = get_version_from_tag()
repo_url = "https://github.com/SAP/cf-cli-java-plugin"

# Define the binary platforms and their corresponding file extensions
platforms = {
"linux64": "cf-cli-java-plugin-linux-amd64",
"osx": "cf-cli-java-plugin-macos-arm64",
"win64": "cf-cli-java-plugin-windows-amd64"
}

binaries = []
dist_dir = Path("dist")

for platform, filename in platforms.items():
file_path = dist_dir / filename
if file_path.exists():
checksum = calculate_sha1(file_path)
binary_info = {
"checksum": checksum,
"platform": platform,
"url": f"{repo_url}/releases/download/v{version}/{filename}"
}
binaries.append(binary_info)
print(f"Added {platform}: {filename} (checksum: {checksum})")
else:
print(f"Warning: Binary not found for {platform}: {filename}")

if not binaries:
print("Error: No binaries found in dist/ directory")
sys.exit(1)

# Create the plugin repository entry
plugin_entry = {
"authors": [{
"contact": "johannes.bechberger@sap.com",
"homepage": "https://github.com/SAP",
"name": "Johannes Bechberger"
}],
"binaries": binaries,
"company": "SAP",
"created": "2024-01-01T00:00:00Z", # Initial creation date
"description": "Plugin for profiling Java applications and getting heap and thread-dumps",
"homepage": repo_url,
"name": "java",
"updated": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
"version": version
}

# Write the YAML file
output_file = Path("plugin-repo-entry.yml")
with open(output_file, 'w') as f:
yaml.dump(plugin_entry, f, default_flow_style=False, sort_keys=False)

print(f"Generated plugin repository YAML file: {output_file}")
print(f"Version: {version}")
print(f"Binaries: {len(binaries)} platforms")

# Also create a human-readable summary
summary_file = Path("plugin-repo-summary.txt")
with open(summary_file, 'w') as f:
f.write(f"CF CLI Java Plugin Repository Entry\n")
f.write(f"====================================\n\n")
f.write(f"Version: {version}\n")
f.write(f"Updated: {plugin_entry['updated']}\n")
f.write(f"Binaries: {len(binaries)} platforms\n\n")
f.write("Platform checksums:\n")
for binary in binaries:
f.write(f" {binary['platform']}: {binary['checksum']}\n")
f.write(f"\nRepository URL: {repo_url}\n")
f.write(f"Release URL: {repo_url}/releases/tag/v{version}\n")

print(f"Generated summary file: {summary_file}")

if __name__ == "__main__":
generate_plugin_repo_yaml()
56 changes: 56 additions & 0 deletions .github/workflows/plugin-repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Generate Plugin Repository Entry

on:
release:
types: [published]

jobs:
generate-plugin-repo:
name: Generate Plugin Repository YAML
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install PyYAML requests

- name: Download release assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p dist
# Download all release assets
gh release download ${{ github.event.release.tag_name }} -D dist/

- name: Generate plugin repository YAML
env:
GITHUB_REF_NAME: ${{ github.event.release.tag_name }}
run: python3 .github/workflows/generate_plugin_repo.py

- name: Upload plugin repository files to release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload ${{ github.event.release.tag_name }} plugin-repo-entry.yml plugin-repo-summary.txt

- name: Create PR to plugin repository (optional)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Plugin repository entry generated!"
echo "To submit to CF CLI plugin repository:"
echo "1. Fork https://github.com/cloudfoundry-incubator/cli-plugin-repo"
echo "2. Add the contents of plugin-repo-entry.yml to repo-index.yml"
echo "3. Create a pull request"
echo ""
echo "Entry content:"
cat plugin-repo-entry.yml
Loading