Skip to content

Commit dc3ab1f

Browse files
authored
feat: add intellij plugin for cty (#208)
* feat: add intellij plugin for cty Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> * removed built stuff Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> * it is working now, however the context menu is greyed out Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> * fixing the output, the context menu is still not working Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> * add github action and tests Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> * ugh my local environment is NOT java friendly Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> * fix IntelliJ plugin test failures * still trying to fix the stupid java test Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> * okay something is missing Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> --------- Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
1 parent 345e71a commit dc3ab1f

29 files changed

+2092
-14
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: IntelliJ Plugin Tests
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'intellij-plugin/**'
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- 'intellij-plugin/**'
12+
workflow_dispatch:
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
24+
- name: Setup Java
25+
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
26+
with:
27+
distribution: 'temurin'
28+
java-version: '17'
29+
30+
- name: Setup Gradle
31+
uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0
32+
with:
33+
gradle-home-cache-cleanup: true
34+
35+
- name: Cache Gradle dependencies
36+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
37+
with:
38+
path: |
39+
~/.gradle/caches
40+
~/.gradle/wrapper
41+
key: ${{ runner.os }}-gradle-${{ hashFiles('intellij-plugin/**/*.gradle*', 'intellij-plugin/**/gradle-wrapper.properties') }}
42+
restore-keys: |
43+
${{ runner.os }}-gradle-
44+
45+
- name: Run tests
46+
working-directory: intellij-plugin
47+
run: |
48+
if [ ! -f gradlew ]; then
49+
gradle wrapper
50+
fi
51+
./gradlew test
52+
53+
- name: Upload test results
54+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
55+
if: always()
56+
with:
57+
name: test-results
58+
path: intellij-plugin/build/reports/tests/
59+
60+
- name: Upload test reports
61+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
62+
if: failure()
63+
with:
64+
name: test-reports
65+
path: intellij-plugin/build/test-results/
66+
67+
build:
68+
runs-on: ubuntu-latest
69+
needs: test
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
73+
74+
- name: Setup Java
75+
uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4.5.0
76+
with:
77+
distribution: 'temurin'
78+
java-version: '17'
79+
80+
- name: Setup Gradle
81+
uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808 # v4.1.0
82+
with:
83+
gradle-home-cache-cleanup: true
84+
85+
- name: Cache Gradle dependencies
86+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
87+
with:
88+
path: |
89+
~/.gradle/caches
90+
~/.gradle/wrapper
91+
key: ${{ runner.os }}-gradle-${{ hashFiles('intellij-plugin/**/*.gradle*', 'intellij-plugin/**/gradle-wrapper.properties') }}
92+
restore-keys: |
93+
${{ runner.os }}-gradle-
94+
95+
- name: Build plugin
96+
working-directory: intellij-plugin
97+
run: |
98+
if [ ! -f gradlew ]; then
99+
gradle wrapper
100+
fi
101+
./gradlew buildPlugin
102+
103+
- name: Verify plugin
104+
working-directory: intellij-plugin
105+
run: |
106+
if [ ! -f gradlew ]; then
107+
gradle wrapper
108+
fi
109+
./gradlew verifyPlugin
110+
111+
- name: Upload plugin artifact
112+
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
113+
with:
114+
name: intellij-plugin
115+
path: intellij-plugin/build/distributions/

intellij-plugin/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gradle
2+
build

intellij-plugin/README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# CRD to Sample YAML - IntelliJ Plugin
2+
3+
IntelliJ IDEA plugin for generating sample YAML files from Kubernetes Custom Resource Definitions using the CTY tool.
4+
5+
## Features
6+
7+
- **CRD Detection**: Automatically detects CRD files in your project
8+
- **Sample Generation**: Generate complete, minimal, or commented sample YAML files
9+
- **Validation**: Validate sample YAML files against CRD schemas
10+
- **Context Menu Integration**: Right-click on CRD files to access all features
11+
- **Configurable**: Settings panel to configure CTY binary path and output options
12+
13+
## Prerequisites
14+
15+
Install the CTY binary:
16+
```bash
17+
go install github.com/Skarlso/crd-to-sample-yaml@latest
18+
```
19+
20+
## Installation
21+
22+
1. Build the plugin:
23+
```bash
24+
cd intellij-plugin
25+
./gradlew buildPlugin
26+
```
27+
28+
2. Install the generated `.zip` file from `build/distributions/` via:
29+
- **File → Settings → Plugins → Install Plugin from Disk**
30+
31+
## Usage
32+
33+
### Generate Samples
34+
1. Right-click on any CRD YAML file
35+
2. Select **CRD to Sample YAML** from the context menu
36+
3. Choose your generation option:
37+
- **Generate Sample YAML** - Complete sample with all fields
38+
- **Generate Minimal Sample YAML** - Required fields only
39+
- **Generate Sample YAML with Comments** - Sample with field descriptions
40+
41+
### Validate Samples
42+
1. Right-click on a CRD file
43+
2. Select **CRD to Sample YAML → Validate Sample Against CRD**
44+
3. Choose the sample YAML file to validate
45+
46+
### Configure Settings
47+
1. Go to **File → Settings → Tools → CRD to Sample YAML**
48+
2. Configure:
49+
- **CTY Binary Path**: Path to the cty executable (leave empty to use PATH)
50+
- **Output Location**: Where to save generated files
51+
- **Show Notifications**: Enable/disable success/error notifications
52+
53+
## Development
54+
55+
### Prerequisites
56+
- IntelliJ IDEA 2023.2+
57+
- Java 17+
58+
- Gradle
59+
60+
### Setup
61+
```bash
62+
git clone https://github.com/Skarlso/crd-to-sample-yaml.git
63+
cd crd-to-sample-yaml/intellij-plugin
64+
./gradlew buildPlugin
65+
```
66+
67+
### Testing
68+
```bash
69+
./gradlew test
70+
```
71+
72+
### Running in Development
73+
```bash
74+
./gradlew runIde
75+
```
76+
77+
### Project Structure
78+
```
79+
src/main/java/com/skarlso/crdtosampleyaml/
80+
├── actions/ # Context menu actions
81+
│ ├── BaseAction.java
82+
│ ├── GenerateSampleAction.java
83+
│ ├── GenerateMinimalSampleAction.java
84+
│ ├── GenerateSampleWithCommentsAction.java
85+
│ └── ValidateSampleAction.java
86+
├── services/ # Core services
87+
│ ├── CrdDetectorService.java
88+
│ └── CtyService.java
89+
└── settings/ # Plugin configuration
90+
├── CtySettings.java
91+
└── CtyConfigurable.java
92+
```
93+
94+
## Troubleshooting
95+
96+
### CTY Not Found
97+
- Install CTY: `go install github.com/Skarlso/crd-to-sample-yaml@latest`
98+
- Or configure the full path in plugin settings
99+
100+
### No Context Menu Options
101+
- Ensure you're right-clicking on a valid CRD YAML file
102+
- CRD files must have `kind: CustomResourceDefinition` and `apiVersion: apiextensions.k8s.io/v1`
103+
104+
### Generation Fails
105+
- Check that CTY is properly installed: `cty version`
106+
- Verify the CRD file is valid
107+
- Check IntelliJ's Event Log for detailed error messages
108+
109+
## Building for Distribution
110+
111+
```bash
112+
./gradlew buildPlugin
113+
```
114+
115+
The plugin ZIP file will be created in `build/distributions/`
116+
117+
## License
118+
119+
This plugin is part of the CRD to Sample YAML project and follows the same license terms.

intellij-plugin/build.gradle.kts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
plugins {
2+
id("java")
3+
id("org.jetbrains.kotlin.jvm") version "1.9.25"
4+
id("org.jetbrains.intellij") version "1.17.4"
5+
}
6+
7+
group = "com.skarlso"
8+
version = "1.0.0"
9+
10+
repositories {
11+
mavenCentral()
12+
}
13+
14+
intellij {
15+
version.set("2023.2.6")
16+
type.set("IC") // IntelliJ IDEA Community Edition
17+
18+
plugins.set(listOf(
19+
"com.intellij.java",
20+
"org.jetbrains.plugins.yaml"
21+
))
22+
}
23+
24+
tasks {
25+
withType<JavaCompile> {
26+
sourceCompatibility = "17"
27+
targetCompatibility = "17"
28+
}
29+
30+
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
31+
kotlinOptions.jvmTarget = "17"
32+
}
33+
34+
patchPluginXml {
35+
sinceBuild.set("232")
36+
untilBuild.set("251.*")
37+
}
38+
39+
signPlugin {
40+
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
41+
privateKey.set(System.getenv("PRIVATE_KEY"))
42+
password.set(System.getenv("PRIVATE_KEY_PASSWORD"))
43+
}
44+
45+
publishPlugin {
46+
token.set(System.getenv("PUBLISH_TOKEN"))
47+
}
48+
}
49+
50+
dependencies {
51+
implementation("org.yaml:snakeyaml:2.2")
52+
53+
testImplementation("junit:junit:4.13.2")
54+
testImplementation("org.mockito:mockito-core:5.7.0")
55+
testImplementation("org.mockito:mockito-inline:5.2.0")
56+
}

intellij-plugin/gradle.properties

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# IntelliJ Platform Plugin Template Properties
2+
platformVersion=2023.2.6
3+
platformType=IC
4+
5+
# Plugin Dependencies
6+
# https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
7+
platformPlugins=com.intellij.java,org.jetbrains.plugins.yaml
8+
9+
# Gradle Releases -> https://github.com/gradle/gradle/releases
10+
gradleVersion=8.4
11+
12+
# Opt-out flag for bundling Kotlin standard library -> https://kotlinlang.org/docs/gradle-configure-project.html#gradle-java-toolchains-support
13+
kotlin.stdlib.default.dependency=false
14+
15+
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
16+
org.gradle.configuration-cache=true
17+
18+
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
19+
org.gradle.caching=true
42.7 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)