1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 01:55:50 +01:00

Build nightly changelog from git

This commit is contained in:
José Rebelo 2023-08-09 19:52:03 +01:00
parent 942e853ca7
commit 7fb34eb262
3 changed files with 54 additions and 0 deletions

View File

@ -14,6 +14,7 @@ tasks.withType(Test) {
systemProperty "logback.configurationFile", System.getProperty("user.dir", null) + "/app/src/main/assets/logback.xml"
systemProperty "GB_LOGFILES_DIR", Files.createTempDirectory("gblog").toString()
}
def getVersionCode = { ->
try {
def stdout = new ByteArrayOutputStream()
@ -27,6 +28,27 @@ def getVersionCode = { ->
}
}
def buildGitChangelog = {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', '--pretty=format:%h %s'
standardOutput = stdout
}
def commitVersionCode = getVersionCode()
def changelogNode = new Node(null, 'changelog')
stdout.toString().trim().eachLine { line ->
def (commitHash, commitMessage) = line.split(" ", 2)
def releaseNode = new Node(changelogNode, 'release', [version: commitHash, versioncode: commitVersionCode--])
def _ = new Node(releaseNode, 'change', [:], commitMessage)
}
def changelogFile = new File("${project.rootDir}/app/build/generated/res/changelog/xml/changelog_git.xml")
changelogFile.getParentFile().mkdirs()
changelogFile.write(groovy.xml.XmlUtil.serialize(changelogNode))
}
def getGitHashShort = { ->
try {
def stdout = new ByteArrayOutputStream()
@ -106,6 +128,12 @@ android {
}
}
sourceSets {
main {
res.srcDirs += "build/generated/res/changelog"
}
}
buildTypes {
release {
minifyEnabled true
@ -170,6 +198,7 @@ android {
applicationVariants.all { variant ->
variant.resValue "string", "applicationId", variant.applicationId
buildGitChangelog()
if (variant.buildType.name == 'nightly' || variant.buildType.name == 'nopebble') {
variant.outputs.all {

View File

@ -1380,6 +1380,10 @@ public class GBApplication extends Application {
return language;
}
public static boolean isNightly() {
return BuildConfig.APPLICATION_ID.contains("nightly");
}
public String getVersion() {
try {
return getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_META_DATA).versionName;

View File

@ -18,20 +18,41 @@ package nodomain.freeyourgadget.gadgetbridge.util;
import android.content.Context;
import android.content.DialogInterface;
import android.util.SparseArray;
import android.webkit.WebView;
import androidx.appcompat.app.AlertDialog;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.cketti.library.changelog.ChangeLog;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
public class GBChangeLog extends ChangeLog {
private static final Logger LOG = LoggerFactory.getLogger(GBChangeLog.class);
public GBChangeLog(Context context, String css) {
super(context, css);
}
@Override
protected SparseArray<ReleaseItem> getMasterChangeLog(boolean full) {
if (GBApplication.isNightly()) {
try {
return readChangeLogFromResource(R.xml.changelog_git, full);
} catch (final Exception e) {
// Just in case the git changelog is broken somehow..
LOG.error("Failed to read git changelog for nightly", e);
}
}
return super.getMasterChangeLog(full);
}
public AlertDialog getMaterialLogDialog() {
return getMaterialDialog(isFirstRunEver());
}