Skip to content

Commit 029d254

Browse files
committed
New CI
1 parent 872ae2b commit 029d254

File tree

11 files changed

+235
-84
lines changed

11 files changed

+235
-84
lines changed

.github/workflows/android.yml

-54
This file was deleted.

.github/workflows/preview.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build and Release Preview
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
env:
8+
MAVEN_OPTS: >-
9+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: set up JDK 18
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: "18"
21+
distribution: "temurin"
22+
# cache: gradle
23+
24+
- uses: gradle/gradle-build-action@v2
25+
with:
26+
gradle-version: 7.5
27+
28+
- name: Decode Keystore
29+
id: decode_keystore
30+
uses: timheuer/[email protected]
31+
with:
32+
fileDir: "./secrets"
33+
fileName: "my.keystore"
34+
encodedString: ${{ secrets.KEYSTORE_FILE }}
35+
36+
- name: Execute Gradle build
37+
run: |
38+
./gradlew \
39+
-PDEBUG_STORE_FILE="../${{ steps.decode_keystore.outputs.filePath }}" \
40+
-PDEBUG_STORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }} \
41+
-PDEBUG_KEY_ALIAS=${{ secrets.KEY_ALIAS }} \
42+
-PDEBUG_KEY_PASSWORD=${{ secrets.KEY_PASSWORD }} \
43+
assembleDebug
44+
45+
# - name: Cache Gradle packages
46+
# uses: actions/cache@v1
47+
# with:
48+
# path: ~/.gradle/caches
49+
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
50+
# restore-keys: ${{ runner.os }}-gradle
51+
52+
- run: mv ${{ github.workspace }}/app/build/outputs/apk/debug/app-debug.apk ${{ github.workspace }}/app/build/outputs/apk/debug/notable-next.apk
53+
54+
- name: Release
55+
uses: softprops/action-gh-release@v1
56+
with:
57+
files: ${{ github.workspace }}/app/build/outputs/apk/debug/notable-next.apk
58+
tag_name: next
59+
name: next
60+
prerelease: true
61+
draft: true
62+
body: "Preview version corresponding to the latest build on main"
63+
token: ${{ secrets.TOKEN }}

.github/workflows/release.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build and Release Version
2+
3+
on:
4+
push:
5+
branches: ["release"]
6+
7+
env:
8+
MAVEN_OPTS: >-
9+
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: set up JDK 18
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: "18"
21+
distribution: "temurin"
22+
# cache: gradle
23+
24+
- uses: gradle/gradle-build-action@v2
25+
with:
26+
gradle-version: 7.5
27+
28+
- name: Decode Keystore
29+
id: decode_keystore
30+
uses: timheuer/[email protected]
31+
with:
32+
fileDir: "./secrets"
33+
fileName: "my.keystore"
34+
encodedString: ${{ secrets.KEYSTORE_FILE }}
35+
36+
- name: Execute Gradle build
37+
run: |
38+
./gradlew \
39+
-PDEBUG_STORE_FILE="../${{ steps.decode_keystore.outputs.filePath }}" \
40+
-PDEBUG_STORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }} \
41+
-PDEBUG_KEY_ALIAS=${{ secrets.KEY_ALIAS }} \
42+
-PDEBUG_KEY_PASSWORD=${{ secrets.KEY_PASSWORD }} \
43+
assembleDebug
44+
45+
# - name: Cache Gradle packages
46+
# uses: actions/cache@v1
47+
# with:
48+
# path: ~/.gradle/caches
49+
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
50+
# restore-keys: ${{ runner.os }}-gradle
51+
52+
- name: Retrieve Version
53+
run: |
54+
echo "::set-output name=VERSION_NAME::$(${{github.workspace}}/gradlew \
55+
-PDEBUG_STORE_FILE="../${{ steps.decode_keystore.outputs.filePath }}" \
56+
-PDEBUG_STORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }} \
57+
-PDEBUG_KEY_ALIAS=${{ secrets.KEY_ALIAS }} \
58+
-PDEBUG_KEY_PASSWORD=${{ secrets.KEY_PASSWORD }} \
59+
-q printVersionName)"
60+
id: android_version
61+
62+
- name: Get version
63+
run: |
64+
echo "version_name=${{steps.android_version.outputs.VERSION_NAME}}" >> $GITHUB_ENV
65+
66+
- run: mv ${{ github.workspace }}/app/build/outputs/apk/debug/app-debug.apk ${{ github.workspace }}/app/build/outputs/apk/debug/notable-${{ env.version_name }}.apk
67+
68+
- name: Release
69+
uses: softprops/action-gh-release@v1
70+
with:
71+
files: ${{ github.workspace }}/app/build/outputs/apk/debug/notable-${{ env.version_name }}.apk
72+
tag_name: v${{env.version_name}}
73+
token: ${{ secrets.TOKEN }}

