Skip to content

Commit

Permalink
Merge remote-tracking branch 'Parent/main' into Current
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaRHristov committed Apr 28, 2024
2 parents 087daac + 497e091 commit d0960f2
Show file tree
Hide file tree
Showing 43 changed files with 2,102 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

[*.kt]
indent_size = 4
14 changes: 14 additions & 0 deletions .github/actions/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Setup
description: Sets up the job
runs:
using: composite
steps:
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 17
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
71 changes: 71 additions & 0 deletions .github/workflows/_build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Reusable Build Workflow
name: _Build

on:
workflow_call:
inputs:
nightly:
type: boolean
default: false
required: false
description: 'Publish a nightly build'
artifact:
type: boolean
required: false
default: false
description: 'Create an artifact for the compiled plugin'
outputs:
version:
value: ${{ jobs.build-plugin.outputs.version }}
description: 'Version of the built plugin'
nightly:
value: ${{ inputs.nightly }}
description: "Whether or not the build is a nightly build"

jobs:
build-plugin:
name: Build Plugin
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
uses: ./.github/actions/setup

- name: Read version from gradle.properties (nightly)
if: ${{ inputs.nightly }}
id: original-version
run: echo "version=$(grep -P '^pluginVersion=\K(.+)$' -o gradle.properties)" >> $GITHUB_OUTPUT

- name: Generate nightly version identifier (nightly)
if: ${{ inputs.nightly }}
id: nightly-version
run: echo "version=${{ steps.original-version.outputs.version }}-nightly.$(echo '${{ github.sha }}' | cut -c 1-7)" >> "$GITHUB_OUTPUT"

- name: Replace version in gradle.properties (nightly)
if: ${{ inputs.nightly }}
run: sed -i -E 's/^pluginVersion=.*/pluginVersion=${{ steps.nightly-version.outputs.version }}/' gradle.properties

- name: Read final version
id: version
run: echo "version=$(grep -P '^pluginVersion=\K(.+)$' -o gradle.properties)" >> $GITHUB_OUTPUT

- name: Build
run: ./gradlew buildPlugin

- name: Cache gradle.properties
if: ${{ inputs.artifact }}
uses: actions/cache@v3
with:
path: gradle.properties
key: gradle.properties.${{ github.sha }}

- name: Upload plugin artifact
if: ${{ inputs.artifact }}
uses: actions/upload-artifact@v4
with:
name: Biome-${{ steps.version.outputs.version }}.zip
path: build/distributions/Biome-${{ steps.version.outputs.version }}.zip
12 changes: 12 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Integrate

on:
push:
branches: [ "main" ]
pull_request:
workflow_dispatch:

jobs:
build:
name: Build
uses: ./.github/workflows/_build.yaml
90 changes: 90 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Publish

on:
workflow_dispatch:
inputs:
nightly:
type: boolean
default: true
required: false
description: 'Publish a nightly build'

jobs:
build:
name: Build
uses: ./.github/workflows/_build.yaml
with:
nightly: ${{ inputs.nightly }}
artifact: true

publish-jetbrains:
name: Publish to JetBrains Marketplace
needs: [ build ]
runs-on: ubuntu-latest
environment: intellij-plugin
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download the artifact
uses: actions/download-artifact@v4
with:
name: Biome-${{ needs.build.outputs.version }}.zip

- name: Restore gradle.properties
uses: actions/cache/restore@v3
with:
path: gradle.properties
key: gradle.properties.${{ github.sha }}

- name: Publish Plugin
env:
PUBLISH_TOKEN: ${{ secrets.JETBRAINS_PUBLISH_TOKEN }}
CERTIFICATE_CHAIN: ${{ secrets.JETBRAINS_CERTIFICATE_CHAIN }}
PRIVATE_KEY: ${{ secrets.JETBRAINS_PRIVATE_KEY }}
PRIVATE_KEY_PASSWORD: ${{ secrets.JETBRAINS_PRIVATE_KEY_PASSWORD }}
run: ./gradlew publishPlugin -PdistributionFile="./build/distributions/Biome-${{ needs.build.outputs.version }}.zip"

publish-github-release:
name: Publish to GitHub Releases
needs: [ build ]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download the artifact
uses: actions/download-artifact@v4
with:
name: Biome-${{ needs.build.outputs.version }}.zip

- name: Generate release notes
id: release-notes
uses: orhun/git-cliff-action@v2
with:
config: cliff.toml
args: -vv --latest --strip header e71479100d4ed81b3e9c26881c38a0ddb7da31eb..
env:
OUTPUT: CHANGES.md

- name: Strip tag from release notes
run: tail -n +3 < CHANGES.md > RELEASE_NOTES.md

