From 5e463d6656e54d61235240696d0b2e52109b5fe9 Mon Sep 17 00:00:00 2001 From: chalee Date: Sun, 22 Sep 2024 22:23:36 +0900 Subject: [PATCH] [#8] gh actions to release (#9) * feat: simple upload and download * chore: upload artifact name slash to dash * chore: split files by dir * chore: fix path * chore: set wd & build plugin * chore: set phase * chore: release action * chore: fix * chore: set wd to acquire version * chore: fix * chore: ready to merge --- .github/workflows/release.yml | 115 ++++++++++++++++++ .github/workflows/rust.yml | 48 -------- gitnote-jetbrains/build.gradle.kts | 17 ++- .../io/cjlee/gitnote/core/JniCoreConnector.kt | 2 +- .../gitnote/core/ProcessCoreConnector.kt | 4 +- .../cjlee/gitnote/jcef/GitNoteViewerWindow.kt | 6 +- 6 files changed, 133 insertions(+), 59 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a722904 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,115 @@ +name: Release + +on: + push: + tags: + - "v*.*.*" + pull_request: + branches: [ "master" ] + +env: + PROJECT_NAME: gitnote + CARGO_TERM_COLOR: always + +jobs: + buildCargo: + runs-on: ${{ matrix.runner }} + + strategy: + fail-fast: false + matrix: + include: + - name: linux-amd64 + runner: ubuntu-latest + target: x86_64-unknown-linux-gnu + libName: libgitnote.so + - name: win-amd64 + runner: windows-latest + target: x86_64-pc-windows-msvc + libName: gitnote.dll + - name: macos-amd64 + runner: macos-latest + target: x86_64-apple-darwin + libName: libgitnote.dylib + - name: macos-arm64 + runner: macos-latest + target: aarch64-apple-darwin + libName: libgitnote.dylib + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Build Binary + working-directory: ./gitnote-core + run: cargo build --lib --verbose --locked --release --target ${{ matrix.target }} + + - name: Run tests + working-directory: ./gitnote-core + run: cargo test --lib --verbose + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.target }} + path: ./gitnote-core/target/${{ matrix.target }}/release/${{ matrix.libName }} + buildJar: + runs-on: ubuntu-latest + needs: buildCargo + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + path: ./gitnote-jetbrains/src/main/resources/core + + - name: Build JAR + working-directory: ./gitnote-jetbrains + run: ./gradlew buildPlugin -Dgitnote.phase=2 + + - name: Get Project Version + id: get_version + working-directory: ./gitnote-jetbrains + run: echo "GITNOTE_VERSION=$(./gradlew properties -q | awk '/^version:/ {print $2}')" >> $GITHUB_ENV + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: gitnote-jetbrains-${{ env.GITNOTE_VERSION }}.zip + path: ./gitnote-jetbrains/build/distributions/gitnote-jetbrains-${{ env.GITNOTE_VERSION }}.zip + release: + permissions: + contents: write + runs-on: ubuntu-latest + needs: [ buildCargo, buildJar ] + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get Project Version + id: get_version + working-directory: ./gitnote-jetbrains + run: echo "GITNOTE_VERSION=$(./gradlew properties -q | awk '/^version:/ {print $2}')" >> $GITHUB_ENV + + - name: Download Artifacts + uses: actions/download-artifact@v4 + with: + name: gitnote-jetbrains-${{ env.GITNOTE_VERSION }}.zip + + - name: list resources + run: ls -l . + + - name: Release + uses: softprops/action-gh-release@v2 + if: startsWith(github.ref, 'refs/tags/') + with: + files: gitnote-jetbrains/build/distributions/gitnote-jetbrains-${{ env.GITNOTE_VERSION }}.zip + diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 5e88042..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Rust - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - -env: - PROJECT_NAME: gitnote - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ${{ matrix.runner }} - - strategy: - fail-fast: false - matrix: - include: - - name: linux-amd64 - runner: ubuntu-latest - target: x86_64-unknown-linux-gnu - - name: win-amd64 - runner: windows-latest - target: x86_64-pc-windows-msvc - - name: macos-amd64 - runner: macos-latest - target: x86_64-apple-darwin - - name: macos-arm64 - runner: macos-latest - target: aarch64-apple-darwin - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - targets: ${{ matrix.target }} - - - name: Build Binary - working-directory: ./gitnote-core - run: cargo build --lib --verbose --locked --release --target ${{ matrix.target }} - - - name: Run tests - working-directory: ./gitnote-core - run: cargo test --lib --verbose diff --git a/gitnote-jetbrains/build.gradle.kts b/gitnote-jetbrains/build.gradle.kts index 02a4e9e..3244f37 100644 --- a/gitnote-jetbrains/build.gradle.kts +++ b/gitnote-jetbrains/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "io.cjlee" -version = "0.1.0" +version = "0.2.0" repositories { mavenCentral() @@ -29,7 +29,14 @@ intellij { plugins.set(listOf(/* Plugin Dependencies */)) } -val development = false +// phase +// 0 : develop +// 1 : alpha +// 2 : release +val PHASE_DEVELOP = 0 +val PHASE_ALPHA = 1 +val PHASE_RELEASE = 2 +val phase = (System.getProperty("gitnote.phase") ?: "0").toInt() tasks { // Set the JVM compatibility versions @@ -48,11 +55,11 @@ tasks { runIde { autoReloadPlugins = true - systemProperty("gitnote.developmentPhase", development) + systemProperty("gitnote.phase", phase) } buildPlugin { - if (!development) { + if (phase == PHASE_ALPHA) { dependsOn("buildCore") dependsOn("buildGui") } @@ -94,7 +101,7 @@ tasks { } processResources { - if (!development) { + if (phase == PHASE_ALPHA) { dependsOn(named("copyCore")) dependsOn(named("copyGui")) } diff --git a/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/JniCoreConnector.kt b/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/JniCoreConnector.kt index 48c551f..a27a12e 100644 --- a/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/JniCoreConnector.kt +++ b/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/JniCoreConnector.kt @@ -14,7 +14,7 @@ class JniCoreConnector( val libFile: File by lazy { val platform = ConnectorLoader.platform ?: throw IllegalStateException("platform is not supported") val libName = when (platform) { - Platform.WINDOWS -> "libgitnote.dll" + Platform.WINDOWS -> "gitnote.dll" Platform.LINUX -> "libgitnote.so" Platform.INTEL_MAC -> "libgitnote.dylib" Platform.SILICON_MAC -> "libgitnote.dylib" diff --git a/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/ProcessCoreConnector.kt b/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/ProcessCoreConnector.kt index 97b71f8..eb88660 100644 --- a/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/ProcessCoreConnector.kt +++ b/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/core/ProcessCoreConnector.kt @@ -44,7 +44,7 @@ class ProcessCoreConnector( } companion object { - private val isDevelopment = System.getProperty("gitnote.developmentPhase", "false").toBoolean() + private val phase = System.getProperty("gitnote.phase", "1").toInt() private val systemCommand = arrayOf("git", "note") val COMMAND: Array @@ -54,7 +54,7 @@ class ProcessCoreConnector( private fun determineCommand(): Array { val platform = ConnectorLoader.platform - if (isDevelopment || platform == null) { + if (phase == 0 || platform == null) { return systemCommand } val filename = when (platform) { diff --git a/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/jcef/GitNoteViewerWindow.kt b/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/jcef/GitNoteViewerWindow.kt index 7eac8e0..bbaae4f 100644 --- a/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/jcef/GitNoteViewerWindow.kt +++ b/gitnote-jetbrains/src/main/kotlin/io/cjlee/gitnote/jcef/GitNoteViewerWindow.kt @@ -22,13 +22,13 @@ class GitNoteViewerWindow( private val project: Project, private val protocolHandlers: Map ) { - private val isDevelopment = System.getProperty("gitnote.developmentPhase", "false").toBoolean() + private val phase = System.getProperty("gitnote.phase", "1").toInt() val webView: JBCefBrowser = JBCefBrowser.createBuilder() .setOffScreenRendering(false) .build() .apply { - if (isDevelopment) this.loadURL("http://localhost:3000/index.html") + if (phase == 0) this.loadURL("http://localhost:3000/index.html") else this.loadURL("http://gitnote/index.html") registerAppSchemeHandler() @@ -49,7 +49,7 @@ class GitNoteViewerWindow( frontHandler.addHandler("theme", ThemeProtocolHandler()) jsQuery.addHandler(frontHandler) - if (isDevelopment) { + if (phase == 0) { browser.jbCefClient.addDisplayHandler(JCefDebugDisplayHandler(), browser.cefBrowser) // for debugging } }