Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests workflow for PRs and pushes to main #33

Merged
merged 5 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Checks
on:
pull_request:
push:
branches:
- 'main'
jobs:
tests:
name: 'Tests'
runs-on: ubuntu-latest
steps:
- name: 'Check out the repository'
uses: actions/checkout@v4
- name: 'Set up the JDK'
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
- name: 'Set up the Android SDK'
uses: android-actions/setup-android@v3
- name: 'Run tests'
uses: gradle/gradle-build-action@v2
with:
arguments: test
- name: 'Publish test report'
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
with:
report_paths: '**/build/test-results/**/TEST-*.xml'
15 changes: 10 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import java.nio.file.NoSuchFileException
import org.jetbrains.kotlin.konan.properties.loadProperties

plugins {
Expand All @@ -21,11 +22,15 @@ android {

signingConfigs {
create("release") {
val uploadKeystoreProperties = loadProperties(PROPERTIES_FILE_PATH)
storeFile = file(uploadKeystoreProperties.getProperty(PROPERTIES_KEY_STORE_FILE))
storePassword = uploadKeystoreProperties.getProperty(PROPERTIES_KEY_STORE_PASSWORD)
keyAlias = uploadKeystoreProperties.getProperty(PROPERTIES_KEY_ALIAS)
keyPassword = uploadKeystoreProperties.getProperty(PROPERTIES_KEY_PASSWORD)
try {
val uploadKeystoreProperties = loadProperties(PROPERTIES_FILE_PATH)
storeFile = file(uploadKeystoreProperties.getProperty(PROPERTIES_KEY_STORE_FILE))
storePassword = uploadKeystoreProperties.getProperty(PROPERTIES_KEY_STORE_PASSWORD)
keyAlias = uploadKeystoreProperties.getProperty(PROPERTIES_KEY_ALIAS)
keyPassword = uploadKeystoreProperties.getProperty(PROPERTIES_KEY_PASSWORD)
} catch (_: NoSuchFileException) {
// Builds can't be signed for upload to store unless properties file is loaded
}
}
}
compileSdk = libs.versions.android.sdk.compile.get().toInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.trewartha.positional.data.sun.LibrarySolarTimesRepository
import kotlinx.datetime.LocalDate
import kotlinx.datetime.LocalTime
import kotlinx.datetime.Month
import java.util.TimeZone

private val JAN_1_2000 = LocalDate(2000, Month.JANUARY, 1)
private val MAR_1_2000 = LocalDate(2000, Month.MARCH, 1)
Expand All @@ -16,6 +17,7 @@ private val DEC_1_2000 = LocalDate(2000, Month.DECEMBER, 1)

class LocalSolarTimesRepositorySpec : BehaviorSpec({

lateinit var originalDefaultTimeZone: TimeZone
lateinit var subject: LibrarySolarTimesRepository

val dates = listOf(JAN_1_2000, MAR_1_2000, JUN_1_2000, SEP_1_2000, DEC_1_2000)
Expand All @@ -24,9 +26,15 @@ class LocalSolarTimesRepositorySpec : BehaviorSpec({
val coordinates = Coordinates(46.7867, -92.1005)

beforeTest {
originalDefaultTimeZone = TimeZone.getDefault()
TimeZone.setDefault(TimeZone.getTimeZone("America/Chicago")) // Time zone for Duluth above
subject = LibrarySolarTimesRepository()
}

afterTest {
TimeZone.setDefault(originalDefaultTimeZone)
}

given("a date at a specific location") {
`when`("astronomical dawn is calculated") {
val astronomicalDawns = dates.associateWith { date ->
Expand Down