# S2 Riskwise application

[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![node](https://img.shields.io/badge/node-lts/erbium-informational?style=flat&logo=node.js&logoColor=white)](https://nodejs.org/en/about/releases/)
[![ionic](https://img.shields.io/badge/ionic-4-informational?style=flat&logo=ionic&logoColor=white)](https://nodejs.org/en/about/releases/)


This repo is the S2 Riskwise Ionic applications.

## Purpose

* Port of the the existing native iOS/Android applications to a Hybrid model using [Ionic]

## Architecture

The app is an Ionic application utilising [Capacitor] for creating native projects

## Encryption

* An encryption secret is injected by bitrise at buildtime with RISKWISE_ENCRYPTION_KEY variable. 

### iOS

It's been [said](https://twitter.com/thehappypenguin/status/908700871642554373) that 80% of iOS development is code signing.  It's probably higher.  

That being said, we use [Fastlane] to aid with the code signing and deployment to distribution channels - app center and tesflight/appstore.

Because we're nice, running `bitrise run download_profiles` will install the necessary certificates and profiles to build with.

_nb. You will need to add the bundle ids to the Waracle enterprise account._

## Configuration
Each tool should where possible utilise its own config file
For examples that could be added to [package.json](./package.json), they instead use their own config.  
* .huskyrc
* .nvmrc
* .releaserc
* ...

This makes it easier to move to new tooling, etc, without polluting the package.json file 

## Dependencies
1. Install [nvm] to accurately control the node version to build against.  
Then run `nvm install` or `nvm use` to install the project node version or activate it, respectively.  
The node version is configured in the [.nvmrc](./.nvmrc) file.  Ensure *only* `lts` [versions](https://nodejs.org/en/about/releases/) are used.

1. Install the bitrise [CLI](https://app.bitrise.io/cli) for running and building the applications locally.

1. Install [rbenv] to accurately control the ruby version for building iOS apps with

1. Create a new .env file from .env.template containing required environment variables.

1. [Bitrise] CI requires an `APPCENTER_API_TOKEN` for uploads to app center. One should be created for the new app by logging in to AppCenter as the webmaster@waracle.com user.

1. [Xcode] is required for building the iOS application

1. [Android studio] and a Java [JDK] is required for buildung the Android application 

## Environment variables

To add a new env var, do the following:

1. Add it to .env.template and your .env file
1. Add it to the projectEnvVars array in tools/set-env.js
1. Run `npm run config` to create the environment.ts file

## AppCenter

Test builds of both iOS and Android apps are distributed to app center as follows:

1. When opening a pull request - uploaded to Ionic Skeleton IQA
1. When merged to main - uploaded to Ionic Skeleton UAT

IQA builds should be signed off by testers prior to merge.
UAT builds should be signed off prior to store release.

## Testing

### Unit

Run `npm test` for unit tests

### e2e

Run `npm run e2e` for end-to-end tests

## Running

Run `npm run serve` to start the application in your local browser.  

By default, it'll be available from http://localhost:4200.

## Building

As we're using TypeScript, the source will need transpiled to JavaScript as part of the build process.  To confirm the code is buildable, run `npm run build`.  Upon git push, the build will be tested to ensure it works too.  

See [Deployment](#markdown-header-committing%2Fpushing) for more information.

### Code

To transpile, run `npm run build`

### Apps

Run `bitrise workflows` in your terminal to see a list of available workflows.

By default, running `bitrise run dev` will build the ionic applications for both platforms - iOs and Android - for emulators.  Where running `bitrise run internal_qa` will build actual apps for running on devices.

## Committing/Pushing

We use [semantic release] to automate the versioning of the repo, therefore follow the commit message [guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) 

## Deployment

We utilise CI/CD wherever possible, and for native/non-web applications, [Bitrise] is used as the runner.
  
Committing to the repo will start the `feature` workflow, opening a PR will run `internal_qa`, merging to `main` will run `external_qa` and tagging will run the release workflow.

### Bitrise project creation

The easiest way to set up a new bitrise project is to use the website and follow the [instructions](https://app.bitrise.io/apps/add).  
The main thing to remember is to add the private key from [1password](https://waracle.1password.com/vaults/4l26zj5eo7uikdfs2ikaoo6s6m/allitems/la3faetzx4vpj7u7tclgbyxqcu) for the bitrise bitbucket user, instead of the default readonly one that will be creation during the process.  
The reason is to allow writing back to the repo, for semantic versioning for example.

Once the project is created add the relevant `.bitrise.secrets.yml` properties

### Git Hooks

The repo is equipped with [Husky] git hooks that will run `npm run lint` on each commit, and run `npm run build` and `npm test` on each push.

Appending `--no-verify` to the `git commit` and/or `git push` commands will skip the hooks, but they are there to help development so don't skip to avoid fixing a linter or test problem.  The CI build will fail exposing your shame. 


## Who do I talk to?

* MS Teams Channel -> S2 Software -> Mobile Apps - Stand Up https://teams.microsoft.com/l/channel/19%3a573d3da22daf45958ab04ca2c448e0b8%40thread.skype/Mobile%2520Apps%2520-%2520Stand%2520Up?groupId=382ec643-8724-45d9-a2ea-63eef2429538&tenantId=a8d272c6-b029-403a-8a1b-082d524a1b4d

[android studio]: https://developer.android.com/studio
[bitrise]: https://bitrise.io
[capacitor]: https://capacitorjs.com
[fastlane]: https://fastlane.tools/
[husky]: https://github.com/typicode/husky
[jdk]: https://openjdk.java.net/
[ionic]: https://ionicframework.com/
[nvm]: https://github.com/nvm-sh/nvm/blob/master/README.md
[rbenv]: https://github.com/rbenv/rbenv
[semantic release]: https://semantic-release.gitbook.io
[xcode]: https://developer.apple.com/xcode/
