Skip to content

Commit

Permalink
cleanup & add maven publishing (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 authored May 5, 2024
1 parent 9b233d8 commit f27d209
Show file tree
Hide file tree
Showing 20 changed files with 290 additions and 94 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: 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ replay_pid*
.idea/*
.DS_Store
*/build/*
build
build

application.yml
63 changes: 57 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,32 +46,67 @@ 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.

<details>
<summary>Using with Lavalink v3:</summary>

```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"
repository: "https://maven.lavalink.dev/releases" # use https://maven.lavalink.dev/snapshots if you want to use a snapshot version.
```
</details>
<details>
<summary>Using with Lavalink v4:</summary>
```yaml
lavalink:
plugins:
# 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.
```
</details>
Configuring the plugin:
```yaml
plugins:
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.

Loading

0 comments on commit f27d209

Please sign in to comment.