Skip to content

Commit 40592b7

Browse files
authored
Improve the CI to create proper releases and YML for the cf repo (#48)
* Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Generate plugin repo YAML in CI * Update version script * Update version script * Update version script * Update version script * Update version script * Update version script * Update version script * Update version script
1 parent db3b08d commit 40592b7

File tree

5 files changed

+548
-32
lines changed

5 files changed

+548
-32
lines changed

.github/workflows/build-and-snapshot.yml

Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@ jobs:
2525
with:
2626
python-version: "3.11"
2727

28-
- name: Check if Python tests exist
29-
id: check-tests
30-
run: |
31-
if [ -f "test/requirements.txt" ] && [ -f "test/test.sh" ]; then
32-
echo "tests_exist=true" >> $GITHUB_OUTPUT
33-
echo "✅ Python test suite found"
34-
else
35-
echo "tests_exist=false" >> $GITHUB_OUTPUT
36-
echo "⚠️ Python test suite not found - skipping tests"
37-
fi
38-
3928
- name: Setup Python test environment
40-
if: steps.check-tests.outputs.tests_exist == 'true'
4129
run: |
4230
cd test
4331
python -m venv venv
@@ -46,21 +34,11 @@ jobs:
4634
python -m pip install -r requirements.txt
4735
4836
- name: Run Python linting
49-
if: steps.check-tests.outputs.tests_exist == 'true'
5037
run: |
5138
cd test
5239
source venv/bin/activate
5340
../scripts/lint-python.sh ci
5441
55-
# - name: Run Python tests
56-
# if: steps.check-tests.outputs.tests_exist == 'true'
57-
# run: |
58-
# cd testing
59-
# source venv/bin/activate
60-
# echo "🧪 Running Python tests..."
61-
# pytest -v --tb=short
62-
# echo "✅ Python tests completed!"
63-
6442
build:
6543
name: Build and Test Go Plugin
6644
runs-on: ${{ matrix.os }}
@@ -106,6 +84,19 @@ jobs:
10684
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')
10785

10886
steps:
87+
- name: Checkout code
88+
uses: actions/checkout@v4
89+
90+
- name: Set up Python
91+
uses: actions/setup-python@v4
92+
with:
93+
python-version: "3.11"
94+
95+
- name: Install Python dependencies for plugin repo generation
96+
run: |
97+
python -m pip install --upgrade pip
98+
pip install PyYAML
99+
109100
- name: Download all artifacts
110101
uses: actions/download-artifact@v4
111102
with:
@@ -116,6 +107,22 @@ jobs:
116107
mkdir -p dist
117108
mv dist/*/* dist/ || true
118109
110+
- name: Generate plugin repository YAML for snapshot
111+
env:
112+
GITHUB_REF_NAME: snapshot
113+
run: |
114+
echo "📝 Generating plugin repository YAML file..."
115+
python3 -m venv venv
116+
source venv/bin/activate
117+
python3 -m pip install --upgrade pip
118+
pip install PyYAML requests
119+
python3 .github/workflows/generate_plugin_repo.py
120+
echo "✅ Plugin repository YAML generated"
121+
122+
- name: Generate timestamp
123+
id: timestamp
124+
run: echo "timestamp=$(date -u +'%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_OUTPUT
125+
119126
- uses: thomashampson/delete-older-releases@main
120127
with:
121128
keep_latest: 0
@@ -125,24 +132,50 @@ jobs:
125132
env:
126133
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
127134

135+
- name: Delete and regenerate tag snapshot
136+
run: |
137+
echo "Deleting existing snapshot tag..."
138+
git tag -d snapshot || true
139+
git push origin :snapshot || true
140+
echo "Regenerating snapshot tag..."
141+
git tag snapshot
142+
git push origin snapshot --force
143+
128144
- name: Create GitHub Release
129145
uses: softprops/action-gh-release@v1
130146
with:
131-
files: dist/*
147+
files: |
148+
dist/*
149+
plugin-repo-entry.yml
150+
plugin-repo-summary.txt
132151
prerelease: false
133-
release: false
152+
draft: false
134153
tag_name: snapshot
135154
body: |
136155
This is a snapshot release of the cf-cli-java-plugin.
137156
It includes the latest changes and is not intended for production use.
138157
Please test it and provide feedback.
139158
140-
## Build Status
141-
- ✅ Go Plugin: Built and tested on Linux, macOS, and Windows
142-
- ✅ Python Tests: Linting and test suite validation completed
159+
**Build Timestamp**: ${{ steps.timestamp.outputs.timestamp }}
160+
161+
## Installation
162+
163+
Download the current snapshot release and install manually:
164+
165+
```sh
166+
# on Mac arm64
167+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/snapshot/cf-cli-java-plugin-macos-arm64
168+
# on Windows x86
169+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/snapshot/cf-cli-java-plugin-windows-amd64
170+
# on Linux x86
171+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/snapshot/cf-cli-java-plugin-linux-amd64
172+
```
173+
174+
**Note:** On Linux and macOS, if you get a permission error, run `chmod +x [cf-cli-java-plugin]` on the plugin binary.
175+
On Windows, the plugin will refuse to install unless the binary has the `.exe` file extension.
143176
144-
## Changes
145-
This snapshot includes the latest commits from the repository.
177+
You can verify that the plugin is successfully installed by looking for `java` in the output of `cf plugins`.
178+
146179
name: Snapshot Release
147180
env:
148181
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
"linux64": "cf-cli-java-plugin-linux-amd64",
38+
"osx": "cf-cli-java-plugin-macos-arm64",
39+
"win64": "cf-cli-java-plugin-windows-amd64"
40+
}
41+
42+
binaries = []
43+
dist_dir = Path("dist")
44+
45+
for platform, filename in platforms.items():
46+
file_path = dist_dir / filename
47+
if file_path.exists():
48+
checksum = calculate_sha1(file_path)
49+
binary_info = {
50+
"checksum": checksum,
51+
"platform": platform,
52+
"url": f"{repo_url}/releases/download/v{version}/{filename}"
53+
}
54+
binaries.append(binary_info)
55+
print(f"Added {platform}: {filename} (checksum: {checksum})")
56+
else:
57+
print(f"Warning: Binary not found for {platform}: {filename}")
58+
59+
if not binaries:
60+
print("Error: No binaries found in dist/ directory")
61+
sys.exit(1)
62+
63+
# Create the plugin repository entry
64+
plugin_entry = {
65+
"authors": [{
66+
"contact": "johannes.bechberger@sap.com",
67+
"homepage": "https://github.com/SAP",
68+
"name": "Johannes Bechberger"
69+
}],
70+
"binaries": binaries,
71+
"company": "SAP",
72+
"created": "2024-01-01T00:00:00Z", # Initial creation date
73+
"description": "Plugin for profiling Java applications and getting heap and thread-dumps",
74+
"homepage": repo_url,
75+
"name": "java",
76+
"updated": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
77+
"version": version
78+
}
79+
80+
# Write the YAML file
81+
output_file = Path("plugin-repo-entry.yml")
82+
with open(output_file, 'w') as f:
83+
yaml.dump(plugin_entry, f, default_flow_style=False, sort_keys=False)
84+
85+
print(f"Generated plugin repository YAML file: {output_file}")
86+
print(f"Version: {version}")
87+
print(f"Binaries: {len(binaries)} platforms")
88+
89+
# Also create a human-readable summary
90+
summary_file = Path("plugin-repo-summary.txt")
91+
with open(summary_file, 'w') as f:
92+
f.write(f"CF CLI Java Plugin Repository Entry\n")
93+
f.write(f"====================================\n\n")
94+
f.write(f"Version: {version}\n")
95+
f.write(f"Updated: {plugin_entry['updated']}\n")
96+
f.write(f"Binaries: {len(binaries)} platforms\n\n")
97+
f.write("Platform checksums:\n")
98+
for binary in binaries:
99+
f.write(f" {binary['platform']}: {binary['checksum']}\n")
100+
f.write(f"\nRepository URL: {repo_url}\n")
101+
f.write(f"Release URL: {repo_url}/releases/tag/v{version}\n")
102+
103+
print(f"Generated summary file: {summary_file}")
104+
105+
if __name__ == "__main__":
106+
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)