Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Git Hooks + dev exp improvements (#2536)
Browse files Browse the repository at this point in the history
* Delete some unused code

* Remove "Final Steps" from the PR template

* Prevent duplicate PR runs

* Add detektFormat `pre-push` hook

* Add instructions to setup `.git/hooks`

* Test the pre-push hook

* Hook test #1

* WIP: Fix pre-push hook and detektFormat.sh

* Generate a new baseline.yml

* Fix the `lint` workflow to always upload Lint and Detekt result

* Fix the detekt/baselin.yml AS auto-format breaks it
  • Loading branch information
ILIYANGERMANOV authored Sep 2, 2023
1 parent cc5e51d commit d90bcbf
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 49 deletions.
12 changes: 1 addition & 11 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,4 @@ _💡 Tip: Attach screenshots and screen recordings. It helps a lot!_
Check **[Ivy Wallet Issues](https://github.com/Ivy-Apps/ivy-wallet/issues)**.
- Closes #{ISSUE_NUMBER}

_Replace `{ISSUE_NUMBER}` with the id/number of the issue that you've fixed._

## Final Steps

Test your build again with the **app-demo.apk** generated by the `APK workflow`. This is an important step because it applies code obfuscation and R8 that often produces runtime exceptions which make the app crash.

> We don't have QA, you are the QA! That's why we require so much testing.
If everything still works fines, comment and tag **@ILIYANGERMANOV**. He'll try to merge your PR whenever possible.

**Thank you for your contribution! 🎉**
_Replace `{ISSUE_NUMBER}` with the id/number of the issue that you've fixed._
2 changes: 2 additions & 0 deletions .github/workflows/apk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: APK
on:
# Triggers the workflow on push or pull request events
push:
branches:
- main

pull_request:

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: Lint
on:
# Triggers the workflow on push or pull request events
push:
branches:
- main

pull_request:

Expand Down Expand Up @@ -43,6 +45,7 @@ jobs:
run: ./gradlew detekt

- name: Upload Detekt Release report to GitHub
if: always()
uses: actions/upload-artifact@v3
with:
name: detekt-report.html
Expand All @@ -54,6 +57,7 @@ jobs:
run: ./gradlew lintRelease

- name: Upload Lint Release report to GitHub
if: always()
uses: actions/upload-artifact@v3
with:
name: lint-release-report.html
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: Unit tests
on:
# Triggers the workflow on push or pull request events
push:
branches:
- main

pull_request:

Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ You can do that by cliking this badge: 👉 [![Fork Ivy Wallet](https://img.shie

**[How To Fork Guide by GitHub](https://docs.github.com/en/get-started/quickstart/fork-a-repo)**

After you've cloned your Ivy Wallet fork make sure to initialize the project using **[the initialization instructions in the README](./README.md#initialize-the-project)**.

## 2. Pick an issue

What do you want to work on? How do you want to contribute?
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ Ivy Wallet's biggest advantage is its UI/UX, simplicity, and customization that
- The latest **Android Studio Hedgehog** or above (for easy install
use [JetBrains Toolbox](https://www.jetbrains.com/toolbox-app/))

### Initialize the project

**1. Fork and clone the repo**

**2. Make the initialization script executable:**
```
chmod +x scripts/init.sh
```

**3. Run the initialization script:**
```
./scripts/init.sh
```

## Learning Materials

Ivy Wallet is a great place to code and learn. That's why we're also linking great learning materials (books, articles, videos), check them in **[docs/resources 📚](docs/resources/)**.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ class SettingsViewModel @Inject constructor(
viewModelScope.launch {
TestIdlingResource.increment()

val settings = ioThread { settingsDao.findFirst() }
val settings = ioThread {
settingsDao.findFirst()
}

_nameLocalAccount.value = settings.name

Expand Down
9 changes: 0 additions & 9 deletions app/src/main/java/com/ivy/wallet/ui/test/TestScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,12 @@ fun BoxWithConstraintsScope.TestScreen(screen: Test) {

UI(
user = user,

onSyncCategories = viewModel::syncCategories,
onTestWorker = viewModel::testWorker,
)
}

@Composable
private fun BoxWithConstraintsScope.UI(
user: User?,

onSyncCategories: () -> Unit,
onTestWorker: () -> Unit,
) {
var chooseIconModalVisible by remember {
mutableStateOf(false)
Expand Down Expand Up @@ -88,9 +82,6 @@ private fun Preview() {
IvyWalletPreview {
UI(
user = null,

onSyncCategories = {},
onTestWorker = {}
)
}
}
22 changes: 0 additions & 22 deletions app/src/main/java/com/ivy/wallet/ui/test/TestViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ivy.frp.test.TestIdlingResource
import com.ivy.wallet.backup.github.GitHubClient
import com.ivy.wallet.domain.data.core.User
import com.ivy.wallet.domain.deprecated.logic.notification.TransactionReminderLogic
import com.ivy.wallet.domain.deprecated.sync.item.CategorySync
import com.ivy.wallet.io.network.IvySession
import com.ivy.wallet.io.persistence.dao.UserDao
import com.ivy.wallet.utils.asLiveData
Expand All @@ -18,11 +15,8 @@ import javax.inject.Inject

@HiltViewModel
class TestViewModel @Inject constructor(
private val categorySync: CategorySync,
private val userDao: UserDao,
private val ivySession: IvySession,
private val transactionReminderLogic: TransactionReminderLogic,
private val gitHubClient: GitHubClient,
) : ViewModel() {

private val _user = MutableLiveData<User?>()
Expand All @@ -40,20 +34,4 @@ class TestViewModel @Inject constructor(
TestIdlingResource.decrement()
}
}

fun syncCategories() {
viewModelScope.launch {
TestIdlingResource.increment()

ioThread {
categorySync.sync()
}

TestIdlingResource.decrement()
}
}

fun testWorker() {
transactionReminderLogic.testNow()
}
}
8 changes: 7 additions & 1 deletion buildSrc/src/main/kotlin/ivy.lint.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ plugins {
}

configure<DetektExtension> {
source.setFrom(projectDir)
val filesToCheck: String? = System.getProperty("detekt.filesToCheck")
if (!filesToCheck.isNullOrEmpty()) {
source.setFrom(filesToCheck.split(","))
} else {
source.setFrom(projectDir)
}
config.setFrom("$rootDir/config/detekt/config.yml")
baseline = file("$rootDir/config/detekt/baseline.yml")
}


tasks.register<Detekt>("detektFormat") {
autoCorrect = true
}
Expand Down
8 changes: 3 additions & 5 deletions config/detekt/baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4355,6 +4355,7 @@
<ID>NoConsecutiveBlankLines:WrapContentRow.kt$ </ID>
<ID>NoConsecutiveBlankLines:build.gradle.kts$ </ID>
<ID>NoConsecutiveBlankLines:dependencies.kt$ </ID>
<ID>NoConsecutiveBlankLines:ivy.lint.gradle.kts$ </ID>
<ID>NoEmptyClassBody:AccountsUpdatedEvent.kt$AccountsUpdatedEvent${ }</ID>
<ID>NoEmptyFirstLineInMethodBlock:AccountCharts.kt$ </ID>
<ID>NoEmptyFirstLineInMethodBlock:AccountModal.kt$ </ID>
Expand Down Expand Up @@ -4625,7 +4626,7 @@
<ID>PackageName:MoreMenu.kt$package com.ivy.design.l4_patterns</ID>
<ID>PackageName:Onboarding.kt$package com.ivy.design.l5_concept</ID>
<ID>PackageName:PieChart.kt$package com.ivy.design.l3_ivyComponents.chart</ID>
<ID>PackageName:PluginSpecBuilders.kt$package gradle.kotlin.dsl.plugins._cbc4edcb0c3d88134f29766b2a7d4f41</ID>
<ID>PackageName:PluginSpecBuilders.kt$package gradle.kotlin.dsl.plugins._fe0b42ce1102c239397a785329863d5f</ID>
<ID>PackageName:ProgressBar.kt$package com.ivy.design.l3_ivyComponents.percentage</ID>
<ID>PackageName:ReorderModal.kt$package com.ivy.design.l4_patterns</ID>
<ID>PackageName:ScreenTitle.kt$package com.ivy.design.l3_ivyComponents</ID>
Expand Down Expand Up @@ -4692,7 +4693,7 @@
<ID>PackageNaming:MoreMenu.kt$package com.ivy.design.l4_patterns</ID>
<ID>PackageNaming:Onboarding.kt$package com.ivy.design.l5_concept</ID>
<ID>PackageNaming:PieChart.kt$package com.ivy.design.l3_ivyComponents.chart</ID>
<ID>PackageNaming:PluginSpecBuilders.kt$package gradle.kotlin.dsl.plugins._cbc4edcb0c3d88134f29766b2a7d4f41</ID>
<ID>PackageNaming:PluginSpecBuilders.kt$package gradle.kotlin.dsl.plugins._fe0b42ce1102c239397a785329863d5f</ID>
<ID>PackageNaming:ProgressBar.kt$package com.ivy.design.l3_ivyComponents.percentage</ID>
<ID>PackageNaming:ReorderModal.kt$package com.ivy.design.l4_patterns</ID>
<ID>PackageNaming:ScreenTitle.kt$package com.ivy.design.l3_ivyComponents</ID>
Expand Down Expand Up @@ -5224,8 +5225,6 @@
<ID>UnusedParameter:SettingsScreen.kt$onLogin: () -&gt; Unit</ID>
<ID>UnusedParameter:SettingsScreen.kt$screen: Settings</ID>
<ID>UnusedParameter:Shapes.kt$modifier: Modifier = Modifier</ID>
<ID>UnusedParameter:TestScreen.kt$onSyncCategories: () -&gt; Unit</ID>
<ID>UnusedParameter:TestScreen.kt$onTestWorker: () -&gt; Unit</ID>
<ID>UnusedParameter:TestScreen.kt$screen: Test</ID>
<ID>UnusedParameter:Title.kt$initialTransactionId: UUID?</ID>
<ID>UnusedParameter:WalletCharts.kt$baseCurrencyCode: String</ID>
Expand Down Expand Up @@ -5430,7 +5429,6 @@
<ID>UnusedPrivateProperty:SearchScreen.kt$val ivyContext = ivyWalletCtx()</ID>
<ID>UnusedPrivateProperty:SearchScreen.kt$val nav = navigation()</ID>
<ID>UnusedPrivateProperty:SettingsViewModel.kt$SettingsViewModel$private val exchangeRatesLogic: ExchangeRatesLogic</ID>
<ID>UnusedPrivateProperty:TestViewModel.kt$TestViewModel$private val gitHubClient: GitHubClient</ID>
<ID>UnusedPrivateProperty:TransactionReminderLogic.kt$TransactionReminderLogic.Companion$private const val UNIQUE_WORK_NAME_V1 = "transaction_reminder_work"</ID>
<ID>UnusedPrivateProperty:TransactionViewModel.kt$TransactionViewModel$private val saveTrnLocallyAct: SaveTrnLocallyAct</ID>
<ID>UnusedPrivateProperty:UploadTrnToServerAct.kt$UploadTrnToServerAct$private val dao: TransactionDao</ID>
Expand Down
8 changes: 8 additions & 0 deletions git/hooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

./gradlew detektFormat

if [ $? -ne 0 ]; then
echo "Detekt found issues. Aborting push."
exit 1
fi
12 changes: 12 additions & 0 deletions scripts/detektFormat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Fetch changed and untracked Kotlin files
CHANGED_FILES=$(git diff --name-only HEAD | grep '\.kt[s]*$' | tr '\n' ',')

if [ -z "$CHANGED_FILES" ]; then
echo "No Kotlin files have changed."
exit 0
fi

# Run detektFormat only on those files
./gradlew detektFormat -Ddetekt.filesToCheck=$CHANGED_FILES
27 changes: 27 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# scripts/init.sh

# Define directories
HOOKS_DIR="git/hooks"
GIT_HOOKS_DIR=".git/hooks"
BASE_DIR="$(pwd)"

# Check if the .git directory exists
if [ ! -d "$GIT_HOOKS_DIR" ]; then
echo "Error: This script should be run from the root of the git repository."
exit 1
fi

# Set up symbolic link for pre-push hook
ln -s -f $BASE_DIR/$HOOKS_DIR/pre-push $GIT_HOOKS_DIR/pre-push
echo "pre-push hook has been set up."

# Ensure the pre-push hook is executable
chmod +x $GIT_HOOKS_DIR/pre-push
echo "pre-push hook is now executable."

chmod +x /script/detektFormat.sh
echo "scripts in '/scripts' are now executable."

echo "Repository setup complete!"

0 comments on commit d90bcbf

Please sign in to comment.