Skip to content

Implement CI pipeline #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Dependabot configuration:
# https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
# Maintain dependencies for Gradle dependencies
- package-ecosystem: "gradle"
directory: "/"
target-branch: "main"
schedule:
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
ignore:
# these depend on the toolbox API and should be updated manually
- dependency-name: "org.jetbrains.kotlin.jvm"
- dependency-name: "org.jetbrains.kotlin.plugin.serialization"
- dependency-name: "com.google.devtools.ksp"
# these can have breaking changes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we detect the breaking changes via some tests in the PRs. I would prefer an auto update over a manual one if we can detect the breaking changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the breaking changes (like for example breaking changes in the Toolbox api) can be detected at compile time. Basically the CI pipeline will fail and we can't merge the upgrade. However, the kotlin dependencies will be harder to detect, the compile can work fine but at runtime things might break because of the changes in the kotlin stdlib (just an example) shipped with Toolbox. We would need some end to end tests to detect these kind of changes. :(

- dependency-name: "com.jetbrains.toolbox:core-api"
- dependency-name: "com.jetbrains.toolbox:ui-api"
- dependency-name: "com.jetbrains.toolbox:remote-dev-api"
commit-message:
prefix: "chore"
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "main"
schedule:
interval: "weekly"
time: "06:00"
timezone: "America/Chicago"
commit-message:
prefix: "chore"
132 changes: 132 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# GitHub Actions workflow for testing and preparing the plugin release.
# GitHub Actions reference: https://help.github.com/en/actions

name: Coder Toolbox Plugin Build

on:
push:
branches:
- main
pull_request:

jobs:
# Run plugin tests on every supported platform.
test:
strategy:
matrix:
platform:
- ubuntu-latest
- macos-latest
- windows-latest
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/[email protected]

- uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 21
cache: gradle

- uses: gradle/[email protected]

# Run tests
- run: ./gradlew test --info

# Collect Tests Result of failed tests
- if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: tests-result
path: ${{ github.workspace }}/build/reports/tests

build:
name: Build
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.properties.outputs.version }}
changelog: ${{ steps.properties.outputs.changelog }}
steps:
# Check out current repository
- name: Fetch Sources
uses: actions/[email protected]

# Setup Java 21 environment for the next steps
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 21
cache: gradle

# Set environment variables
- name: Export Properties
id: properties
shell: bash
run: |
PROPERTIES="$(./gradlew properties --console=plain -q)"
VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')"
NAME="$(echo "$PROPERTIES" | grep "^group:" | cut -f2- -d ' ')"
CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)"
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
echo "::set-output name=version::$VERSION"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I will fix this everywhere.

echo "::set-output name=name::$NAME"
echo "::set-output name=changelog::$CHANGELOG"

# Run plugin build
- name: Run Build
run: ./gradlew clean pluginZip --info

