-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemented user registration, sending email notifications, and…
… api documentation Merge pull request #9 from vickywane/docs/swagger
- Loading branch information
Showing
48 changed files
with
16,082 additions
and
614 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 |
---|---|---|
@@ -1,29 +1,76 @@ | ||
name: Ambianic Functions API CI Test | ||
name: Ambianic Functions API CI Test | ||
|
||
# Controls when the action will run. Triggers the workflow on push or pull request | ||
# events but only for the master branch | ||
on: [pull_request] | ||
on: | ||
# Trigger the workflow on push or pull request against main branch | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Node JS ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install Newman dependency | ||
run: npm install --prefix tests/postman/ | ||
|
||
- name: Run the API and Postman's tests | ||
run: | | ||
cd tests/postman/ && newman run * | ||
env: | ||
CI: true | ||
- name: Install Node JS ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- uses: actions/checkout@v1 | ||
- name: Install application dependencies | ||
run: npm install | ||
|
||
- name: Generate OpenAPI specs+ | ||
run: npm run generate-swagger && ./scripts.sh cleanup | ||
|
||
- name: Local function testing | ||
run: npm run mock-server & sleep 10 && npm run test:postman | ||
env: | ||
FUNCTION_URL: http://127.0.0.1:4010 | ||
|
||
- name: Wait for successful preview deployment | ||
if: ${{ github.event_name == 'pull_request' }} | ||
uses: jakepartusch/wait-for-netlify-action@v1 | ||
id: get-netlify-url | ||
with: | ||
site_name: "ambianic-serverless" | ||
max_timeout: 60 | ||
|
||
- name: Run tests against deployed preview | ||
if: ${{ github.event_name == 'pull_request' }} | ||
run: npm run test:postman | ||
env: | ||
FUNCTION_URL: http://127.0.0.1:4010 | ||
|
||
- name: Run OpenAPI Tests and generate Code Coverage | ||
run: cd openapi-docs/ && npm install && npm run test | ||
|
||
- name: Create a static API documentation page from openapi specs | ||
run: npm run generate-docs | ||
|
||
# run this step only if its a push to the main branch | ||
- name: Publish static API documentation to Github Pages | ||
if: ${{ github.event_name == 'push' }} | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
personal_token: ${{ secrets.REPOSITORY_ACCESS_TOKEN }} | ||
publish_dir: ./docs | ||
|
||
- name: Run the semantic-release | ||
run: npx semantic-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Code Coverage Report | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: ./openapi-docs/coverage/coverage-final.json | ||
fail_ci_if_error: true | ||
|
||
- name: Checkout generated files | ||
uses: actions/checkout@v1 |
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 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 |
---|---|---|
@@ -1,10 +1,34 @@ | ||
# Ambianic-subscriptions | ||
|
||
## Repo for ambianic premium subscription management | ||
|
||
<p> This repo hosts [Netlify functions](https://www.netlify.com/products/functions/) that handle Ambianic premium user subscriptions. This is code that cannot run in the browser PWA, because it needs access keys to subscription and payment gateway services (Stripe) shared between all app users. If the code runs in the PWA, users will be able to see and manipulate each other's premium subscription data </p> | ||
|
||
|
||
The image below shows the architecture of these serverless functions in connection with the Ambianic [PWA](https://github.com/ambianic/ambianic-ui/). | ||
![serverless-functions-architecture](./assets/serverless-architecture.png) | ||
|
||
|
||
## Running Locally | ||
|
||
The serverless functions within this project are managed using [netlify-dev](https://www.netlify.com/products/dev/). Start the functions emulator from the `netlify` directory using `yarn netlify-dev` to listen for requests to any of created functions on port `5050`. | ||
|
||
Credentials within this project are managed using environment variables and [GitHub Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets). To run the functions here locally using the `netlify dev` command, create a `.env` file in the root directory with the following values; | ||
|
||
``` | ||
# Access key from Stripe to access your Stripe resources | ||
STRIPE_KEY=STRIPE_KEY | ||
# The product ID which users are subscribed to. | ||
EMAIL_PRODUCT_ID=STRIPE_KEY | ||
``` | ||
|
||
## CI / CD Pipeline | ||
|
||
|
||
The three currently available serverless function endpoints are all tested using [Postman Tests](https://www.postman.com/automated-testing/). The API documentation explaining the endpoints can be found in the GitHub pages for this repository [here](https://ambianic.github.io/ambianic-subscriptions.github.io/). An exported file of the postman collection in json format is available at `./tests/postman/ambianic-functions-collection.postman_collection.json`. | ||
|
||
Continuous integration for this project is managed using [GitHub Actions](https://github.com/features/actions), driven using the steps in the `.github/workflows/ci.yaml` file. The following sensitive credentials used within the CI jobs are managed using [Github Secrets](https://docs.github.com/en/actions/reference/encrypted-secrets); | ||
|
||
- STRIPE_KEY | ||
- GITHUB_TOKEN | ||
- NPM_TOKEN | ||
- REPOSITORY_ACCESS_TOKEN |
Oops, something went wrong.