Skip to content

Commit 995af63

Browse files
authored
Refactoring (#49)
* Refactor and add more linters * Simpler refactoring than before due to bugs * Fix spelling, grammar and small refactorings * Try to fix the CI * Improve README
1 parent d8cd08d commit 995af63

30 files changed

+1507
-540
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
lint-and-test-python:
15-
name: Python Test Suite
15+
name: Lint Python Test Suite
1616
runs-on: ubuntu-latest
1717
if: github.event_name == 'pull_request' || github.event_name == 'push'
1818

@@ -38,6 +38,7 @@ jobs:
3838
cd test
3939
source venv/bin/activate
4040
../scripts/lint-python.sh ci
41+
- name: Python test
4142

4243
build:
4344
name: Build and Test Go Plugin
@@ -59,12 +60,13 @@ jobs:
5960
- name: Install dependencies
6061
run: go mod tidy -e || true
6162

62-
- name: Lint Go files
63-
run: |
64-
echo "🔍 Running go fmt..."
65-
go fmt .
66-
echo "🔍 Running go vet..."
67-
go vet .
63+
- name: Run golangci-lint
64+
uses: golangci/golangci-lint-action@v8
65+
with:
66+
version: latest
67+
68+
- name: Lint and format Go files
69+
run: ./scripts/lint-go.sh ci
6870

6971
- name: Build binary
7072
run: |

.github/workflows/generate_plugin_repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def generate_plugin_repo_yaml():
4949
binary_info = {
5050
"checksum": checksum,
5151
"platform": platform,
52-
"url": f"{repo_url}/releases/download/v{version}/{filename}"
52+
"url": f"{repo_url}/releases/download/{version}/{filename}"
5353
}
5454
binaries.append(binary_info)
5555
print(f"Added {platform}: {filename} (checksum: {checksum})")

.github/workflows/pr-validation.yml

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

28+
- name: Set up Node.js for markdownlint
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: "18"
32+
2833
- name: Install Go dependencies
2934
run: go mod tidy -e || true
3035

36+
- name: Run golangci-lint
37+
uses: golangci/golangci-lint-action@v8
38+
with:
39+
version: latest
40+
3141
- name: Lint Go code
3242
run: ./scripts/lint-go.sh ci
3343

@@ -55,6 +65,9 @@ jobs:
5565
if: steps.check-python.outputs.python_tests_exist == 'true'
5666
run: ./scripts/lint-python.sh ci
5767

68+
- name: Lint Markdown files
69+
run: ./scripts/lint-markdown.sh ci
70+
5871
# TODO: Re-enable Python tests when ready
5972
# - name: Run Python tests
6073
# if: steps.check-python.outputs.python_tests_exist == 'true'
@@ -90,6 +103,7 @@ jobs:
90103
echo "=================================="
91104
echo "✅ Go code formatting and linting"
92105
echo "✅ Go tests"
106+
echo "✅ Markdown formatting and linting"
93107
if [ "${{ steps.check-python.outputs.python_tests_exist }}" == "true" ]; then
94108
echo "✅ Python code quality checks"
95109
echo "✅ Python tests"

.github/workflows/release.yml

Lines changed: 6 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ jobs:
4343
- name: Install dependencies
4444
run: go mod tidy -e || true
4545

46+
- name: Run golangci-lint
47+
uses: golangci/golangci-lint-action@v8
48+
with:
49+
version: latest
50+
4651
- name: Lint Go files
4752
run: ./scripts/lint-go.sh ci
4853

@@ -151,59 +156,7 @@ jobs:
151156
dist/*
152157
plugin-repo-entry.yml
153158
plugin-repo-summary.txt
154-
body: |
155-
## CF CLI Java Plugin ${{ github.event.inputs.version }}
156-
157-
Plugin for profiling Java applications and getting heap and thread-dumps.
158-
159-
## Changes
160-
161-
$(cat release_changelog.txt || echo "No changelog available")
162-
163-
## Installation
164-
165-
### Installation via CF Community Repository
166-
167-
Make sure you have the CF Community plugin repository configured or add it via:
168-
```bash
169-
cf add-plugin-repo CF-Community http://plugins.cloudfoundry.org
170-
```
171-
172-
Trigger installation of the plugin via:
173-
```bash
174-
cf install-plugin -r CF-Community "java"
175-
```
176-
177-
### Manual Installation
178-
179-
Download this specific release (${{ github.event.inputs.version }}) and install manually:
180-
181-
```bash
182-
# on Mac arm64
183-
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/${{ github.event.inputs.version }}/cf-cli-java-plugin-macos-arm64
184-
# on Windows x86
185-
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/${{ github.event.inputs.version }}/cf-cli-java-plugin-windows-amd64
186-
# on Linux x86
187-
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/${{ github.event.inputs.version }}/cf-cli-java-plugin-linux-amd64
188-
```
189-
190-
Or download the latest release:
191-
192-
```bash
193-
# on Mac arm64
194-
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/latest/download/cf-cli-java-plugin-macos-arm64
195-
# on Windows x86
196-
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/latest/download/cf-cli-java-plugin-windows-amd64
197-
# on Linux x86
198-
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/latest/download/cf-cli-java-plugin-linux-amd64
199-
```
200-
201-
**Note:** On Linux and macOS, if you get a permission error, run `chmod +x [cf-cli-java-plugin]` on the plugin binary.
202-
On Windows, the plugin will refuse to install unless the binary has the `.exe` file extension.
203-
204-
You can verify that the plugin is successfully installed by looking for `java` in the output of `cf plugins`.
205-
206-
**Build Timestamp**: ${{ steps.timestamp.outputs.timestamp }}
159+
body_path: release_notes.md
207160
env:
208161
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
209162

.github/workflows/update_version.py

Lines changed: 87 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,58 @@ def update_version_in_go_file(file_path, major, minor, build):
1212
"""Update the version in the Go plugin metadata."""
1313
with open(file_path, 'r') as f:
1414
content = f.read()
15-
15+
1616
# Pattern to match the Version struct in PluginMetadata
1717
pattern = r'(Version: plugin\.VersionType\s*{\s*Major:\s*)\d+(\s*,\s*Minor:\s*)\d+(\s*,\s*Build:\s*)\d+(\s*,\s*})'
18-
18+
1919
replacement = rf'\g<1>{major}\g<2>{minor}\g<3>{build}\g<4>'
20-
20+
2121
new_content = re.sub(pattern, replacement, content)
22-
22+
2323
if new_content == content:
2424
print(f"Warning: Version pattern not found or not updated in {file_path}")
2525
return False
26-
26+
2727
with open(file_path, 'w') as f:
2828
f.write(new_content)
29-
29+
3030
print(f"✅ Updated version to {major}.{minor}.{build} in {file_path}")
3131
return True
3232

3333
def process_readme_changelog(readme_path, version):
3434
"""Process the README changelog section for the release."""
3535
with open(readme_path, 'r') as f:
3636
content = f.read()
37-
37+
3838
# Look for the snapshot section
3939
snapshot_pattern = rf'## {re.escape(version)}-snapshot\s*\n'
4040
match = re.search(snapshot_pattern, content)
41-
41+
4242
if not match:
4343
print(f"Error: README.md does not contain a '## {version}-snapshot' section")
4444
return False, None
45-
45+
4646
# Find the content of the snapshot section
4747
start_pos = match.end()
48-
48+
4949
# Find the next ## section or end of file
5050
next_section_pattern = r'\n## '
5151
next_match = re.search(next_section_pattern, content[start_pos:])
52-
52+
5353
if next_match:
5454
end_pos = start_pos + next_match.start()
5555
section_content = content[start_pos:end_pos].strip()
5656
else:
5757
section_content = content[start_pos:].strip()
58-
58+
5959
# Remove the "-snapshot" from the header
6060
new_header = f"## {version}"
6161
updated_content = re.sub(snapshot_pattern, new_header + '\n\n', content)
62-
62+
6363
# Write the updated README
6464
with open(readme_path, 'w') as f:
6565
f.write(updated_content)
66-
66+
6767
print(f"✅ Updated README.md: converted '## {version}-snapshot' to '## {version}'")
6868
return True, section_content
6969

@@ -75,20 +75,77 @@ def is_rc_version(version_str):
7575
"""Return True if the version string ends with -rc or -rcN."""
7676
return bool(re.match(r"^\d+\.\d+\.\d+-rc(\d+)?$", version_str))
7777

78+
def generate_release_notes(version, changelog_content):
79+
"""Generate complete release notes file."""
80+
release_notes = f"""## CF CLI Java Plugin {version}
81+
82+
Plugin for profiling Java applications and getting heap and thread-dumps.
83+
84+
## Changes
85+
86+
{changelog_content}
87+
88+
## Installation
89+
90+
### Installation via CF Community Repository
91+
92+
Make sure you have the CF Community plugin repository configured or add it via:
93+
```bash
94+
cf add-plugin-repo CF-Community http://plugins.cloudfoundry.org
95+
```
96+
97+
Trigger installation of the plugin via:
98+
```bash
99+
cf install-plugin -r CF-Community "java"
100+
```
101+
102+
### Manual Installation
103+
104+
Download this specific release ({version}) and install manually:
105+
106+
```bash
107+
# on Mac arm64
108+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/{version}/cf-cli-java-plugin-macos-arm64
109+
# on Windows x86
110+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/{version}/cf-cli-java-plugin-windows-amd64
111+
# on Linux x86
112+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/download/{version}/cf-cli-java-plugin-linux-amd64
113+
```
114+
115+
Or download the latest release:
116+
117+
```bash
118+
# on Mac arm64
119+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/latest/download/cf-cli-java-plugin-macos-arm64
120+
# on Windows x86
121+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/latest/download/cf-cli-java-plugin-windows-amd64
122+
# on Linux x86
123+
cf install-plugin https://github.com/SAP/cf-cli-java-plugin/releases/latest/download/cf-cli-java-plugin-linux-amd64
124+
```
125+
126+
**Note:** On Linux and macOS, if you get a permission error, run `chmod +x [cf-cli-java-plugin]` on the plugin binary.
127+
On Windows, the plugin will refuse to install unless the binary has the `.exe` file extension.
128+
129+
You can verify that the plugin is successfully installed by looking for `java` in the output of `cf plugins`.
130+
"""
131+
132+
with open("release_notes.md", 'w') as f:
133+
f.write(release_notes)
134+
78135
def main():
79136
if len(sys.argv) != 4:
80137
print("Usage: update_version.py <major> <minor> <build>")
81138
print("Example: update_version.py 4 1 0")
82139
sys.exit(1)
83-
140+
84141
try:
85142
major = int(sys.argv[1])
86143
minor = int(sys.argv[2])
87144
build = int(sys.argv[3])
88145
except ValueError:
89146
print("Error: Version numbers must be integers")
90147
sys.exit(1)
91-
148+
92149
version = f"{major}.{minor}.{build}"
93150
version_arg = f"{major}.{minor}.{build}" if (major + minor + build) != 0 else sys.argv[1]
94151
# Accept any -rc suffix, e.g. 4.0.0-rc, 4.0.0-rc1, 4.0.0-rc2
@@ -117,29 +174,38 @@ def main():
117174
section_content = content[start_pos:].strip()
118175
with open(changelog_file, 'w') as f:
119176
f.write(section_content)
177+
178+
# Generate full release notes for RC
179+
generate_release_notes(sys.argv[1], section_content)
180+
120181
print(f"✅ RC release: Changelog for {base_version} saved to {changelog_file}")
182+
print(f"✅ RC release: Full release notes saved to release_notes.md")
121183
sys.exit(0)
122-
184+
123185
go_file = Path("cf_cli_java_plugin.go")
124186
readme_file = Path("README.md")
125187
changelog_file = Path("release_changelog.txt")
126-
188+
127189
# Update Go version
128190
success = update_version_in_go_file(go_file, major, minor, build)
129191
if not success:
130192
sys.exit(1)
131-
193+
132194
# Process README changelog
133195
success, changelog_content = process_readme_changelog(readme_file, version)
134196
if not success:
135197
sys.exit(1)
136-
198+
137199
# Write changelog content to a file for the workflow to use
138200
with open(changelog_file, 'w') as f:
139201
f.write(changelog_content)
140-
202+
203+
# Generate full release notes
204+
generate_release_notes(version, changelog_content)
205+
141206
print(f"✅ Version updated successfully to {version}")
142207
print(f"✅ Changelog content saved to {changelog_file}")
208+
print(f"✅ Full release notes saved to release_notes.md")
143209

144210
if __name__ == "__main__":
145211
main()

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ counterfeiter
2828

2929
# Built binaries
3030
build/
31+
pkg/
3132

3233
# built project binary (go build)
3334
cf-java-plugin
@@ -49,4 +50,7 @@ test/snapshots/
4950
*.hprof
5051

5152
# Build artifacts
52-
dist
53+
dist
54+
55+
# go
56+
pkg

0 commit comments

Comments
 (0)