# Prepare plugin archive content for creating artifact
- name: Prepare Plugin Artifact
id: artifact
shell: bash
run: |
cd ${{ github.workspace }}/build/distributions
FILENAME=`ls *.zip`
unzip "$FILENAME" -d content
echo "::set-output name=filename::${FILENAME:0:-4}"
# Store already-built plugin as an artifact for downloading
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact.outputs.filename }}
path: ./build/distributions/content/*/*

# Prepare a draft release for GitHub Releases page for the manual verification
# If accepted and published, release workflow would be triggered
releaseDraft:
name: Release Draft
if: github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-latest
steps:

# Check out current repository
- name: Fetch Sources
uses: actions/[email protected]

# Remove old release drafts by using the curl request for the available releases with draft flag
- name: Remove Old Release Drafts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh api repos/{owner}/{repo}/releases \
--jq '.[] | select(.draft == true) | .id' \
| xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{}
# Create new release draft - which is not publicly visible and requires manual acceptance
- name: Create Release Draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${{ needs.build.outputs.version }} \
--draft \
--target ${GITHUB_REF_NAME} \
--title "v${{ needs.build.outputs.version }}" \
--notes "$(cat << 'EOM'
${{ needs.build.outputs.changelog }}
EOM
)"
91 changes: 91 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# GitHub Actions Workflow created for handling the release process based on the draft release prepared with the Build workflow.

name: Release
on:
release:
types: [ prereleased, released ]

jobs:

# Prepare and publish the plugin to the Marketplace repository
release:
name: Publish Plugin
runs-on: ubuntu-latest
steps:

# Check out current repository
- name: Fetch Sources
uses: actions/[email protected]
with:
ref: ${{ github.event.release.tag_name }}

# Setup Java 21 environment for the next steps
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 21
cache: gradle

# Set environment variables
- name: Export Properties
id: properties
shell: bash
run: |
CHANGELOG="$(cat << 'EOM' | sed -e 's/^[[:space:]]*$//g' -e '/./,$!d'
${{ github.event.release.body }}
EOM
)"

CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"

echo "::set-output name=changelog::$CHANGELOG"

# Update Unreleased section with the current release note
- name: Patch Changelog
if: ${{ steps.properties.outputs.changelog != '' }}
env:
CHANGELOG: ${{ steps.properties.outputs.changelog }}
run: |
./gradlew patchChangelog --release-note="$CHANGELOG"

# Publish the plugin to the Marketplace
# TODO - enable this step (by removing the `if` block) when JetBrains is clear about release procedures
- name: Publish Plugin
if: false
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
CERTIFICATE_CHAIN: ${{ secrets.CERTIFICATE_CHAIN }}
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
PRIVATE_KEY_PASSWORD: ${{ secrets.PRIVATE_KEY_PASSWORD }}
run: ./gradlew publishPlugin --info

# Upload artifact as a release asset
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*

# Create pull request
- name: Create Pull Request
if: ${{ steps.properties.outputs.changelog != '' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ github.event.release.tag_name }}"
BRANCH="changelog-update-$VERSION"

git config user.email "[email protected]"
git config user.name "GitHub Action"

git checkout -b $BRANCH
git commit -am "Changelog update - $VERSION"
git push --set-upstream origin $BRANCH

gh pr create \
--title "Changelog update - \`$VERSION\`" \
--body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \
--base main \
--head $BRANCH
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ build
jvm/

# IntelliJ IDEA
.idea
.idea

# hidden macOS metadata files
.DS_Store
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Coder Toolbox Plugin Changelog

## Unreleased

### Added

- initial support for JetBrains Toolbox 2.6.0.38311 with the possibility to manage the workspaces - i.e. start, stop,
update and delete actions and also quick shortcuts to templates, web terminal and dashboard.
26 changes: 20 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ plugins {
alias(libs.plugins.dependency.license.report)
alias(libs.plugins.ksp)
alias(libs.plugins.gradle.wrapper)
alias(libs.plugins.changelog)
}

buildscript {
Expand Down Expand Up @@ -50,6 +51,16 @@ dependencies {
testImplementation(kotlin("test"))
}

val pluginId = properties("group")
val pluginName = properties("name")
val pluginVersion = properties("version")

changelog {
version.set(pluginVersion)
groups.set(emptyList())
title.set("Coder Toolbox Plugin Changelog")
}

licenseReport {
renderers = arrayOf(JsonReportRenderer("dependencies.json"))
filters = arrayOf(ExcludeTransitiveDependenciesFilter())
Expand All @@ -65,9 +76,6 @@ tasks.test {
useJUnitPlatform()
}

val pluginId = "com.coder.toolbox"
val pluginVersion = "0.0.1"

val assemblePlugin by tasks.registering(Jar::class) {
archiveBaseName.set(pluginId)
from(sourceSets.main.get().output)
Expand Down Expand Up @@ -138,14 +146,18 @@ val pluginZip by tasks.creating(Zip::class) {
include("icon.svg")
rename("icon.svg", "pluginIcon.svg")
}
archiveBaseName.set("$pluginId-$pluginVersion")
into(pluginId)
archiveBaseName.set(pluginName)
}

val uploadPlugin by tasks.creating {
val publishPlugin by tasks.creating {
dependsOn(pluginZip)

doLast {
val instance = PluginRepositoryFactory.create("https://plugins.jetbrains.com", project.property("pluginMarketplaceToken").toString())
val instance = PluginRepositoryFactory.create(
"https://plugins.jetbrains.com",
project.property("PUBLISH_TOKEN").toString()
)

// first upload
// instance.uploader.uploadNewPlugin(pluginZip.outputs.files.singleFile, listOf("toolbox", "gateway"), LicenseUrl.APACHE_2_0, ProductFamily.TOOLBOX)
Expand All @@ -163,3 +175,5 @@ tasks.register("classpath") {
)
}
}

fun properties(key: String) = project.findProperty(key).toString()
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version=0.1.0
group=com.coder.toolbox
name=coder-toolbox
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ exec = "1.12"
moshi = "1.15.1"
ksp = "2.1.0-1.0.29"
retrofit = "2.8.2"
changelog = "2.2.1"

[libraries]
toolbox-core-api = { module = "com.jetbrains.toolbox:core-api", version.ref = "toolbox-plugin-api" }
Expand Down Expand Up @@ -40,4 +41,5 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
dependency-license-report = { id = "com.github.jk1.dependency-license-report", version.ref = "dependency-license-report" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp"}
gradle-wrapper = { id = "me.filippov.gradle.jvm.wrapper", version.ref = "gradle-wrapper" }
gradle-wrapper = { id = "me.filippov.gradle.jvm.wrapper", version.ref = "gradle-wrapper" }
changelog = { id = "org.jetbrains.changelog", version.ref = "changelog" }
Loading