Skip to content

Commit

Permalink
fix: 🐛 add tests and standardize repo
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmohamed-anno committed Jan 26, 2021
1 parent 28a67b0 commit 8bf59ae
Show file tree
Hide file tree
Showing 13 changed files with 12,556 additions and 124 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/node-audit-dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: NPM Audit Dependencies

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Setup npmrc
run: echo "" >> .npmrc && echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" >> .npmrc
- run: npx audit-ci -m
37 changes: 37 additions & 0 deletions .github/workflows/node-js-unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js Unit Tests

on:
push:
branches: [ devel ]
pull_request:
branches: [ devel ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Setup npmrc
run: echo "" >> .npmrc && echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" >> .npmrc
- run: npm ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm run build --if-present
- run: npm run test:unit
env:
ANNO_AI_SERVICES_CERT: ${{ secrets.ANNO_AI_SERVICES_CERT }}
56 changes: 56 additions & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Semantic Release

on:
push:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [10.x]

steps:
- name: Git Checkout
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Setup npmrc
run: echo "" >> .npmrc && echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" >> .npmrc

- run: npm ci
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- run: npm run build --if-present

- run: npm run test:unit
env:
ANNO_AI_SERVICES_CERT: ${{ secrets.ANNO_AI_SERVICES_CERT }}

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
with:
semantic_version: 17.1.1
id: semantic # Need an `id` for output variables
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Do something when a new release published
if: steps.semantic.outputs.new_release_published == 'true'
run: |
echo ${{ steps.semantic.outputs.new_release_version }}
echo ${{ steps.semantic.outputs.new_release_major_version }}
echo ${{ steps.semantic.outputs.new_release_minor_version }}
echo ${{ steps.semantic.outputs.new_release_patch_version }}
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
################################################
# Anno.Ai Application Specific
################################################


################################################
# Exclude default node gitignore
# https://github.com/anno-ai/anno.ai-gitignore/blob/master/Node.gitignore
################################################

# Mac specific hidden files
.DS_STORE

# Exclude certificates
*.crt
*.key
*.pem

# Logs
logs
*.log
*.swp
*.out
npm-debug.log*
yarn-debug.log*
yarn-error.log*
Expand Down
7 changes: 7 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"spec": [
"./**/*.test.js",
"./**/*.test.ts"
],
"require": "ts-node/register"
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
![Node.js Unit Tests](https://github.com/anno-ai/node-is-required-env-set/workflows/Node.js%20Unit%20Tests/badge.svg)

![NPM Audit Dependencies](https://github.com/anno-ai/node-is-required-env-set/workflows/NPM%20Audit%20Dependencies/badge.svg)

# node-is-required-env-set

Helper function to check if required environment variables are set

# Usage
Expand Down
1 change: 0 additions & 1 deletion app.js → app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { isRequiredEnvSet } = require('./index.js')

isRequiredEnvSet('Shell', ['SHELL'])

24 changes: 0 additions & 24 deletions index.js

This file was deleted.

22 changes: 22 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const checkEnv = require('check-env')

/**
*
* @param {String} name The name of the service you are checking environment variables for
* @param {Array} vars Array of variable names to check if set
* @param {Bool} fatal If true, function will throw error instead of printing
* @param {String} type The type of service that you are checking environment variables for
*/
export function isRequiredEnvSet (name: string, vars: any = [], fatal: boolean = false, type: string = 'plugin') {
try {
checkEnv(vars)
return true
} catch (err) {
const _err = `${name} ${type} requires the following environment variables to be set: ${vars.join(', ')}`
if (fatal) {
throw new Error(_err)
}
console.log(_err)
return false
}
}
Loading

0 comments on commit 8bf59ae

Please sign in to comment.