Skip to content

Commit

Permalink
cleanup & add maven publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed May 3, 2024
1 parent 59fe892 commit 6bb4f33
Show file tree
Hide file tree
Showing 19 changed files with 264 additions and 93 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Publish
on:
push:
release:
types: [ published ]
jobs:
build:
runs-on: ubuntu-latest
env:
MAVEN_USERNAME: ${{ vars.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
cache: gradle

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Build and Publish
run: ./gradlew build publish --no-daemon -PMAVEN_USERNAME=$MAVEN_USERNAME -PMAVEN_PASSWORD=$MAVEN_PASSWORD

- name: Upload common Artifact
uses: actions/upload-artifact@v3
with:
name: youtube-common.jar
path: common/build/libs/youtube-common-*.jar

- name: Upload lldevs Artifact
uses: actions/upload-artifact@v3
with:
name: youtube-v2.jar
path: v2/build/libs/youtube-v2-*.jar

- name: Upload plugin Artifact
uses: actions/upload-artifact@v3
with:
name: youtube-plugin.jar
path: plugin/build/libs/youtube-plugin-*.jar

release:
needs: build
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download youtube-common Artifact
uses: actions/download-artifact@v3
with:
name: youtube-common.jar

- name: Download youtube-v2 Artifact
uses: actions/download-artifact@v3
with:
name: youtube-v2.jar

- name: Download youtube-plugin Artifact
uses: actions/download-artifact@v3
with:
name: youtube-plugin.jar

- name: Upload Artifacts to GitHub Release
uses: ncipollo/release-action@v1
with:
artifacts: '*.jar'
allowUpdates: true
omitBodyDuringUpdate: true
omitDraftDuringUpdate: true
omitNameDuringUpdate: true
omitPrereleaseDuringUpdate: true
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ Which clients are used is entirely configurable.
This module provides the base source manager, which can be used with any
`com.sedmelluq.discord.lavaplayer` packages still on major version `1`.

<details>
<summary>Using in Gradle:</summary>

```kotlin
repositories {
// replace with https://maven.lavalink.dev/snapshots if you want to use a snapshot version.
maven(url = "https://maven.lavalink.dev/releases")
}

dependencies {
// Replace VERSION with the current version as shown by the Releases tab or a long commit hash `-SNAPSHOT` for snapshots.
implementation("dev.lavalink.youtube:common:VERSION")
}
```

</details>
Example usage:
```java
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager();
Expand All @@ -30,30 +46,46 @@ rotator.forConfiguration(youtube.getHttpInterfaceManager(), false)
.setup();
```

## lldevs
## v2
This modules expands on `common` by providing additional support for
Lavaplayer `2.x` clients, such as [Lavalink-Devs/Lavaplayer](https://github.com/lavalink-devs/lavaplayer).
Such features currently include thumbnail support within `AudioTrackInfo`.
Additional clients are included that provide access to this additional information.
These clients are suffixed with `Thumbnail`, such as `WebWithThumbnail`, `AndroidWithThumbnail` etc.

<details>
<summary>Using in Gradle:</summary>

```kotlin
repositories {
// replace with https://maven.lavalink.dev/snapshots if you want to use a snapshot version.
maven(url = "https://maven.lavalink.dev/releases")
}

dependencies {
// Replace VERSION with the current version as shown by the Releases tab or a long commit hash `-SNAPSHOT` for snapshots.
implementation("dev.lavalink.youtube:v2:VERSION")
}
```

</details>

Example usage:
```java
// same as the 'common' module but there are additional clients that provide video thumbnails in the returned metadata.
YoutubeAudioSourceManager youtube = new YoutubeAudioSourceManager(/*allowSearch:*/ true, new Client[] { new MusicWithThumbnail(), new WebWithThumbnail(), new AndroidWithThumbnail() });
```

## plugin
This module serves as the plugin for use with [Lavalink](https://github.com/lavalink-devs/lavalink).
This module serves as the plugin for use with [Lavalink](https://github.com/lavalink-devs/Lavalink).

To use this plugin with Lavalink, you must declare the dependency.
```yaml
lavalink:
# ...
plugins:
# replace VERSION with the current version as shown by the Releases tab.
- dependency: "com.github.lavalink-devs.lavaplayer-youtube-source:plugin:VERSION"
repository: "https://jitpack.io"
# Replace VERSION with the current version as shown by the Releases tab or a long commit hash for snapshots.
- dependency: "dev.lavalink.youtube:youtube-plugin:VERSION"
snapshot: false # Set to true if you want to use a snapshot version.
```
Configuring the plugin:
Expand Down
64 changes: 51 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
import org.ajoberstar.grgit.Grgit

plugins {
java
`maven-publish`
id("org.ajoberstar.grgit") version "5.2.0"
alias(libs.plugins.maven.publish.base) apply false
}

group = "dev.lavalink.youtube"
version = "1.0.7"
val (gitVersion, release) = versionFromGit()
logger.lifecycle("Version: $gitVersion (release: $release)")

allprojects {
group = rootProject.group
version = rootProject.version
group = "dev.lavalink.youtube"
// The plugin project is the only one that should not have a snapshot version since lavalink expects the jar name to be specific
version = if (project.name == "plugin") {
gitVersion.removeSuffix("-SNAPSHOT")
} else {
gitVersion
}


repositories {
mavenLocal()
mavenCentral()
maven(url = "https://maven.lavalink.dev/releases")
maven(url = "https://jitpack.io")
}
}

apply(plugin = "java")
apply(plugin = "maven-publish")
subprojects {
apply<JavaPlugin>()
apply<MavenPublishPlugin>()

java {
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
implementation("org.mozilla:rhino-engine:1.7.14")
implementation("com.grack:nanojson:1.7")
compileOnly("org.slf4j:slf4j-api:1.7.25")
compileOnly("org.jetbrains:annotations:24.1.0")
configure<PublishingExtension> {
if (findProperty("MAVEN_PASSWORD") != null && findProperty("MAVEN_USERNAME") != null) {
repositories {
val snapshots = "https://maven.lavalink.dev/snapshots"
val releases = "https://maven.lavalink.dev/releases"

maven(if (release) releases else snapshots) {
credentials {
password = findProperty("MAVEN_PASSWORD") as String?
username = findProperty("MAVEN_USERNAME") as String?
}
}
}
} else {
logger.lifecycle("Not publishing to maven.lavalink.dev because credentials are not set")
}
}
}

@SuppressWarnings("GrMethodMayBeStatic")
fun versionFromGit(): Pair<String, Boolean> {
Grgit.open(mapOf("currentDir" to project.rootDir)).use { git ->
val headTag = git.tag
.list()
.find { it.commit.id == git.head().id }

val clean = git.status().isClean || System.getenv("CI") != null
if (!clean) {
logger.lifecycle("Git state is dirty, version is a snapshot.")
}

return if (headTag != null && clean) headTag.name to true else "${git.head().id}-SNAPSHOT" to false
}
}
31 changes: 15 additions & 16 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar

plugins {
`java-library`
`maven-publish`
alias(libs.plugins.maven.publish.base)
}

val moduleName = "common"
base {
archivesName = "youtube-common"
}

dependencies {
compileOnly("dev.arbjerg:lavaplayer:1.5.3")
}
compileOnly(libs.lavaplayer.v1)

val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
implementation(libs.rhino.engine)
implementation(libs.nanojson)
compileOnly(libs.slf4j)
compileOnly(libs.annotations)
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifactId = moduleName
artifact(sourcesJar)
}
}
}
mavenPublishing {
configure(JavaLibrary(JavadocJar.Javadoc()))
}
Empty file added gradle.properties
Empty file.
26 changes: 0 additions & 26 deletions lldevs/build.gradle.kts

This file was deleted.

54 changes: 26 additions & 28 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar

plugins {
`java-library`
`maven-publish`
alias(libs.plugins.lavalink.gradle.plugin)
alias(libs.plugins.maven.publish.base)
}

val moduleName = "plugin"
lavalinkPlugin {
name = "youtube-plugin"
path = "dev.lavalink.youtube.plugin"
apiVersion = libs.versions.lavalink
serverVersion = "4.0.4"
configurePublishing = false
}

base {
archivesName = "youtube-plugin"
}

dependencies {
implementation(project(":common"))
implementation(project(":lldevs"))
compileOnly("dev.arbjerg.lavalink:plugin-api:3.7.11")
compileOnly("dev.arbjerg.lavalink:Lavalink-Server:3.7.11")
compileOnly("dev.arbjerg:lavaplayer-ext-youtube-rotator:1.5.3")
implementation(projects.common)
implementation(projects.v2)
compileOnly(libs.lavalink.server)
compileOnly(libs.lavaplayer.ext.youtube.rotator)
compileOnly(libs.slf4j)
compileOnly(libs.annotations)
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

val sourcesJar by tasks.registering(Jar::class) {
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
}

tasks.jar {
dependsOn(project(":common").tasks.jar)
dependsOn(project(":lldevs").tasks.jar)
from(configurations.runtimeClasspath.get().map(::zipTree))
duplicatesStrategy = DuplicatesStrategy.WARN
}

publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
artifactId = moduleName
artifact(sourcesJar)
}
}
}
mavenPublishing {
coordinates("dev.lavalink.youtube", "youtube-plugin", version.toString())
configure(JavaLibrary(JavadocJar.None(), sourcesJar = false))
}
3 changes: 0 additions & 3 deletions plugin/src/main/resources/lavalink-plugins/youtube.properties

This file was deleted.

Loading

0 comments on commit 6bb4f33

Please sign in to comment.