From 624a4964c119184e15c1c58856bde0308a2ecb50 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 18 Jul 2024 04:30:10 +0200 Subject: [PATCH] build(Needs bump): Use ReVanced Patches Gradle plugin to configure the build system --- .github/workflows/build_pull_request.yml | 6 + .github/workflows/release.yml | 6 + .releaserc | 3 +- README.md | 17 +-- build.gradle.kts | 137 ------------------ extensions/extension/build.gradle.kts | 7 + .../extension/src/main/AndroidManifest.xml | 1 + .../revanced/extension/ExampleExtension.java | 7 + gradle/libs.versions.toml | 4 +- .../api/patches.api | 0 patches/build.gradle.kts | 13 ++ .../revanced/patches/example/ExamplePatch.kt | 2 + settings.gradle.kts | 19 ++- 13 files changed, 70 insertions(+), 152 deletions(-) delete mode 100644 build.gradle.kts create mode 100644 extensions/extension/build.gradle.kts create mode 100644 extensions/extension/src/main/AndroidManifest.xml create mode 100644 extensions/extension/src/main/java/app/revanced/extension/ExampleExtension.java rename api/revanced-patches-template.api => patches/api/patches.api (100%) create mode 100644 patches/build.gradle.kts rename {src => patches/src}/main/kotlin/app/revanced/patches/example/ExamplePatch.kt (88%) diff --git a/.github/workflows/build_pull_request.yml b/.github/workflows/build_pull_request.yml index 250871bcc..193a26af0 100644 --- a/.github/workflows/build_pull_request.yml +++ b/.github/workflows/build_pull_request.yml @@ -16,6 +16,12 @@ jobs: with: fetch-depth: 0 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + - name: Cache Gradle uses: burrunan/gradle-cache-action@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 574ee8cfd..9cdd88d59 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,6 +20,12 @@ jobs: persist-credentials: false fetch-depth: 0 + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + - name: Cache Gradle uses: burrunan/gradle-cache-action@v1 diff --git a/.releaserc b/.releaserc index 2c9aca9c2..fc8fd5f15 100644 --- a/.releaserc +++ b/.releaserc @@ -24,7 +24,6 @@ "README.md", "CHANGELOG.md", "gradle.properties", - "patches.json" ] } ], @@ -33,7 +32,7 @@ { "assets": [ { - "path": "build/libs/revanced-patches*" + "path": "patches/build/libs/*.rvp" } ], successComment: false diff --git a/README.md b/README.md index 4ceb767cb..577b48668 100644 --- a/README.md +++ b/README.md @@ -10,15 +10,15 @@ For an example repository, see [ReVanced Patches](https://github.com/revanced/re To start using this template, follow these steps: 1. [Create a new repository using this template](https://github.com/new?template_name=revanced-patches-template&template_owner=ReVanced) -2. Set up the [build.gradle.kts](build.gradle.kts) file (Specifically, the [group of the project](build.gradle.kts#L11), -[manifest attributes](build.gradle.kts#L44-L54), and the [POM](build.gradle.kts#L105-L128)) +2. Set up the [build.gradle.kts](patches/build.gradle.kts) file (Specifically, the [group of the project](patches/build.gradle.kts#L1), +and the [About](patches/build.gradle.kts#L5-L11)) 3. Update dependencies in the [libs.versions.toml](gradle/libs.versions.toml) file 4. [Create a pass-phrased GPG master key and subkey](https://mikeross.xyz/create-gpg-key-pair-with-subkeys/) - 1. Add the private key as a secret named [GPG_PRIVATE_KEY](.github/workflows/release.yml#L43) to your repository - 2. Add the passphrase as a secret named [GPG_PASSPHRASE](.github/workflows/release.yml#L44) to your repository - 3. Add the fingerprint of the GPG subkey as a secret named [GPG_FINGERPRINT](.github/workflows/release.yml#L45) to your repository + 1. Add the private key as a secret named [GPG_PRIVATE_KEY](.github/workflows/release.yml#L48) to your repository + 2. Add the passphrase as a secret named [GPG_PASSPHRASE](.github/workflows/release.yml#L49) to your repository + 3. Add the fingerprint of the GPG subkey as a secret named [GPG_FINGERPRINT](.github/workflows/release.yml#L50) to your repository 6. [Create a PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) with [push access](https://github.com/semantic-release/semantic-release/blob/master/docs/usage/ci-configuration.md#authentication) - 1. Add it as a secret named [REPOSITORY_PUSH_ACCESS](.github/workflows/release.yml#L49) to your repository + 1. Add it as a secret named [REPOSITORY_PUSH_ACCESS](.github/workflows/release.yml#L54) to your repository 7. Set up the [README.md](README.md) file[^1] (e.g, title, description, license, summary of the patches that are included in the repository) @@ -48,9 +48,8 @@ To develop and release ReVanced Patches using this template, some things need to via the [release.yml](.github/workflows/release.yml) workflow, which is also responsible for generating the changelog and updating the version of ReVanced Patches. It is triggered by pushing to the `dev` or `main` branch. The workflow uses the `publish` task to publish the release of ReVanced Patches -- To build ReVanced Patches that can be used on Android, the [`buildDexJar`](build.gradle.kts#L50-L73) task must be run. -The [`publish` task depends on the `buildDexJar`](build.gradle.kts#L78) task, -so it will be run automatically when publishing a release. +- The `buildAndroid` task is used to build ReVanced Patches so that it can be used on Android. +The `publish` task depends on the `buildAndroid` task, so it will be run automatically when publishing a release. ## 📚 Everything else diff --git a/build.gradle.kts b/build.gradle.kts deleted file mode 100644 index e16972614..000000000 --- a/build.gradle.kts +++ /dev/null @@ -1,137 +0,0 @@ -import org.gradle.kotlin.dsl.support.listFilesOrdered -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - -plugins { - alias(libs.plugins.kotlin) - alias(libs.plugins.binary.compatibility.validator) - `maven-publish` - signing -} - -group = "app.revanced" - -repositories { - mavenCentral() - mavenLocal() - google() - maven { - // A repository must be specified for some reason. "registry" is a dummy. - url = uri("https://maven.pkg.github.com/revanced/registry") - credentials { - username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") - password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") - } - } -} - -dependencies { - implementation(libs.revanced.patcher) - implementation(libs.smali) -} - -kotlin { - compilerOptions { - jvmTarget.set(JvmTarget.JVM_11) - } -} - -java { - targetCompatibility = JavaVersion.VERSION_11 -} - -tasks { - withType(Jar::class) { - manifest { - attributes["Name"] = "ReVanced Patches template" - attributes["Description"] = "Patches template for ReVanced." - attributes["Version"] = version - attributes["Timestamp"] = System.currentTimeMillis().toString() - attributes["Source"] = "git@github.com:revanced/revanced-patches-template.git" - attributes["Author"] = "ReVanced" - attributes["Contact"] = "contact@revanced.app" - attributes["Origin"] = "https://revanced.app" - attributes["License"] = "GNU General Public License v3.0" - } - } - - register("buildDexJar") { - description = "Build and add a DEX to the JAR file" - group = "build" - - dependsOn(build) - - doLast { - val d8 = File(System.getenv("ANDROID_HOME")).resolve("build-tools") - .listFilesOrdered().last().resolve("d8").absolutePath - - val patchesJar = configurations.archives.get().allArtifacts.files.files.first().absolutePath - val workingDirectory = layout.buildDirectory.dir("libs").get().asFile - - exec { - workingDir = workingDirectory - commandLine = listOf(d8, "--release", patchesJar) - } - - exec { - workingDir = workingDirectory - commandLine = listOf("zip", "-u", patchesJar, "classes.dex") - } - } - } - - // Needed by gradle-semantic-release-plugin. - // Tracking: https://github.com/KengoTODA/gradle-semantic-release-plugin/issues/435 - publish { - dependsOn("buildDexJar") - } -} - -publishing { - repositories { - maven { - name = "GitHubPackages" - url = uri("https://maven.pkg.github.com/revanced/revanced-patches-template") - credentials { - username = System.getenv("GITHUB_ACTOR") - password = System.getenv("GITHUB_TOKEN") - } - } - } - - publications { - create("revanced-patches-publication") { - from(components["java"]) - - pom { - name = "ReVanced Patches template" - description = "Patches template for ReVanced." - url = "https://revanced.app" - - licenses { - license { - name = "GNU General Public License v3.0" - url = "https://www.gnu.org/licenses/gpl-3.0.en.html" - } - } - developers { - developer { - id = "ReVanced" - name = "ReVanced" - email = "contact@revanced.app" - } - } - scm { - connection = "scm:git:git://github.com/revanced/revanced-patches-template.git" - developerConnection = "scm:git:git@github.com:revanced/revanced-patches-template.git" - url = "https://github.com/revanced/revanced-patches-template" - } - } - } - } -} - -signing { - useGpgCmd() - - sign(publishing.publications["revanced-patches-publication"]) -} diff --git a/extensions/extension/build.gradle.kts b/extensions/extension/build.gradle.kts new file mode 100644 index 000000000..f404582d2 --- /dev/null +++ b/extensions/extension/build.gradle.kts @@ -0,0 +1,7 @@ +extension { + name = "extensions/extension.rve" +} + +android { + namespace = "app.revanced.extension" +} diff --git a/extensions/extension/src/main/AndroidManifest.xml b/extensions/extension/src/main/AndroidManifest.xml new file mode 100644 index 000000000..9b65eb06c --- /dev/null +++ b/extensions/extension/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/extensions/extension/src/main/java/app/revanced/extension/ExampleExtension.java b/extensions/extension/src/main/java/app/revanced/extension/ExampleExtension.java new file mode 100644 index 000000000..87ebc1244 --- /dev/null +++ b/extensions/extension/src/main/java/app/revanced/extension/ExampleExtension.java @@ -0,0 +1,7 @@ +package app.revanced.extension; + +public class ExampleExtension { + public static void get() { + // TODO("Not yet implemented") + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7db954618..0f123f167 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,3 +1,5 @@ [versions] revanced-patcher = "20.0.0" -smali = "3.0.7" +# Tracking https://github.com/google/smali/issues/64. +#noinspection GradleDependency +smali = "3.0.5" diff --git a/api/revanced-patches-template.api b/patches/api/patches.api similarity index 100% rename from api/revanced-patches-template.api rename to patches/api/patches.api diff --git a/patches/build.gradle.kts b/patches/build.gradle.kts new file mode 100644 index 000000000..beb08f2b9 --- /dev/null +++ b/patches/build.gradle.kts @@ -0,0 +1,13 @@ +group = "app.revanced" + +patches { + about { + name = "ReVanced Patches template" + description = "Patches template for ReVanced" + source = "git@github.com:revanced/revanced-patches-template.git" + author = "ReVanced" + contact = "contact@revanced.app" + website = "https://revanced.app" + license = "GNU General Public License v3.0" + } +} diff --git a/src/main/kotlin/app/revanced/patches/example/ExamplePatch.kt b/patches/src/main/kotlin/app/revanced/patches/example/ExamplePatch.kt similarity index 88% rename from src/main/kotlin/app/revanced/patches/example/ExamplePatch.kt rename to patches/src/main/kotlin/app/revanced/patches/example/ExamplePatch.kt index df68ee607..277dc5b33 100644 --- a/src/main/kotlin/app/revanced/patches/example/ExamplePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/example/ExamplePatch.kt @@ -9,6 +9,8 @@ val examplePatch = bytecodePatch( ) { compatibleWith("com.example.app"("1.0.0")) + extendWith("extensions/extension.rve") + execute { // TODO("Not yet implemented") } diff --git a/settings.gradle.kts b/settings.gradle.kts index 50d0be92b..d81d22ba1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,20 @@ rootProject.name = "revanced-patches-template" -buildCache { - local { - isEnabled = "CI" !in System.getenv() +pluginManagement { + repositories { + gradlePluginPortal() + google() + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/revanced/registry") + credentials { + username = providers.gradleProperty("gpr.user").orNull ?: System.getenv("GITHUB_ACTOR") + password = providers.gradleProperty("gpr.key").orNull ?: System.getenv("GITHUB_TOKEN") + } + } } } + +plugins { + id("app.revanced.patches") version "1.0.0-dev.4" +}