app/build.gradle

+20
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ android {
1414
applicationId "com.olup.notable"
1515
minSdk 29
1616
targetSdk 33
17+
1718
versionCode 9
1819
versionName "0.0.9"
1920

@@ -26,7 +27,26 @@ android {
2627
}
2728
}
2829

30+
signingConfigs {
31+
debug {
32+
storeFile file(DEBUG_STORE_FILE)
33+
storePassword DEBUG_STORE_PASSWORD
34+
keyAlias DEBUG_KEY_ALIAS
35+
keyPassword DEBUG_KEY_PASSWORD
36+
37+
// Optional, specify signing versions used
38+
v1SigningEnabled true
39+
v2SigningEnabled true
40+
}
41+
}
42+
43+
2944
buildTypes {
45+
debug {
46+
minifyEnabled false
47+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
48+
signingConfig signingConfigs.debug
49+
}
3050
release {
3151
minifyEnabled false
3252
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

app/gradle.properties

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DEBUG_STORE_FILE=/Users/louptopalian/.android/debug.keystore
2+
DEBUG_STORE_PASSWORD=android
3+
DEBUG_KEY_ALIAS=androiddebugkey
4+
DEBUG_KEY_PASSWORD=android

app/release/app-release.apk

22.5 MB
Binary file not shown.

app/release/output-metadata.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": 3,
3+
"artifactType": {
4+
"type": "APK",
5+
"kind": "Directory"
6+
},
7+
"applicationId": "com.olup.notable",
8+
"variantName": "release",
9+
"elements": [
10+
{
11+
"type": "SINGLE",
12+
"filters": [],
13+
"attributes": [],
14+
"versionCode": 1,
15+
"versionName": "1.0",
16+
"outputFile": "app-release.apk"
17+
}
18+
],
19+
"elementType": "File"
20+
}

app/src/main/java/com/olup/notable/modals/AppSettings.kt

+39-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.olup.notable
22

3+
import android.content.Intent
4+
import android.net.Uri
35
import androidx.compose.foundation.background
46
import androidx.compose.foundation.border
57
import androidx.compose.foundation.layout.*
@@ -16,39 +18,51 @@ import androidx.compose.ui.text.font.FontStyle
1618
import androidx.compose.ui.text.style.TextDecoration
1719
import androidx.compose.ui.unit.dp
1820
import androidx.compose.ui.window.Dialog
21+
import androidx.compose.ui.window.DialogProperties
1922
import com.olup.notable.components.SelectMenu
2023
import com.olup.notable.db.Kv
2124
import com.olup.notable.db.KvProxy
2225
import kotlinx.coroutines.launch
2326
import kotlinx.serialization.decodeFromString
2427
import kotlinx.serialization.encodeToString
2528
import kotlinx.serialization.json.Json
29+
import kotlin.concurrent.thread
2630

2731
@kotlinx.serialization.Serializable
28-
data class AppSettings (
32+
data class AppSettings(
2933
val version: Int,
30-
val defaultNativeTemplate : String = "blank",
31-
val quickNavPages : List<String> = listOf()
34+
val defaultNativeTemplate: String = "blank",
35+
val quickNavPages: List<String> = listOf()
3236
)
3337

3438

3539
@Composable
3640
fun AppSettingsModal(onClose: () -> Unit) {
3741
val context = LocalContext.current
3842
val kv = KvProxy(context)
39-
val isLatestVersion = remember {
40-
isLatestVersion(context)
43+
44+
var isLatestVersion by remember {
45+
mutableStateOf(true)
4146
}
42-
val settings by kv.observeKv("APP_SETTINGS", AppSettings.serializer(), AppSettings(version = 1)).observeAsState()
43-
val uriHandler = LocalUriHandler.current
47+
LaunchedEffect(key1 = Unit, block = {
48+
thread {
49+
isLatestVersion = isLatestVersion(context)
50+
}
51+
})
52+
53+
val settings by kv.observeKv("APP_SETTINGS", AppSettings.serializer(), AppSettings(version = 1))
54+
.observeAsState()
4455

56+
if (settings == null) return
4557

46-
if(settings == null) return
4758
Dialog(
48-
onDismissRequest = { onClose() }
49-
) {
59+
onDismissRequest = { onClose() },
60+
properties = DialogProperties(usePlatformDefaultWidth = false),
61+
62+
) {
5063
Column(
5164
modifier = Modifier
65+
.padding(40.dp)
5266
.background(Color.White)
5367
.fillMaxWidth()
5468
.border(2.dp, Color.Black, RectangleShape)
@@ -81,7 +95,11 @@ fun AppSettingsModal(onClose: () -> Unit) {
8195
"squared" to "Small squares grid"
8296
),
8397
onChange = {
84-
kv.setKv("APP_SETTINGS", settings!!.copy(defaultNativeTemplate = it), AppSettings.serializer())
98+
kv.setKv(
99+
"APP_SETTINGS",
100+
settings!!.copy(defaultNativeTemplate = it),
101+
AppSettings.serializer()
102+
)
85103
},
86104
value = settings?.defaultNativeTemplate ?: "blank"
87105
)
@@ -92,9 +110,16 @@ fun AppSettingsModal(onClose: () -> Unit) {
92110
//if(!isLatestVersion){
93111
Text(text = "It seems a new version of ypu app is available on github.", fontStyle = FontStyle.Italic)
94112
Spacer(Modifier.height(10.dp))
95-
Text(text = "See release in browser", textDecoration = TextDecoration.Underline, modifier=Modifier.noRippleClickable {
96-
uriHandler.openUri("https://github.com/olup/notable-public/releases")
97-
})
113+
Text(
114+
text = "See release in browser",
115+
textDecoration = TextDecoration.Underline,
116+
modifier = Modifier.noRippleClickable {
117+
val urlIntent = Intent(
118+
Intent.ACTION_VIEW,
119+
Uri.parse("https://github.com/olup/notable-public/releases")
120+
)
121+
context.startActivity(urlIntent)
122+
})
98123
Spacer(Modifier.height(10.dp))
99124
//}
100125
}

app/src/main/java/com/olup/notable/utils/versionChecker.kt

+5-13
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@ import java.io.BufferedReader
55
import java.io.InputStreamReader
66
import android.content.Context
77
import android.content.pm.PackageManager
8+
import kotlinx.coroutines.CoroutineScope
89

910
fun getLatestReleaseVersion(repoOwner: String, repoName: String): String? {
1011
val apiUrl = "https://api.github.com/repos/$repoOwner/$repoName/releases/latest"
11-
val url = URL(apiUrl)
12-
val connection = url.openConnection()
13-
connection.setRequestProperty("User-Agent", "Mozilla/5.0")
14-
val reader = BufferedReader(InputStreamReader(connection.getInputStream()))
15-
val json = StringBuilder()
16-
var line: String?
17-
while (reader.readLine().also { line = it } != null) {
18-
json.append(line)
19-
}
20-
reader.close()
12+
val json = URL(apiUrl).readText()
2113

2214
// Parse the JSON response and extract the tag name
23-
val version = json.toString()
15+
val version = json
2416
.split("\"tag_name\":")[1]
2517
.split(",")[0]
2618
.replace("\"", "")
@@ -48,8 +40,8 @@ fun getCurrentVersionName(context: Context): String? {
4840

4941
// cache
5042
var isLatestVersion : Boolean? = null
51-
fun isLatestVersion(context: Context) : Boolean{
52-
if(isLatestVersion!=null) return isLatestVersion!!
43+
fun isLatestVersion(context: Context, force : Boolean = false) : Boolean{
44+
if(!force && isLatestVersion!=null) return isLatestVersion!!
5345

5446
try {
5547
val version = getCurrentVersionName(context)

0 commit comments

Comments
 (0)