Skip to content

Commit

Permalink
Distribute CLI (#14)
Browse files Browse the repository at this point in the history
* Add installer

* apiDump + make everything internal
  • Loading branch information
martinbonnin authored Aug 1, 2024
1 parent 100ccf0 commit 9f1c914
Show file tree
Hide file tree
Showing 27 changed files with 521 additions and 170 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: check-pull-request
name: Build pull request

on: pull_request

jobs:
check-pull-request:
build-pull-request:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2
- run: |
./gradlew build
26 changes: 26 additions & 0 deletions .github/workflows/publish-pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish documentation

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

jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
with:
fetch-depth: 0

- uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2
- run: |
export JAVA_HOME=$JAVA_HOME_21_X64 # Remove when ubuntu-latest updates to Java 21
./gradlew dokkatooGeneratePublicationHtml
mkdir -p build/static
cp -rf build/dokka/html build/static/kdoc
- uses: JamesIves/github-pages-deploy-action@94f3c658273cf92fb48ef99e5fbc02bd2dc642b2 #v4.6.3
with:
branch: gh-pages # The branch the action should deploy to.
folder: build/static # The folder the action should deploy.
6 changes: 4 additions & 2 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: publish-release
name: Publish release

on:
workflow_dispatch:
Expand All @@ -12,9 +12,11 @@ jobs:

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2
- run: |
./gradlew librarianPublishToMavenCentral
./gradlew librarianPublishToMavenCentral distZip
gh release create $GITHUB_REF_NAME --title $GITHUB_REF_NAME --verify-tag --notes-from-tag
gh release upload $GITHUB_REF_NAME apollo-cli/build/distributions/apollo-kotlin-cli-${GITHUB_REF_NAME##v}.zip
env:
LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.LIBRARIAN_SONATYPE_USERNAME }}
LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.LIBRARIAN_SONATYPE_PASSWORD }}
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/publish-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: publish-snapshot
name: Publish snapshot

on:
push:
Expand All @@ -9,8 +9,9 @@ jobs:

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: gradle/actions/setup-gradle@dbbdc275be76ac10734476cc723d82dfe7ec6eda #v3.4.2
- run: |
./gradlew librarianPublishToMavenSnapshots
./gradlew librarianPublishToSnapshots
env:
LIBRARIAN_SONATYPE_USERNAME: ${{ secrets.LIBRARIAN_SONATYPE_USERNAME }}
LIBRARIAN_SONATYPE_PASSWORD: ${{ secrets.LIBRARIAN_SONATYPE_PASSWORD }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: prepare-release
name: Tag and bump

on:
workflow_dispatch:
Expand All @@ -9,12 +9,12 @@ on:
type: string

jobs:
prepare-release:
tag-and-bump:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7
- uses: gradleup/librarian/prepare-release@main
- uses: gradleup/librarian/tag-and-bump@2cdb4fa8a36657aec1b52d2c5ec836f04713a80c #v0.0.4
with:
versionToRelease: ${{ inputs.versionToRelease }}
# Trigger a workflow manually because actions cannot trigger workflows to avoid endless loops
Expand Down
48 changes: 0 additions & 48 deletions .github/workflows/update-docs.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions Writerside/c.list

This file was deleted.

18 changes: 0 additions & 18 deletions Writerside/cfg/buildprofiles.xml

This file was deleted.

12 changes: 0 additions & 12 deletions Writerside/doc.tree

This file was deleted.

14 changes: 0 additions & 14 deletions Writerside/images/apollo_logo.svg

This file was deleted.

Binary file removed Writerside/images/favicon-192x192.png
Binary file not shown.
Binary file removed Writerside/images/favicon-96x96.png
Binary file not shown.
8 changes: 0 additions & 8 deletions Writerside/topics/welcome.md

This file was deleted.

6 changes: 0 additions & 6 deletions Writerside/v.list

This file was deleted.

8 changes: 0 additions & 8 deletions Writerside/writerside.cfg

This file was deleted.

4 changes: 4 additions & 0 deletions apollo-cli/api/apollo-cli.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ public final class com/apollographql/cli/MainKt {
public static final fun main ([Ljava/lang/String;)V
}

public final class com/apollographql/cli/VersionKt {
public static final field VERSION Ljava/lang/String;
}

14 changes: 13 additions & 1 deletion apollo-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import com.gradleup.librarian.gradle.librarianModule

plugins {
id("org.jetbrains.kotlin.jvm")
alias(libs.plugins.serialization)
alias(libs.plugins.kotlin)
id("application")
}

dependencies {
implementation(libs.clikt)
implementation(libs.serialization.json)
implementation(libs.apollo.tooling)
implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.datetime)
implementation(libs.okhttp)
implementation(libs.jsonpathkt)
implementation(libs.mordant)
}

librarianModule(true)

application {
mainClass.set("com.apollographql.cli.MainKt")
applicationName = "apollo-kotlin-cli"
}
1 change: 1 addition & 0 deletions apollo-cli/librarian.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version.packageName=com.apollographql.cli
77 changes: 77 additions & 0 deletions apollo-cli/src/main/kotlin/com/apollographql/cli/InstallCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.apollographql.cli

import com.github.ajalt.clikt.core.CliktCommand
import java.io.File
import kotlin.system.exitProcess

private val initFilename = "init.sh"
internal val home = File(System.getProperty("user.home"))
internal val installDir = home.resolve(".apollo-kotlin-cli")

/**
* The install command is run from the install.sh script and finishes installation:
* - copies files to ~/.apollo-kotlin-cli
* - add ~/.apollo-kotlin-cli/init.sh to the .zshrc/.bashrc
*/
internal class InstallCommand : CliktCommand(
hidden = true,
help = "installs apollo-kotlin-cli in your home directory"
) {

private fun copyFiles() {
val uri = this::class.java.protectionDomain.codeSource.location.toURI()
if (uri.scheme != "file") {
System.err.println("Cannot install from non-file location '$uri'")
exitProcess(1)
}

val sourceDir = File(uri.path).parentFile.parentFile

sourceDir.resolve("lib").apply {
check(exists()) {
"Cannot find '$path': was this installed from a distribution?"
}
}
sourceDir.resolve("bin").apply {
check(exists()) {
"Cannot find '$path': was this installed from a distribution?"
}
}

sourceDir.copyRecursively(installDir, overwrite = true)

installDir.resolve("bin/apollo-kotlin-cli").setExecutable(true)

println("apollo-kotlin-cli has been installed in '${installDir.path}' ✅")

installDir.resolve(initFilename).writeText("""
export PATH="$installDir/bin:${'$'}PATH"
""".trimIndent())
}

override fun run() {
copyFiles()

val source = "source \"${installDir.resolve(initFilename)}\""
var found = false
listOf(".zshrc", ".bashrc").forEach {
home.resolve(it).apply {
if (exists()) {
found = true
if (!readText().contains(source)) {
appendText("\n")
appendText(source)
}
}
}
}

if (!found) {
println("Cannot detect your shell. Add the following to your init scripts:")
println(source)
} else {
println("Open a new terminal or run the command below to start using apollo-kotlin-cli")
println(source)
}
}
}
Loading

0 comments on commit 9f1c914

Please sign in to comment.