-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'integration' into main: v3.2.0
- Loading branch information
Showing
1,493 changed files
with
107,694 additions
and
97,174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: 'Automated Tests' | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- integration | ||
|
||
jobs: | ||
automated_tests: | ||
runs-on: ubuntu-20.04 | ||
container: node:16.13.2 | ||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_DB: 'test_farm' | ||
POSTGRES_USER: 'postgres' | ||
POSTGRES_PASSWORD: 'pipeline' | ||
POSTGRES_HOST: postgres | ||
POSTGRES_PORT: 5432 | ||
ports: | ||
- "5432:5432" | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 5s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
env: | ||
JWT_INVITE_SECRET: ${{secrets.JWT_INVITE_SECRET}} | ||
JWT_RESET_SECRET: ${{secrets.JWT_RESET_SECRET}} | ||
JWT_SCHEDULER_SECRET: ${{secrets.JWT_SCHEDULER_SECRET}} | ||
JWT_SECRET: ${{secrets.JWT_SECRET}} | ||
TEST_USER: ${{secrets.TEST_USER}} | ||
TEST_USER_ID: ${{secrets.TEST_USER_ID}} | ||
steps: | ||
# Checkout the current code in the repository | ||
- name: Check out repository code | ||
uses: actions/checkout@v3 | ||
# Install all the dependencies | ||
- name: Install dependencies | ||
run: cd packages/api && npm ci | ||
# Run migrations on the database | ||
- name: Setup database | ||
run: cd packages/api && npm run migrate:pipeline:db | ||
# Run all the CI tests | ||
- name: Run tests | ||
run: cd packages/api && npm run test-ci | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,29 @@ name: 'Chromatic' | |
|
||
on: | ||
push: | ||
branches: [ develop ] | ||
branches: [ integration ] | ||
|
||
jobs: | ||
chromatic-deployment: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: packages/webapp | ||
strategy: | ||
matrix: | ||
node-version: [ 16 ] | ||
steps: | ||
- uses: actions/checkout@v1 | ||
with: | ||
fetch-depth: 0 | ||
- uses: pnpm/[email protected] | ||
with: | ||
version: 6.26.1 | ||
- name: Install dependencies | ||
run: npm install | ||
run: pnpm install | ||
|
||
- name: Publish to Chromatic | ||
env: | ||
NODE_OPTIONS: "--max-old-space-size=8192" | ||
run: ./node_modules/.bin/chromatic --project-token ${{ secrets.CHROMATIC_PROJECT_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# For most projects, this workflow file will not need changing; you simply need | ||
# to commit it to your repository. | ||
# | ||
# You may wish to alter this file to override the set of languages analyzed, | ||
# or to provide custom queries or build logic. | ||
# | ||
# ******** NOTE ******** | ||
# We have attempted to detect the languages in your repository. Please check | ||
# the `language` matrix defined below to confirm you have the correct set of | ||
# supported CodeQL languages. | ||
# | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ integration, main ] | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ integration ] | ||
schedule: | ||
- cron: '44 15 * * 1' | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ 'javascript' ] | ||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] | ||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
|
||
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs | ||
# queries: security-extended,security-and-quality | ||
|
||
|
||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). | ||
# If this step fails, then you should remove it and run the build manually (see below) | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun | ||
|
||
# If the Autobuild fails above, remove it and uncomment the following three lines. | ||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. | ||
|
||
# - run: | | ||
# echo "Run, Build Application using script" | ||
# ./location_of_script_within_repo/buildscript.sh | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,42 +10,27 @@ If you’re a farmer and would like to join LiteFarm you can sign up today at ap | |
|
||
# Setup | ||
|
||
LiteFarm is comprised of two applications which both reside in this monorepo. | ||
LiteFarm is comprised of three applications which all reside in this monorepo. | ||
|
||
- `packages/api`: the back-end API server | ||
- `packages/webapp`: the client-facing application | ||
- `packages/webapp` is the client-facing application | ||
- `packages/api` is the back-end API server with entry point `src/server.js` | ||
- `packages/api/src/jobs` is the "jobs scheduler" for certification exports, with entry point `index.js` | ||
|
||
## Preliminaries | ||
|
||
1. Install [node.js](https://nodejs.org/en/download/package-manager/) if you do not already have it. | ||
2. Use the `git clone` command to clone this repository to your computer. | ||
2. If you do not have pnpm installed, run `npm install -g pnpm` in a terminal. | ||
3. Use the `git clone` command to clone this repository to your computer. | ||
4. In a terminal, navigate to the root folder of the repo and run `npm install`. | ||
5. Navigate to the `packages/api` folder, and run `npm install`. | ||
6. Navigate to the `packages/webapp` folder, and run `pnpm install`. | ||
|
||
## Configure LiteFarm applications | ||
|
||
The applications are configured with environment variables stored in `.env` files. Configuration information includes secrets like API keys, so the `.env` files should never be added to source control. This repository does contain `.env.default` files for api and webapp. Begin with these, and customize as needed. | ||
## Configuring the applications | ||
|
||
1. Create the api configuration file by copying `packages/api/env.default` to `packages/api/.env`. | ||
The applications are configured with environment variables stored in `.env` files. Configuration information includes secrets like API keys, so the `.env` files should never be added to source control. This repository does contain `.env.default` files for api and webapp. These files contain all necessary environment variables, but for sensitive ones the values are redacted. Contact [email protected] for assistance. | ||
|
||
2. Create the webapp configuration file by copying `packages/webapp/env.default` to `packages/webapp/.env`. For webapp to work, you must edit your new `.env` file to provide values for two required environment variables: | ||
- `REACT_APP_GOOGLE_MAPS_API_KEY` is a Google Maps API key. You should obtain your own key value from [Google](https://developers.google.com/maps/documentation/javascript/get-api-key). | ||
- `REACT_APP_WEATHER_API_KEY` is an OpenWeather API key. You should obtain your own key value from [OpenWeather](https://openweathermap.org/api). | ||
|
||
## Runtime setup | ||
|
||
### Option 1: Docker containers | ||
|
||
This approach runs the LiteFarm applications and the database server in Docker containers. If you prefer to run them directly on your hardware, skip to the next section. | ||
|
||
1. Install [docker](https://docs.docker.com/desktop/) and [docker-compose](https://docs.docker.com/compose/install/) if you do not already have them. | ||
2. In a terminal, navigate to the root folder for the repository. | ||
3. Execute `docker-compose -f docker-compose.dev.yml up`. Alternatively, you can run `make up` if you have `make` installed. | ||
- The initial build will take some time. Subsequent incremental builds are much quicker. | ||
- This process will run [migrations](https://knexjs.org/#Migrations) to set up the PostgreSQL database, then start the Docker containers for webapp, api, databases, and Storybook. | ||
4. When the build completes, you can load the webapp at `http://localhost:3000`. Storybook is available on `http://localhost:6006`. | ||
|
||
### Option 2: Your hardware | ||
|
||
This approach runs the LiteFarm applications and database server directly on your hardware. If you prefer Docker containers, see the previous section. | ||
## Database setup | ||
|
||
1. Install PostgreSQL by downloading installers or packages from https://www.postgresql.org/download/. Alternatively, Mac and Linux users can use homebrew as shown below. | ||
|
||
|
@@ -58,7 +43,7 @@ This approach runs the LiteFarm applications and database server directly on you | |
brew services start postgresql | ||
``` | ||
|
||
2. Set up the PostgreSQL role (account) and databases. (The `packages/api/.env.default` file specifies `pg-litefarm` and `test_farm`, respectively, for development and test database names.) You will use the `psql` client program. Account setup details will vary by OS. If an installer asks you to choose a password for the `postgres` (superuser) account, use `postgres`. | ||
2. Set up the PostgreSQL role (account) and databases. You will use the `psql` client program. Account setup details will vary by OS. If an installer asks you to choose a password for the `postgres` (superuser) account, use `postgres` for consistency with the contents of `.env.default`. | ||
|
||
- Linux. In a terminal, start the client with `sudo -u postgres psql`, then execute each of the following commands. (The last command terminates the client session.) | ||
```sql | ||
|
@@ -67,39 +52,31 @@ This approach runs the LiteFarm applications and database server directly on you | |
CREATE DATABASE test_farm; | ||
exit; | ||
``` | ||
|
||
- Windows. At the Start menu, type `psql` and the search results will show "SQL Shell (psql)". In the client, execute each of the following commands. (The last command terminates the client session.) | ||
|
||
|
||
- Windows. At the Start menu, type `psql` and the search results will show "SQL Shell (psql)". In the client, execute | ||
each of the following commands. (The last command terminates the client session.) | ||
|
||
```sql | ||
CREATE DATABASE "pg-litefarm"; | ||
CREATE DATABASE test_farm; | ||
exit; | ||
``` | ||
|
||
3. In a terminal, navigate to the root folder of the repository. Run `npx lerna bootstrap` to install the dependencies for both applications. | ||
|
||
4. Edit the `packages/api/.env` file, setting the value of variable `DEV_DATABASE_HOST` to `localhost` | ||
|
||
5. In the terminal, navigate to the `packages/api` folder. | ||
3. In a terminal, navigate to the `packages/api` folder. Execute `npm run migrate:dev:db` to run the [migrations](https://knexjs.org/#Migrations) that set up the PostgreSQL database used by the app. | ||
|
||
6. Execute `npm run migrate:dev:db` to run the [migrations](https://knexjs.org/#Migrations) that set up the PostgreSQL database. (If you run into issues here, you can try dropping and recreating the database.) | ||
# Running the apps | ||
|
||
7. Run `npm start` to launch the api application. | ||
|
||
8. In a different terminal, navigate to the `packages/webapp` folder and run `npm start` to launch the webapp application. Load it in your browser at http://localhost:3000. | ||
## api | ||
|
||
# Testing | ||
In a terminal, navigate to the `packages/api` folder. Run `npm run nodemon` to launch the backend application. It will automatically reflect any changes you make to the backend. | ||
|
||
## webapp | ||
|
||
To run [ESLint](https://eslint.org/) checks execute `npm run lint` | ||
In a terminal, navigate to the `packages/webapp` folder and run `pnpm dev`. This builds the frontend code, and starts a web server that will automatically reflect any changes you make to the frontend. | ||
|
||
Since this is a mobile web application, webapp should be viewed in a mobile view in the browser. | ||
Load the frontend app in your browser at http://localhost:3000. | ||
|
||
Automated testing for the front-end is done using [cypress](https://www.cypress.io/). | ||
|
||
1. In a terminal, navigate to the `packages/webapp` folder. | ||
2. Execute `npm test` to launch the tests. Or, to generate test coverage information, run `npm test -- --coverage .` and then see the `coverage/index.html` file. | ||
# Testing | ||
|
||
## api | ||
|
||
|
@@ -111,4 +88,10 @@ The [chai.js](https://www.chaijs.com/) and [jest](https://jestjs.io/) libraries | |
2. Execute `npm run migrate:testing:db` to set up the test database. | ||
3. Execute `npm test` to launch the tests. Or, to generate test coverage information, run `npm test -- --coverage .` and then see the `coverage/index.html` file. | ||
|
||
It is good practice to use `psql` to `DROP` and `CREATE` the `test_farm` database before repeating this process. | ||
While the tests do attempt to clean up after themselves, it's a good idea to periodically use `psql` to `DROP` and `CREATE` the `test_farm` database, followed by the migrations from step 2 above. | ||
## webapp | ||
To run [ESLint](https://eslint.org/) checks execute `pnpm lint` | ||
Since this is a mobile web application, webapp should be viewed in a mobile view in the browser. |
Oops, something went wrong.