Skip to content

Commit 8eea8b4

Browse files
committed
Generate plugin repo YAML in CI
1 parent c81caec commit 8eea8b4

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Generate plugin repository YAML file for CF CLI plugin repository.
4+
This script creates the YAML file in the required format for the CF CLI plugin repository.
5+
"""
6+
7+
import os
8+
import sys
9+
import yaml
10+
import hashlib
11+
import requests
12+
from datetime import datetime
13+
from pathlib import Path
14+
15+
def calculate_sha1(file_path):
16+
"""Calculate SHA1 checksum of a file."""
17+
sha1_hash = hashlib.sha1()
18+
with open(file_path, "rb") as f:
19+
for chunk in iter(lambda: f.read(4096), b""):
20+
sha1_hash.update(chunk)
21+
return sha1_hash.hexdigest()
22+
23+
def get_version_from_tag():
24+
"""Get version from git tag or environment variable."""
25+
version = os.environ.get('GITHUB_REF_NAME', '')
26+
if version.startswith('v'):
27+
version = version[1:] # Remove 'v' prefix
28+
return version or "dev"
29+
30+
def generate_plugin_repo_yaml():
31+
"""Generate the plugin repository YAML file."""
32+
version = get_version_from_tag()
33+
repo_url = "https://github.com/SAP/cf-cli-java-plugin"
34+
35+
# Define the binary platforms and their corresponding file extensions
36+
platforms = {
37+
"osx": "cf-cli-java-plugin-osx",
38+
"win64": "cf-cli-java-plugin-win64.exe",
39+
"win32": "cf-cli-java-plugin-win32.exe",
40+
"linux32": "cf-cli-java-plugin-linux32",
41+
"linux64": "cf-cli-java-plugin-linux64"
42+
}
43+
44+
binaries = []
45+
dist_dir = Path("dist")
46+
47+
for platform, filename in platforms.items():
48+
file_path = dist_dir / filename
49+
if file_path.exists():
50+
checksum = calculate_sha1(file_path)
51+
binary_info = {
52+
"checksum": checksum,
53+
"platform": platform,
54+
"url": f"{repo_url}/releases/download/v{version}/{filename}"
55+
}
56+
binaries.append(binary_info)
57+
print(f"Added {platform}: {filename} (checksum: {checksum})")
58+
else:
59+
print(f"Warning: Binary not found for {platform}: {filename}")
60+
61+
if not binaries:
62+
print("Error: No binaries found in dist/ directory")
63+
sys.exit(1)
64+
65+
# Create the plugin repository entry
66+
plugin_entry = {
67+
"authors": [{
68+
"contact": "[email protected]",
69+
"homepage": "https://github.com/SAP",
70+
"name": "Johannes Bechberger"
71+
}],
72+
"binaries": binaries,
73+
"company": "SAP",
74+
"created": "2024-01-01T00:00:00Z", # Initial creation date
75+
"description": "Plugin for profiling Java applications and getting heap and thread-dumps",
76+
"homepage": repo_url,
77+
"name": "java",
78+
"updated": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
79+
"version": version
80+
}
81+
82+
# Write the YAML file
83+
output_file = Path("plugin-repo-entry.yml")
84+
with open(output_file, 'w') as f:
85+
yaml.dump(plugin_entry, f, default_flow_style=False, sort_keys=False)
86+
87+
print(f"Generated plugin repository YAML file: {output_file}")
88+
print(f"Version: {version}")
89+
print(f"Binaries: {len(binaries)} platforms")
90+
91+
# Also create a human-readable summary
92+
summary_file = Path("plugin-repo-summary.txt")
93+
with open(summary_file, 'w') as f:
94+
f.write(f"CF CLI Java Plugin Repository Entry\n")
95+
f.write(f"====================================\n\n")
96+
f.write(f"Version: {version}\n")
97+
f.write(f"Updated: {plugin_entry['updated']}\n")
98+
f.write(f"Binaries: {len(binaries)} platforms\n\n")
99+
f.write("Platform checksums:\n")
100+
for binary in binaries:
101+
f.write(f" {binary['platform']}: {binary['checksum']}\n")
102+
f.write(f"\nRepository URL: {repo_url}\n")
103+
f.write(f"Release URL: {repo_url}/releases/tag/v{version}\n")
104+
105+
print(f"Generated summary file: {summary_file}")
106+
107+
if __name__ == "__main__":
108+
generate_plugin_repo_yaml()

.github/workflows/plugin-repo.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Generate Plugin Repository Entry
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
generate-plugin-repo:
9+
name: Generate Plugin Repository YAML
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install Python dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install PyYAML requests
25+
26+
- name: Download release assets
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
mkdir -p dist
31+
# Download all release assets
32+
gh release download ${{ github.event.release.tag_name }} -D dist/
33+
34+
- name: Generate plugin repository YAML
35+
env:
36+
GITHUB_REF_NAME: ${{ github.event.release.tag_name }}
37+
run: python3 .github/workflows/generate_plugin_repo.py
38+
39+
- name: Upload plugin repository files to release
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
run: |
43+
gh release upload ${{ github.event.release.tag_name }} plugin-repo-entry.yml plugin-repo-summary.txt
44+
45+
- name: Create PR to plugin repository (optional)
46+
env:
47+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48+
run: |
49+
echo "Plugin repository entry generated!"
50+
echo "To submit to CF CLI plugin repository:"
51+
echo "1. Fork https://github.com/cloudfoundry-incubator/cli-plugin-repo"
52+
echo "2. Add the contents of plugin-repo-entry.yml to repo-index.yml"
53+
echo "3. Create a pull request"
54+
echo ""
55+
echo "Entry content:"
56+
cat plugin-repo-entry.yml

0 commit comments

Comments
 (0)