Skip to content

Commit

Permalink
cleanup & add maven publishing
Browse files Browse the repository at this point in the history
* add auto versioning via git
* add version catalogue
* rename lldevs to v2
* add `youtube-` prefix to built jars
* add lavalink gradle plugin for plugin sub project & remove manual youtube.properties
* update README.md with gradle usage
* add github actions to build & publish
  • Loading branch information
topi314 committed Apr 21, 2024
1 parent 39a29c0 commit b799945
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 32 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Publish
on:
push:
release:
types: [ published ]
jobs:
build:
runs-on: ubuntu-latest
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ vars.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: 17
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 short commit hash for snapshots.
implementation("dev.lavalink.youtube:v2: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 short commit hash 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 short 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
53 changes: 47 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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.2"

allprojects {
group = rootProject.group
version = rootProject.version
group = "dev.lavalink.youtube"
version = versionFromTag()

repositories {
mavenLocal()
Expand All @@ -31,4 +32,44 @@ allprojects {
compileOnly("org.slf4j:slf4j-api:1.7.25")
compileOnly("org.jetbrains:annotations:24.1.0")
}
}
}

subprojects {
afterEvaluate {
plugins.withId(libs.plugins.maven.publish.base.get().pluginId) {
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 ((version as String).endsWith("-SNAPSHOT")) snapshots else releases) {
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 versionFromTag(): String {
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) {
println("Git state is dirty, setting version as snapshot.")
}

return if (headTag != null && clean) headTag.name else "${git.head().id}-SNAPSHOT"
}
}
8 changes: 6 additions & 2 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
plugins {
`java-library`
`maven-publish`
alias(libs.plugins.maven.publish.base)
}

val moduleName = "common"

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

tasks.jar {
archiveBaseName.set("youtube-common")
}

val sourcesJar by tasks.registering(Jar::class) {
Expand Down
27 changes: 17 additions & 10 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
plugins {
`java-library`
`maven-publish`
alias(libs.plugins.lavalink.gradle.plugin)
}

val moduleName = "plugin"

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

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)
}

java {
Expand All @@ -19,15 +26,15 @@ java {
}

val sourcesJar by tasks.registering(Jar::class) {
archiveBaseName.set("youtube-plugin")
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
dependsOn(projects.common.dependencyProject.tasks.jar)
dependsOn(projects.v2.dependencyProject.tasks.jar)
archiveBaseName.set(moduleName)
}

publishing {
Expand Down
3 changes: 0 additions & 3 deletions plugin/src/main/resources/lavalink-plugins/youtube.properties

This file was deleted.

28 changes: 27 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
include("lldevs")
rootProject.name = "youtube-source"

include("v2")
include("common")
include("plugin")

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
version("lavaplayer-v1", "1.5.3")
version("lavaplayer-v2", "2.1.1")

library("lavaplayer-v1", "dev.arbjerg", "lavaplayer").versionRef("lavaplayer-v1")
library("lavaplayer-v2", "dev.arbjerg", "lavaplayer").versionRef("lavaplayer-v2")

version("lavalink", "3.7.11")
library("lavalink-server", "dev.arbjerg.lavalink", "Lavalink-Server").versionRef("lavalink")
library("lavaplayer-ext-youtube-rotator", "dev.arbjerg", "lavaplayer-ext-youtube-rotator").versionRef("lavaplayer-v1")

plugin("lavalink-gradle-plugin", "dev.arbjerg.lavalink.gradle-plugin").version("1.0.15")

val mavenPublishPlugin = version("maven-publish-plugin", "0.25.3")
plugin("maven-publish", "com.vanniktech.maven.publish").versionRef(mavenPublishPlugin)
plugin("maven-publish-base", "com.vanniktech.maven.publish.base").versionRef(mavenPublishPlugin)
}
}
}
12 changes: 8 additions & 4 deletions lldevs/build.gradle.kts → v2/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
plugins {
`java-library`
`maven-publish`
alias(libs.plugins.maven.publish.base)
}

val moduleName = "lldevs"
val moduleName = "v2"

dependencies {
compileOnly(project(":common"))
compileOnly("dev.arbjerg:lavaplayer:2.1.1")
compileOnly(projects.common)
compileOnly(libs.lavaplayer.v2)
}

tasks.jar {
archiveBaseName.set("youtube-v2")
}

val sourcesJar by tasks.registering(Jar::class) {
Expand Down

0 comments on commit b799945

Please sign in to comment.