-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
201 lines (181 loc) · 6.93 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
201 lines (181 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
* Software Name: OUDS Android
* SPDX-FileCopyrightText: Copyright (c) Orange SA
* SPDX-License-Identifier: MIT
*
* This software is distributed under the MIT license,
* the text of which is available at https://opensource.org/license/MIT/
* or see the "LICENSE" file for more details.
*
* Software description: Android library of reusable graphical components
*/
import com.google.firebase.appdistribution.gradle.firebaseAppDistributionDefault
import com.orange.ouds.gradle.Environment
import com.orange.ouds.gradle.execute
import com.orange.ouds.gradle.findTypedProperty
import com.orange.ouds.gradle.gitHubGraphQLApi
import com.orange.ouds.gradle.gitHubRestApi
import com.orange.ouds.gradle.updateChangelog
plugins {
id("firebase")
id(libs.plugins.android.application.get().pluginId) // https://github.com/gradle/gradle/issues/20084#issuecomment-1060822638
alias(libs.plugins.ksp)
id(libs.plugins.kotlin.parcelize.get().pluginId)
alias(libs.plugins.compose.compiler)
id(libs.plugins.firebase.appdistribution.get().pluginId)
alias(libs.plugins.firebase.crashlytics)
alias(libs.plugins.google.services)
alias(libs.plugins.hilt)
}
android {
namespace = "com.orange.ouds.app"
compileSdk = libs.versions.androidCompileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.androidMinSdk.get().toInt()
targetSdk = libs.versions.androidTargetSdk.get().toInt()
versionCode = project.findTypedProperty<String>("versionCode")?.toInt() ?: 12
versionName = version.toString()
versionNameSuffix = project.findTypedProperty<String>("versionNameSuffix")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
buildConfig = true
compose = true
}
val (storeFilePath, storePassword, keyAlias, keyPassword) = Environment.getVariablesOrNull(
"SIGNING_STORE_FILE_PATH",
"SIGNING_STORE_PASSWORD",
"SIGNING_KEY_ALIAS",
"SIGNING_KEY_PASSWORD"
)
val storeFile = if (storeFilePath != null) file(storeFilePath).takeIf { it.exists() } else null
val signingConfigName = "signingConfig"
if (storeFile != null && storePassword != null && keyAlias != null && keyPassword != null) {
signingConfigs {
create(signingConfigName) {
this.storeFile = storeFile
this.storePassword = storePassword
this.keyAlias = keyAlias
this.keyPassword = keyPassword
}
}
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
if (storeFile != null) {
signingConfig = this@android.signingConfigs.getByName(signingConfigName)
}
}
}
val versionFlavorDimension = "version"
flavorDimensions.add(versionFlavorDimension)
productFlavors {
create("alpha") {
dimension = versionFlavorDimension
applicationId = "com.orange.ouds.alpha.app"
}
create("beta") {
dimension = versionFlavorDimension
applicationId = "com.orange.ouds.beta.app"
}
create("prod") {
dimension = versionFlavorDimension
applicationId = "com.orange.ouds.app"
}
}
kotlin {
jvmToolchain(17)
compilerOptions {
allWarningsAsErrors = true
// Suppresses an expected warning that triggers a build failure because allWarningsAsErrors is true
// See https://youtrack.jetbrains.com/issue/KT-68400/K2-w-Kapt-currently-doesnt-support-language-version-2.0.-Falling-back-to-1.9.
freeCompilerArgs.add("-Xsuppress-version-warnings")
}
}
androidResources {
generateLocaleConfig = true
}
}
firebaseAppDistributionDefault {
groups = project.findTypedProperty("appDistributionGroup")
}
dependencies {
implementation(project(":core"))
implementation(project(":foundation"))
implementation(project(":theme-orange"))
implementation(project(":theme-orange-compact"))
implementation(project(":theme-sosh"))
implementation(project(":theme-wireframe"))
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.appcompat)
implementation(libs.androidx.browser)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.material.icons.core)
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.datastore.preferences)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.compose)
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.crashlytics)
implementation(libs.haze)
implementation(libs.hilt.android)
ksp(libs.hilt.compiler)
ksp(libs.kotlin.metadata.jvm)
implementation(libs.kotlin.reflect)
}
tasks.register<DefaultTask>("updateAppChangelog") {
doLast {
val rawResourcesPath = "src/main/res/raw"
val changelogFilename = "CHANGELOG.md"
val updateAppChangelog = {
delete("$rawResourcesPath/$changelogFilename")
updateChangelog(null)
copy {
from("../$changelogFilename").into(rawResourcesPath).rename { it.lowercase() }
}
execute("git", "checkout", changelogFilename)
}
// Ignore failure with local builds
val ignoreFailure = Environment.getVariablesOrNull("CI").firstOrNull().toBoolean().not()
if (ignoreFailure) {
try {
updateAppChangelog()
} catch (_: Exception) {
val errorMessage = "There was an error while generating the changelog."
logger.error(errorMessage)
file("$rawResourcesPath/${changelogFilename.lowercase()}").writeText(errorMessage)
}
} else {
updateAppChangelog()
}
}
}
fun updateBuildConfig() {
val gitHubWorkflow = Environment.getVariablesOrNull("GITHUB_WORKFLOW").first()
val issueNumbers = if (gitHubWorkflow == "app-distribution-alpha") {
gitHubRestApi {
val pullRequests = getPullRequests()
pullRequests.firstOrNull { it.branchName == Environment.branchName }
?.let { pullRequest ->
gitHubGraphQLApi {
getPullRequestClosingIssues(pullRequest.number).map { it.number }
}
}
}
} else {
null
}
android.defaultConfig {
buildConfigField("int[]", "ISSUE_NUMBERS", if (issueNumbers != null) "new int[]{${issueNumbers.joinToString(", ")}}" else "null")
}
}
gradle.projectsEvaluated {
tasks["preBuild"].apply {
dependsOn(":checkDocumentation")
//dependsOn(":checkNotice")
dependsOn(tasks["updateAppChangelog"])
}
updateBuildConfig()
}