From b91b2a99721e9543a4ca94c104340bd5791b70ae Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Mon, 21 Oct 2019 11:05:09 +0100 Subject: [PATCH 1/6] feature/HMA-1258-deploy-new-tax-calc - Release script for iOS --- .gitignore | 3 ++- package-ios.sh | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100755 package-ios.sh diff --git a/.gitignore b/.gitignore index 285b4db..177b2e9 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ gen build .gradle /credentials.properties -local.properties \ No newline at end of file +local.properties +.DS_Store \ No newline at end of file diff --git a/package-ios.sh b/package-ios.sh new file mode 100755 index 0000000..97e315c --- /dev/null +++ b/package-ios.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +export GITHUB_TOKEN="20a19f0825e0b0a9d0a5434da932a91988c8783d" +if [ -z "$1" ]; then + echo "ERROR: Please provide a git tag" +else + if echo "$1" | grep -Eq "^\d{0,3}\.\d{1}\.\d{1}$"; then + ./gradlew build + DIRECTORY="Carthage" + ZIP="TaxKalculator.framework.zip" + if [ -d "$DIRECTORY" ]; then + rm -rf $DIRECTORY + fi + if [ -f "$ZIP" ]; then + rm $ZIP + fi + mkdir $DIRECTORY && mkdir $DIRECTORY/Build && mkdir $DIRECTORY/Build/iOS + cp -r build/xcode-frameworks/TaxKalculator* $DIRECTORY/Build/iOS + zip -r TaxKalculator.framework.zip $DIRECTORY + echo "ghr run step" +# ghr $1 $ZIP + else + echo "ERROR: Please use a valid git tag format e.g 1.0.3" + fi +fi \ No newline at end of file From dcb41546e1c4111728c18809806fff1e5b94dbe9 Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Mon, 21 Oct 2019 11:22:28 +0100 Subject: [PATCH 2/6] feature/HMA-1258-deploy-new-tax-calc - Updating script --- package-ios.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/package-ios.sh b/package-ios.sh index 97e315c..7305008 100755 --- a/package-ios.sh +++ b/package-ios.sh @@ -1,10 +1,8 @@ #!/usr/bin/env bash -export GITHUB_TOKEN="20a19f0825e0b0a9d0a5434da932a91988c8783d" if [ -z "$1" ]; then echo "ERROR: Please provide a git tag" else if echo "$1" | grep -Eq "^\d{0,3}\.\d{1}\.\d{1}$"; then - ./gradlew build DIRECTORY="Carthage" ZIP="TaxKalculator.framework.zip" if [ -d "$DIRECTORY" ]; then @@ -13,11 +11,14 @@ else if [ -f "$ZIP" ]; then rm $ZIP fi + echo "INFO: Creating Carthage folder structure" mkdir $DIRECTORY && mkdir $DIRECTORY/Build && mkdir $DIRECTORY/Build/iOS + echo "INFO: Copying artifact" cp -r build/xcode-frameworks/TaxKalculator* $DIRECTORY/Build/iOS + echo "INFO: Zipping" zip -r TaxKalculator.framework.zip $DIRECTORY - echo "ghr run step" -# ghr $1 $ZIP + echo "INFO: Adding zipped artifact to release" + ghr "$1" $ZIP else echo "ERROR: Please use a valid git tag format e.g 1.0.3" fi From 4a4336cdce2ca76098d17e40ae9af974767012b9 Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Tue, 22 Oct 2019 10:12:27 +0100 Subject: [PATCH 3/6] feature/HMA-1258-deploy-new-tax-calc - Updating script with github token --- package-ios.sh | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/package-ios.sh b/package-ios.sh index 7305008..418c68b 100755 --- a/package-ios.sh +++ b/package-ios.sh @@ -1,25 +1,30 @@ #!/usr/bin/env bash -if [ -z "$1" ]; then - echo "ERROR: Please provide a git tag" +if [ -z "$2" ]; then + echo "ERROR: Please provide a Github token" else - if echo "$1" | grep -Eq "^\d{0,3}\.\d{1}\.\d{1}$"; then - DIRECTORY="Carthage" - ZIP="TaxKalculator.framework.zip" - if [ -d "$DIRECTORY" ]; then - rm -rf $DIRECTORY + export export GITHUB_TOKEN=$2 + if [ -z "$1" ]; then + echo "ERROR: Please provide a git tag" + else + if echo "$1" | grep -Eq "^\d{0,3}\.\d{1}\.\d{1}$"; then + DIRECTORY="Carthage" + ZIP="TaxKalculator.framework.zip" + if [ -d "$DIRECTORY" ]; then + rm -rf $DIRECTORY + fi + if [ -f "$ZIP" ]; then + rm $ZIP + fi + echo "INFO: Creating Carthage folder structure" + mkdir $DIRECTORY && mkdir $DIRECTORY/Build && mkdir $DIRECTORY/Build/iOS + echo "INFO: Copying artifact" + cp -r build/xcode-frameworks/TaxKalculator* $DIRECTORY/Build/iOS + echo "INFO: Zipping" + zip -r TaxKalculator.framework.zip $DIRECTORY + echo "INFO: Adding zipped artifact to release" + ghr "$1" $ZIP + else + echo "ERROR: Please use a valid git tag format e.g 1.0.3" fi - if [ -f "$ZIP" ]; then - rm $ZIP - fi - echo "INFO: Creating Carthage folder structure" - mkdir $DIRECTORY && mkdir $DIRECTORY/Build && mkdir $DIRECTORY/Build/iOS - echo "INFO: Copying artifact" - cp -r build/xcode-frameworks/TaxKalculator* $DIRECTORY/Build/iOS - echo "INFO: Zipping" - zip -r TaxKalculator.framework.zip $DIRECTORY - echo "INFO: Adding zipped artifact to release" - ghr "$1" $ZIP - else - echo "ERROR: Please use a valid git tag format e.g 1.0.3" - fi + fi fi \ No newline at end of file From 3517a0405d9849825b52cb41e5987785f23aebf2 Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Wed, 23 Oct 2019 11:21:56 +0100 Subject: [PATCH 4/6] HMA-1258-deploy-new-tax-calc - Adding Throws annottaion --- build.gradle | 8 +++++-- .../uk/gov/hmrc/calculator/Calculator.kt | 2 ++ .../gov/hmrc/calculator/annotations/Throws.kt | 24 +++++++++++++++++++ .../gov/hmrc/calculator/annotations/Throws.kt | 18 ++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/commonMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt create mode 100644 src/iosMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt diff --git a/build.gradle b/build.gradle index 2e1697c..a25cf51 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.jetbrains.kotlin.multiplatform' version '1.3.41' + id 'org.jetbrains.kotlin.multiplatform' version '1.3.50' id 'jacoco' id 'java' id 'com.github.dawnwords.jacoco.badge' version '0.1.0' @@ -62,6 +62,10 @@ version=System.getenv('BITRISE_GIT_TAG') ?: ("SNAPSHOT-" + getDate() ) apply plugin: 'maven-publish' String frameworkName = 'TaxKalculator' +tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { + kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.ExperimentalMultiplatform"] +} + kotlin { targets { final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \ @@ -76,7 +80,7 @@ kotlin { } sourceSets { - def klockVersion = "1.5.0" + def klockVersion = "1.7.5" commonMain { dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib-common' diff --git a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt index a9cf7a6..cdc906a 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt @@ -15,6 +15,7 @@ */ package uk.gov.hmrc.calculator +import uk.gov.hmrc.calculator.annotations.Throws import uk.gov.hmrc.calculator.model.BandBreakdown import uk.gov.hmrc.calculator.model.CalculatorResponse import uk.gov.hmrc.calculator.model.CalculatorResponsePayPeriod @@ -58,6 +59,7 @@ class Calculator( private val bandBreakdown: MutableList = mutableListOf() + @Throws(InvalidWagesException::class) fun run(): CalculatorResponse { if (!isAboveMinimumWages(wages) || !isBelowMaximumWages(wages)) { throw InvalidWagesException("Wages must be between 0 and 9999999.99") diff --git a/src/commonMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt b/src/commonMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt new file mode 100644 index 0000000..d3b8e9f --- /dev/null +++ b/src/commonMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2019 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.gov.hmrc.calculator.annotations + +import kotlin.reflect.KClass + +@UseExperimental(ExperimentalMultiplatform::class) +@OptionalExpectation +@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR) +@Retention(AnnotationRetention.SOURCE) +expect annotation class Throws(vararg val exceptionClasses: KClass) diff --git a/src/iosMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt b/src/iosMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt new file mode 100644 index 0000000..f636b3f --- /dev/null +++ b/src/iosMain/kotlin/uk/gov/hmrc/calculator/annotations/Throws.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2019 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.gov.hmrc.calculator.annotations + +actual typealias Throws = kotlin.native.Throws \ No newline at end of file From 431cc86c432b6a1f6186c3337ab748c10755a699 Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Wed, 23 Oct 2019 12:18:22 +0100 Subject: [PATCH 5/6] HMA-1258-deploy-new-tax-calc - Throws annotation refinement --- build.gradle | 9 +++++---- .../kotlin/uk/gov/hmrc/calculator/Calculator.kt | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index a25cf51..9e669af 100644 --- a/build.gradle +++ b/build.gradle @@ -62,10 +62,6 @@ version=System.getenv('BITRISE_GIT_TAG') ?: ("SNAPSHOT-" + getDate() ) apply plugin: 'maven-publish' String frameworkName = 'TaxKalculator' -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all { - kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlin.ExperimentalMultiplatform"] -} - kotlin { targets { final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \ @@ -80,6 +76,11 @@ kotlin { } sourceSets { + all { + languageSettings { + useExperimentalAnnotation('kotlin.Experimental') + } + } def klockVersion = "1.7.5" commonMain { dependencies { diff --git a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt index cdc906a..f958421 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt @@ -16,6 +16,7 @@ package uk.gov.hmrc.calculator import uk.gov.hmrc.calculator.annotations.Throws +import uk.gov.hmrc.calculator.exception.* import uk.gov.hmrc.calculator.model.BandBreakdown import uk.gov.hmrc.calculator.model.CalculatorResponse import uk.gov.hmrc.calculator.model.CalculatorResponsePayPeriod @@ -38,9 +39,6 @@ import uk.gov.hmrc.calculator.model.taxcodes.MarriageTaxCodes import uk.gov.hmrc.calculator.model.taxcodes.NoTaxTaxCode import uk.gov.hmrc.calculator.model.taxcodes.SingleBandTax import uk.gov.hmrc.calculator.model.taxcodes.StandardTaxCode -import uk.gov.hmrc.calculator.exception.InvalidTaxBandException -import uk.gov.hmrc.calculator.exception.InvalidTaxCodeException -import uk.gov.hmrc.calculator.exception.InvalidWagesException import uk.gov.hmrc.calculator.model.taxcodes.TaxCode import uk.gov.hmrc.calculator.utils.TaxYear import uk.gov.hmrc.calculator.utils.convertAmountFromYearlyToPayPeriod @@ -59,7 +57,9 @@ class Calculator( private val bandBreakdown: MutableList = mutableListOf() - @Throws(InvalidWagesException::class) + @Throws(InvalidTaxCodeException::class, InvalidTaxYearException::class, + InvalidWagesException::class, InvalidPayPeriodException::class, + InvalidHoursException::class, InvalidTaxBandException::class) fun run(): CalculatorResponse { if (!isAboveMinimumWages(wages) || !isBelowMaximumWages(wages)) { throw InvalidWagesException("Wages must be between 0 and 9999999.99") From 5dbc1d0ab881b3a6a30f454fc4dcbbb25922bd9f Mon Sep 17 00:00:00 2001 From: Christopher O'Brien Date: Wed, 23 Oct 2019 13:18:42 +0100 Subject: [PATCH 6/6] HMA-1258-deploy-new-tax-calc - Cleanup for detekt errors --- .../uk/gov/hmrc/calculator/Calculator.kt | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt index f958421..b305377 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/calculator/Calculator.kt @@ -16,7 +16,12 @@ package uk.gov.hmrc.calculator import uk.gov.hmrc.calculator.annotations.Throws -import uk.gov.hmrc.calculator.exception.* +import uk.gov.hmrc.calculator.exception.InvalidTaxCodeException +import uk.gov.hmrc.calculator.exception.InvalidTaxYearException +import uk.gov.hmrc.calculator.exception.InvalidWagesException +import uk.gov.hmrc.calculator.exception.InvalidPayPeriodException +import uk.gov.hmrc.calculator.exception.InvalidHoursException +import uk.gov.hmrc.calculator.exception.InvalidTaxBandException import uk.gov.hmrc.calculator.model.BandBreakdown import uk.gov.hmrc.calculator.model.CalculatorResponse import uk.gov.hmrc.calculator.model.CalculatorResponsePayPeriod @@ -57,9 +62,8 @@ class Calculator( private val bandBreakdown: MutableList = mutableListOf() - @Throws(InvalidTaxCodeException::class, InvalidTaxYearException::class, - InvalidWagesException::class, InvalidPayPeriodException::class, - InvalidHoursException::class, InvalidTaxBandException::class) + @Throws(InvalidTaxCodeException::class, InvalidTaxYearException::class, InvalidWagesException::class, + InvalidPayPeriodException::class, InvalidHoursException::class, InvalidTaxBandException::class) fun run(): CalculatorResponse { if (!isAboveMinimumWages(wages) || !isBelowMaximumWages(wages)) { throw InvalidWagesException("Wages must be between 0 and 9999999.99") @@ -71,13 +75,25 @@ class Calculator( val taxBands = TaxBands(taxCode.country, taxYear).bands - val taxPayable = taxToPay(yearlyWages, taxCode) - val employeesNI = employeeNIToPay(yearlyWages) - val employersNI = employerNIToPay(yearlyWages) - val taxFreeAmount = adjustTaxBands(taxBands, taxCode)[0].upper val amountToAddToWages = if (taxCode is KTaxCode) taxCode.amountToAddToWages else null + return createResponse( + yearlyWages, + taxFreeAmount, + amountToAddToWages + ) + } + + private fun createResponse( + yearlyWages: Double, + taxFreeAmount: Double, + amountToAddToWages: Double? + ): CalculatorResponse { + val taxCode = this.taxCode.toTaxCode() + val taxPayable = taxToPay(yearlyWages, taxCode) + val employeesNI = employeeNIToPay(yearlyWages) + val employersNI = employerNIToPay(yearlyWages) return CalculatorResponse( taxCode = this.taxCode, country = taxCode.country,