Skip to content

Commit f311f16

Browse files
authored
Refactor CLI manager to support multiple deployments (#213)
* Remove unused wizard variable * Add more logs around authenticating Also rename the function since it loads all workspaces, not just one. * Test on macOS and Windows Since the comments are now out of date I removed them; I figure it is more or less as easy to just read the workflow to see what it does. * Refactor CLI manager to support multiple deployments Currently multiple deployments will delete each other's binaries so this uses a directory for each deployment host to store the binaries. Add a catch for download errors; previously they would go unnoticed. Also refactor the download a little; instead of checking for the file's existence catch the appropriate error and set the permissions from Kotlin code rather than spawning chmod. Remove a chunk of code where we configure the CLI again before moving to the next step; we already do that when we first connect (plus it is missing some checks like making sure the CLI has actually been downloaded and is the right version, etc). This also makes it unnecessary to globally store the version and CLI path on the model since we now only do it in one spot. This is just a first step; in a future PR the config code will all be extracted out since we will want to configure every time we try to connect (rather than just in the initial setup step) since otherwise the recent connections can fail if you have configured a different deployment in the meantime (and probably reconnections would also fail if you already have an IDE open) or if you have restarted (since the binaries are currently in tmp). We will also need to configure ourselves since `config-ssh` does not support multiple deployments and we want to add an environment variable via SetEnv. * Encapsulate process execution in CLI manager We will need to create a new function for config-ssh anyway since we will be doing our own thing rather than spawning the CLI in order to support multiple deployments so this preemptively encapsulates that logic. * Move CLI config read into CLI manager * Add tests for config dir * Redact token from logger output * Use ETag for downloading binary This way we will not need to name the binaries with their versions or otherwise extract the version from each binary since we can just grab their hash and set that in the request. This also means we will not need to remove old versions as there will only be the one file. * Accept gzip when downloading binary * Store binary in data directory The @jvmoverloads annotations make Kotlin generate overloads otherwise the test code thinks the optional arguments are not optional. * Include port in sub-directory if it is set * Test against a mocked server Environment variables can be used to test against a real deployment. I now just check if the file is executable rather than trying to actually execute it since we would need to actually compile something that can run as a .exe on Windows. * Split out version check for testing * Handle IDN * Use real deployment for just one test That is enough to prove the downloading works and the rest can just test their own extra assumptions on top of that. * Mention tests in the readme
1 parent d2bca87 commit f311f16

File tree

9 files changed

+659
-181
lines changed

9 files changed

+659
-181
lines changed

.github/workflows/build.yml

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,61 @@
1-
# GitHub Actions Workflow created for testing and preparing the plugin release in following steps:
2-
# - validate Gradle Wrapper,
3-
# - run 'test' and 'verifyPlugin' tasks,
4-
# - run Qodana inspections,
5-
# - run 'buildPlugin' task and prepare artifact for the further tests,
6-
# - run 'runPluginVerifier' task,
7-
# - create a draft release.
8-
#
9-
# Workflow is triggered on push and pull_request events.
10-
#
1+
# GitHub Actions workflow for testing and preparing the plugin release.
112
# GitHub Actions reference: https://help.github.com/en/actions
12-
#
13-
143

154
name: Coder Gateway Plugin Build
5+
166
on:
17-
# Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests)
187
push:
19-
branches: [ main ]
20-
# Trigger the workflow on any pull request
8+
branches:
9+
- main
2110
pull_request:
2211

2312
jobs:
2413

25-
# Run Gradle Wrapper Validation Action to verify the wrapper's checksum
26-
# Run verifyPlugin, IntelliJ Plugin Verifier, and test Gradle tasks
27-
# Build plugin and provide the artifact for the next workflow jobs
14+
# Run plugin tests on every supported platform.
15+
test:
16+
strategy:
17+
matrix:
18+
platform:
19+
- ubuntu-latest
20+
- macos-latest
21+
- windows-latest
22+
runs-on: ${{ matrix.platform }}
23+
steps:
24+
- uses: actions/checkout@v3.5.0
25+
26+
- uses: actions/setup-java@v3
27+
with:
28+
distribution: zulu
29+
java-version: 17
30+
cache: gradle
31+
32+
- uses: gradle/wrapper-validation-action@v1.0.6
33+
34+
# Run tests
35+
- run: ./gradlew test
36+
37+
# Collect Tests Result of failed tests
38+
- if: ${{ failure() }}
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: tests-result
42+
path: ${{ github.workspace }}/build/reports/tests
43+
44+
# Run Gradle Wrapper Validation Action to verify the wrapper's checksum. Run
45+
# verifyPlugin and IntelliJ Plugin Verifier. Build plugin and provide the
46+
# artifact for the next workflow jobs.
2847
build:
2948
name: Build
49+
needs: test
3050
runs-on: ubuntu-latest
3151
outputs:
3252
version: ${{ steps.properties.outputs.version }}
3353
changelog: ${{ steps.properties.outputs.changelog }}
3454
steps:
35-
3655
# Check out current repository
3756
- name: Fetch Sources
3857
uses: actions/checkout@v3.5.0
3958

40-
# Validate wrapper
41-
- name: Gradle Wrapper Validation
42-
uses: gradle/wrapper-validation-action@v1.0.6
43-
4459
# Setup Java 11 environment for the next steps
4560
- name: Setup Java
4661
uses: actions/setup-java@v3
@@ -66,17 +81,6 @@ jobs:
6681
echo "::set-output name=changelog::$CHANGELOG"
6782
echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier"
6883
./gradlew listProductsReleases # prepare list of IDEs for Plugin Verifier
69-
# Run tests
70-
- name: Run Tests
71-
run: ./gradlew test
72-
73-
# Collect Tests Result of failed tests
74-
- name: Collect Tests Result
75-
if: ${{ failure() }}
76-
uses: actions/upload-artifact@v3
77-
with:
78-
name: tests-result
79-
path: ${{ github.workspace }}/build/reports/tests
8084
8185
# Run plugin build
8286
- name: Run Build
@@ -156,4 +160,4 @@ jobs:
156160
--notes "$(cat << 'EOM'
157161
${{ needs.build.outputs.changelog }}
158162
EOM
159-
)"
163+
)"

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Coder Gateway Plugin
1+
# Coder Gateway Plugin
22

