Adding local pre-tag changelog generation. (#688)

- Adds a ./generate_changelog.sh script, using git-cliff.
- Removes unecessary internet permission.
- Fixes #683
This commit is contained in:
Dessalines 2024-02-07 20:41:09 -05:00 committed by GitHub
parent d84d28ce14
commit 902b25cf5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 99 additions and 29 deletions

1
.gitignore vendored
View File

@ -12,6 +12,7 @@
local.properties
app/release
app/schemas
app/src/main/assets
.project
.settings
.classpath

View File

@ -71,7 +71,6 @@ android {
dependencies {
implementation "com.github.jeziellago:compose-markdown:0.3.5"
implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.12"
implementation 'androidx.navigation:navigation-compose:2.7.6'
implementation 'com.github.alorma:compose-settings-ui-m3:1.0.3'

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".ThumbkeyApplication"
android:allowBackup="true"

View File

@ -25,11 +25,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
const val DEFAULT_KEY_SIZE = 64
const val DEFAULT_ANIMATION_SPEED = 250
@ -360,28 +356,11 @@ class AppSettingsRepository(private val appSettingsDao: AppSettingsDao) {
}
@WorkerThread
suspend fun updateChangelog() {
suspend fun updateChangelog(ctx: Context) {
withContext(Dispatchers.IO) {
try {
val httpClient: OkHttpClient =
OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addNetworkInterceptor { chain ->
chain.request().newBuilder()
.header("User-Agent", "Thumb-Key")
.build()
.let(chain::proceed)
}
.build()
Log.d("thumb-key", "Fetching RELEASES.md ...")
// Fetch the markdown text
val releasesUrl =
"https://raw.githubusercontent.com/dessalines/thumb-key/main/RELEASES.md".toHttpUrl()
val req = Request.Builder().url(releasesUrl).build()
val res = httpClient.newCall(req).execute()
_changelog.value = res.body.string()
val releasesStr = ctx.assets.open("RELEASES.md").bufferedReader().use { it.readText() }
_changelog.value = releasesStr
} catch (e: Exception) {
Log.e("thumb-key", "Failed to load changelog: $e")
}
@ -607,9 +586,9 @@ class AppSettingsViewModel(private val repository: AppSettingsRepository) : View
repository.updateLastVersionCodeViewed(versionCode)
}
fun updateChangelog() =
fun updateChangelog(ctx: Context) =
viewModelScope.launch {
repository.updateChangelog()
repository.updateChangelog(ctx)
}
}

View File

@ -43,6 +43,8 @@ val DONATION_MARKDOWN =
- [Support on Liberapay](https://liberapay.com/dessalines).
- [Support on Patreon](https://www.patreon.com/dessalines).
---
""".trimIndent()
@OptIn(ExperimentalComposeUiApi::class)
@ -62,7 +64,7 @@ fun ShowChangelog(appSettingsViewModel: AppSettingsViewModel) {
val scrollState = rememberScrollState()
val markdown by appSettingsViewModel.changelog.collectAsState()
LaunchedEffect(appSettingsViewModel) {
appSettingsViewModel.updateChangelog()
appSettingsViewModel.updateChangelog(ctx)
}
AlertDialog(

77
cliff.toml Normal file
View File

@ -0,0 +1,77 @@
# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration
[remote.github]
owner = "dessalines"
repo = "thumb-key"
# token = ""
[changelog]
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
# Thumb-Key {{ version }} ({{ timestamp | date(format="%Y-%m-%d") }})
## What's Changed
{% for commit in commits %}
{% if commit.github.pr_title -%}
{%- set commit_message = commit.github.pr_title -%}
{%- else -%}
{%- set commit_message = commit.message -%}
{%- endif -%}
* {{ commit_message | split(pat="\n") | first | trim }}\
{% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%}
{% if commit.github.pr_number %} in #{{ commit.github.pr_number }}{%- endif %}
{%- endfor -%}
{% if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
{% raw %}\n{% endraw -%}
## New Contributors
{%- endif %}\
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
* @{{ contributor.username }} made their first contribution in #{{ contributor.pr_number }}
{%- endfor -%}
{% if version %}
{% if previous.version %}
**Full Changelog**: https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}/compare/{{ previous.version }}...{{ version }}
{% endif %}
{% else -%}
{% raw %}\n{% endraw %}
{% endif %}
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# postprocessors
postprocessors = []
[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = false
# filter out the commits that are not conventional
filter_unconventional = true
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
# remove issue numbers from commits
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# regex for matching git tags
tag_pattern = "v[0-9].*"
# regex for skipping tags
skip_tags = "beta|alpha"
# regex for ignoring tags
ignore_tags = "rc"
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "newest"

13
generate_changelog.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/sh
set -e
# Creating the new tag
new_tag="$1"
last_tag=$(git describe --tags --abbrev=0)
# Writing to the Releases.md asset that's loaded inside the app
git cliff "$last_tag"..HEAD --tag "$new_tag" --output app/src/main/assets/RELEASES.md
# Prepending to the RELEASES.md
git cliff "$last_tag"..HEAD --tag "$new_tag" --prepend RELEASES.md
prettier -w RELEASES.md