Template
mirror of
https://github.com/MorpheApp/morphe-patches-template.git
synced 2026-12-01 00:19:34 +00:00
chore: Add PatchListGenerator (#6)
This commit is contained in:
1 parent
01b9822788
commit
2f671f4daa
16 files changed
+1056
-668
No files matched your search
@@ -12,18 +12,18 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Setup Java
|
- name: Setup Java
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
|
|
||||||
- name: Cache Gradle
|
- name: Cache Gradle
|
||||||
uses: burrunan/gradle-cache-action@v2
|
uses: burrunan/gradle-cache-action@v3
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: ./gradlew build --no-daemon
|
run: ./gradlew :patches:buildAndroid --no-daemon
|
||||||
@@ -15,7 +15,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Open pull request
|
- name: Open pull request
|
||||||
uses: repo-sync/pull-request@v2
|
uses: repo-sync/pull-request@v2
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Setup Java
|
- name: Setup Java
|
||||||
uses: actions/setup-java@v4
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: 'temurin'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
@@ -32,10 +32,10 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: ./gradlew build clean
|
run: ./gradlew :patches:buildAndroid generatePatchesList clean
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: 'lts/*'
|
node-version: 'lts/*'
|
||||||
cache: 'npm'
|
cache: 'npm'
|
||||||
@@ -51,14 +51,20 @@ jobs:
|
|||||||
fingerprint: ${{ vars.GPG_FINGERPRINT }}
|
fingerprint: ${{ vars.GPG_FINGERPRINT }}
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
uses: cycjimmy/semantic-release-action@v4
|
uses: cycjimmy/semantic-release-action@v5
|
||||||
id: release
|
id: release
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Attest
|
- name: Attest
|
||||||
if: steps.release.outputs.new_release_published == 'true'
|
if: steps.release.outputs.new_release_published == 'true'
|
||||||
uses: actions/attest-build-provenance@v2
|
uses: actions/attest-build-provenance@v3
|
||||||
with:
|
with:
|
||||||
subject-name: 'Patches ${{ steps.release.outputs.new_release_git_tag }}'
|
subject-name: 'Morphe Patches ${{ steps.release.outputs.new_release_git_tag }}'
|
||||||
subject-path: patches/build/libs/patches-*.mpp
|
subject-path: patches/build/libs/patches-*.mpp
|
||||||
|
|
||||||
|
- name: Purge jsDelivr Cache
|
||||||
|
run: |
|
||||||
|
for file in patches-bundle.json patches-list.json; do
|
||||||
|
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@${{ github.ref_name }}/$file"
|
||||||
|
done
|
||||||
+18
-3
@@ -15,15 +15,30 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"@semantic-release/release-notes-generator",
|
"@semantic-release/release-notes-generator",
|
||||||
"@semantic-release/changelog",
|
[
|
||||||
|
"@MorpheApp/changelog", {
|
||||||
|
"releaseJson": {
|
||||||
|
"path": "patches-bundle.json",
|
||||||
|
"downloadUrlTemplate": "https://github.com/${owner}/${repo}/releases/download/v${version}/patches-${version}.mpp",
|
||||||
|
"signatureUrlTemplate": "https://github.com/${owner}/${repo}/releases/download/v${version}/patches-${version}.mpp.asc"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"gradle-semantic-release-plugin",
|
"gradle-semantic-release-plugin",
|
||||||
|
[
|
||||||
|
"@semantic-release/exec",
|
||||||
|
{
|
||||||
|
"prepareCmd": "jq '.version=\"${nextRelease.version}\"' patches-list.json > patches-list.json.tmp && mv patches-list.json.tmp patches-list.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"@semantic-release/git",
|
"@semantic-release/git",
|
||||||
{
|
{
|
||||||
"assets": [
|
"assets": [
|
||||||
"README.md",
|
|
||||||
"CHANGELOG.md",
|
"CHANGELOG.md",
|
||||||
"gradle.properties"
|
"gradle.properties",
|
||||||
|
"patches-bundle.json",
|
||||||
|
"patches-list.json"
|
||||||
],
|
],
|
||||||
"message": "chore: Release v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
"message": "chore: Release v${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,7 @@
|
|||||||
morphe-patcher = "1.0.1"
|
morphe-patcher = "1.0.1"
|
||||||
#noinspection GradleDependency
|
#noinspection GradleDependency
|
||||||
smali = "b6365a84f4"
|
smali = "b6365a84f4"
|
||||||
|
gson = "2.13.2"
|
||||||
|
|
||||||
|
[libraries]
|
||||||
|
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
|
||||||
Vendored
BIN
Binary file not shown.
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
|
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
' "$PWD" ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
@@ -115,7 +114,7 @@ case "$( uname )" in #(
|
|||||||
NONSTOP* ) nonstop=true ;;
|
NONSTOP* ) nonstop=true ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
# Determine the Java command to use to start the JVM.
|
||||||
@@ -206,7 +205,7 @@ fi
|
|||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
# Collect all arguments for the java command:
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
# and any embedded shellness will be escaped.
|
# and any embedded shellness will be escaped.
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
# treated as '${Hostname}' itself on the command line.
|
# treated as '${Hostname}' itself on the command line.
|
||||||
@@ -214,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|||||||
set -- \
|
set -- \
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
-classpath "$CLASSPATH" \
|
-classpath "$CLASSPATH" \
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
"$@"
|
"$@"
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
# Stop when "xargs" is not available.
|
||||||
|
|||||||
Vendored
+2
-2
@@ -70,11 +70,11 @@ goto fail
|
|||||||
:execute
|
:execute
|
||||||
@rem Setup the command line
|
@rem Setup the command line
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
@rem Execute Gradle
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
|||||||
Generated
+836
-642
File diff suppressed because it is too large.
Load diff
+3
-2
@@ -1,9 +1,10 @@
|
|||||||
{
|
{
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@saithodev/semantic-release-backmerge": "^4.0.1",
|
"@saithodev/semantic-release-backmerge": "^4.0.1",
|
||||||
"@semantic-release/changelog": "^6.0.3",
|
"@MorpheApp/changelog": "git+https://github.com/MorpheApp/changelog.git#bundle",
|
||||||
|
"@semantic-release/exec": "^6.0.3",
|
||||||
"@semantic-release/git": "^10.0.1",
|
"@semantic-release/git": "^10.0.1",
|
||||||
"gradle-semantic-release-plugin": "^1.10.1",
|
"gradle-semantic-release-plugin": "^1.10.1",
|
||||||
"semantic-release": "^24.1.2"
|
"semantic-release": "^24.2.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"created_at": "",
|
||||||
|
"description": "",
|
||||||
|
"download_url": "",
|
||||||
|
"signature_download_url": "",
|
||||||
|
"version": ""
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"version": "",
|
||||||
|
"patches": []
|
||||||
|
}
|
||||||
@@ -2,3 +2,7 @@ public final class app/morphe/patches/example/ExamplePatchKt {
|
|||||||
public static final fun getExamplePatch ()Lapp/morphe/patcher/patch/BytecodePatch;
|
public static final fun getExamplePatch ()Lapp/morphe/patcher/patch/BytecodePatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class app/morphe/util/PatchListGeneratorKt {
|
||||||
|
public static synthetic fun main ([Ljava/lang/String;)V
|
||||||
|
}
|
||||||
|
|
||||||
@@ -17,3 +17,29 @@ kotlin {
|
|||||||
freeCompilerArgs.add("-Xcontext-parameters")
|
freeCompilerArgs.add("-Xcontext-parameters")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
// Used by JsonGenerator.
|
||||||
|
implementation(libs.gson)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
register<JavaExec>("generatePatchesList") {
|
||||||
|
description = "Build patch with patch list"
|
||||||
|
|
||||||
|
dependsOn(build)
|
||||||
|
|
||||||
|
classpath = sourceSets["main"].runtimeClasspath
|
||||||
|
mainClass.set("app.morphe.util.PatchListGeneratorKt")
|
||||||
|
}
|
||||||
|
// Used by gradle-semantic-release-plugin.
|
||||||
|
publish {
|
||||||
|
dependsOn("generatePatchesList")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
freeCompilerArgs = listOf("-Xcontext-receivers")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 Morphe.
|
||||||
|
* https://github.com/morpheapp/morphe-patches
|
||||||
|
*
|
||||||
|
* File-Specific License Notice (GPLv3 Section 7 Additional Permission).
|
||||||
|
*
|
||||||
|
* This file is part of the Morphe patches project and is licensed under
|
||||||
|
* the GNU General Public License version 3 (GPLv3), with the Additional
|
||||||
|
* Terms under Section 7 described in the Morphe patches LICENSE file.
|
||||||
|
*
|
||||||
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
*
|
||||||
|
* File-Specific Exception to Section 7b:
|
||||||
|
* -------------------------------------
|
||||||
|
* Section 7b (Attribution Requirement) of the Morphe patches LICENSE
|
||||||
|
* does not apply to THIS FILE. Use of this file does NOT require any
|
||||||
|
* user-facing, in-application, or UI-visible attribution.
|
||||||
|
*
|
||||||
|
* For this file only, attribution under Section 7b is satisfied by
|
||||||
|
* retaining this comment block in the source code of this file.
|
||||||
|
*
|
||||||
|
* Distribution and Derivative Works:
|
||||||
|
* ----------------------------------
|
||||||
|
* This comment block MUST be preserved in all copies, distributions,
|
||||||
|
* and derivative works of this file, whether in source or modified
|
||||||
|
* form.
|
||||||
|
*
|
||||||
|
* All other terms of the Morphe Patches LICENSE, including Section 7c
|
||||||
|
* (Project Name Restriction) and the GPLv3 itself, remain fully
|
||||||
|
* applicable to this file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package app.morphe.util
|
||||||
|
|
||||||
|
import app.morphe.patcher.patch.Patch
|
||||||
|
import app.morphe.patcher.patch.loadPatchesFromJar
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import com.google.gson.JsonObject
|
||||||
|
import java.io.File
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
import java.util.jar.Manifest
|
||||||
|
|
||||||
|
typealias PackageName = String
|
||||||
|
typealias VersionName = String
|
||||||
|
|
||||||
|
internal fun main() {
|
||||||
|
val patchFiles = setOf(
|
||||||
|
File("build/libs/").listFiles { file ->
|
||||||
|
val fileName = file.name
|
||||||
|
!fileName.contains("javadoc") &&
|
||||||
|
!fileName.contains("sources") &&
|
||||||
|
fileName.endsWith(".mpp")
|
||||||
|
}!!.first()
|
||||||
|
)
|
||||||
|
val loadedPatches = loadPatchesFromJar(patchFiles)
|
||||||
|
val patchClassLoader = URLClassLoader(patchFiles.map { it.toURI().toURL() }.toTypedArray())
|
||||||
|
val manifest = patchClassLoader.getResources("META-INF/MANIFEST.MF")
|
||||||
|
|
||||||
|
while (manifest.hasMoreElements()) {
|
||||||
|
Manifest(manifest.nextElement().openStream())
|
||||||
|
.mainAttributes
|
||||||
|
.getValue("Version")
|
||||||
|
?.let {
|
||||||
|
generatePatchList(it, loadedPatches)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
private fun generatePatchList(version: String, patches: Set<Patch<*>>) {
|
||||||
|
val listJson = File("../patches-list.json")
|
||||||
|
|
||||||
|
val patchesMap = patches.sortedBy { it.name }.map {
|
||||||
|
JsonPatch(
|
||||||
|
it.name!!,
|
||||||
|
it.description,
|
||||||
|
it.use,
|
||||||
|
it.dependencies.map { dependency -> dependency.javaClass.simpleName },
|
||||||
|
it.compatiblePackages?.associate { (packageName, versions) -> packageName to versions },
|
||||||
|
it.options.values.map { option ->
|
||||||
|
JsonPatch.Option(
|
||||||
|
option.key,
|
||||||
|
option.title,
|
||||||
|
option.description,
|
||||||
|
option.required,
|
||||||
|
option.type.toString(),
|
||||||
|
option.default,
|
||||||
|
option.values,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val gsonBuilder = GsonBuilder()
|
||||||
|
.serializeNulls()
|
||||||
|
.disableHtmlEscaping()
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create()
|
||||||
|
|
||||||
|
val jsonObject = JsonObject()
|
||||||
|
jsonObject.addProperty("version", "v$version")
|
||||||
|
jsonObject.add("patches", gsonBuilder.toJsonTree(patchesMap))
|
||||||
|
|
||||||
|
listJson.writeText(
|
||||||
|
gsonBuilder.toJson(jsonObject)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
private class JsonPatch(
|
||||||
|
val name: String? = null,
|
||||||
|
val description: String? = null,
|
||||||
|
val use: Boolean = true,
|
||||||
|
val dependencies: List<String>,
|
||||||
|
val compatiblePackages: Map<PackageName, Set<VersionName>?>? = null,
|
||||||
|
val options: List<Option>,
|
||||||
|
) {
|
||||||
|
class Option(
|
||||||
|
val key: String,
|
||||||
|
val title: String?,
|
||||||
|
val description: String?,
|
||||||
|
val required: Boolean,
|
||||||
|
val type: String,
|
||||||
|
val default: Any?,
|
||||||
|
val values: Map<String, Any?>?,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user