33
[!["Join us on
44
Discord"](https://img.shields.io/badge/join-us%20on%20Discord-gray.svg?longCache=true&logo=discord&colorB=purple)](https://discord.gg/coder)
@@ -87,7 +87,9 @@ The properties listed define the plugin itself or configure the [gradle-intellij
8787

8888
### Testing
8989

90-
No functional or UI tests are available yet.
90+
Run tests with `./gradlew test`. By default this will test against
91+
`https://dev.coder.com` but you can set `CODER_GATEWAY_TEST_DEPLOYMENT` to a URL
92+
of your choice or to `mock` to use mocks only.
9193

9294
### Code Monitoring
9395

@@ -127,7 +129,8 @@ In the `.github/workflows` directory, you can find definitions for the following
127129
- Triggered on `Publish release` event.
128130
- Updates `CHANGELOG.md` file with the content provided with the release note.
129131
- Publishes the plugin to JetBrains Marketplace using the provided `PUBLISH_TOKEN`.
130-
- Sets publish channel depending on the plugin version, i.e. `1.0.0-beta` -> `beta` channel. For now, both `main` and `eap` branches are published on default release channel.
132+
- Sets publish channel depending on the plugin version, i.e. `1.0.0-beta` -> `beta` channel. For now, both `main`
133+
and `eap` branches are published on default release channel.
131134
- Patches the Changelog and commits.
132135

133136
### Release flow

src/main/kotlin/com/coder/gateway/models/CoderWorkspacesWizardModel.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package com.coder.gateway.models
33
data class CoderWorkspacesWizardModel(
44
var coderURL: String = "https://coder.example.com",
55
var token: String = "",
6-
var buildVersion: String = "",
7-
var localCliPath: String = "",
86
var selectedWorkspace: WorkspaceAgentModel? = null,
97
var useExistingToken: Boolean = false
108
)

0 commit comments

Comments
 (0)