- name: Rename artifact
run: mv "Biome-${{ needs.build.outputs.version }}.zip" biome.zip

- name: Publish extension to GitHub Releases
uses: softprops/action-gh-release@v1
with:
name: "v${{ needs.build.outputs.version }}"
body_path: RELEASE_NOTES.md
prerelease: ${{ needs.build.outputs.nightly == 'true' }}
draft: true
files: biome.zip
tag_name: ${{ needs.build.outputs.nightly == 'true' && github.ref || format('v{0}', needs.build.outputs.version) }}
21 changes: 21 additions & 0 deletions src/main/kotlin/com/github/biomejs/intellijbiome/BiomeBundle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.biomejs.intellijbiome

import com.intellij.DynamicBundle
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey

@NonNls
private const val BUNDLE = "messages.BiomeBundle"

object BiomeBundle : DynamicBundle(BUNDLE) {

@Suppress("SpreadOperator")
@JvmStatic
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getMessage(key, *params)

@Suppress("SpreadOperator", "unused")
@JvmStatic
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
getLazyMessage(key, *params)
}
80 changes: 80 additions & 0 deletions src/main/kotlin/com/github/biomejs/intellijbiome/BiomePackage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.github.biomejs.intellijbiome

import com.github.biomejs.intellijbiome.extensions.runBiomeCLI
import com.github.biomejs.intellijbiome.settings.BiomeSettings
import com.github.biomejs.intellijbiome.settings.ConfigurationMode
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.util.ExecUtil
import com.intellij.javascript.nodejs.interpreter.NodeJsInterpreterManager
import com.intellij.javascript.nodejs.util.NodePackage
import com.intellij.openapi.project.Project
import java.nio.file.Paths

class BiomePackage(private val project: Project) {
private val interpreter = NodeJsInterpreterManager.getInstance(project).interpreter
private val nodePackage: NodePackage?
get() {
return NodePackage.findDefaultPackage(project, "@biomejs/biome", interpreter)
}

val configPath: String?
get() {
val settings = BiomeSettings.getInstance(project)
val configurationMode = settings.configurationMode

return when (configurationMode) {
ConfigurationMode.DISABLED -> null
ConfigurationMode.AUTOMATIC -> null
ConfigurationMode.MANUAL -> BiomeSettings.getInstance(project).configPath
}
}

fun versionNumber(): String? {
val settings = BiomeSettings.getInstance(project)
val configurationMode = settings.configurationMode
return when (configurationMode) {
ConfigurationMode.DISABLED -> null
ConfigurationMode.AUTOMATIC -> nodePackage?.getVersion(project)?.toString()
ConfigurationMode.MANUAL -> getBinaryVersion(binaryPath())
}
}

fun binaryPath(): String? {
val settings = BiomeSettings.getInstance(project)
val configurationMode = settings.configurationMode
return when (configurationMode) {
ConfigurationMode.DISABLED -> null
ConfigurationMode.AUTOMATIC -> nodePackage?.getAbsolutePackagePathToRequire(project)?.let {
Paths.get(
it,
"bin/biome"
)
}?.toString()

ConfigurationMode.MANUAL -> settings.executablePath
}
}


private fun getBinaryVersion(binaryPath: String?): String? {
if (binaryPath.isNullOrEmpty()) {
return null
}

val versionRegex = Regex("\\d{1,2}\\.\\d{1,2}\\.\\d{1,3}")
val commandLine = GeneralCommandLine().runBiomeCLI(project, binaryPath).apply {
addParameter("--version")
}

return runCatching {
val output = ExecUtil.execAndGetOutput(commandLine)
val matchResult = versionRegex.find(output.stdout)
return matchResult?.value
}.getOrNull()
}

companion object {
const val configName = "biome"
val configValidExtensions = listOf("json", "jsonc")
}
}
46 changes: 46 additions & 0 deletions src/main/kotlin/com/github/biomejs/intellijbiome/BiomeRunner.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.biomejs.intellijbiome

import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.openapi.editor.Document
import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.annotations.Nls
import java.util.*
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

enum class Feature {
Format,
SafeFixes,
UnsafeFixes
}

interface BiomeRunner {
companion object {
val DEFAULT_TIMEOUT = 30000.milliseconds
}

fun check(request: Request, features: EnumSet<Feature>): Response
fun createCommandLine(file: VirtualFile, action: String, args: List<String> = listOf()): GeneralCommandLine


data class Request(
val document: Document,
val virtualFile: VirtualFile,
val timeout: Duration,
val commandDescription: String
)

sealed class Response {
class Success(val code: String) : Response()

class Failure(
@Nls val title: String,
@NlsSafe val description: String,
val exitCode: Int?
) : Response()

}
}


Loading

0 comments on commit d0960f2

Please sign in to comment.