Skip to content

Commit

Permalink
ci: enhanced
Browse files Browse the repository at this point in the history
  • Loading branch information
cshezi committed Jan 9, 2024
1 parent 4c04c1d commit 5c025e4
Showing 1 changed file with 110 additions and 58 deletions.
168 changes: 110 additions & 58 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_SCOPE: "@frmscoe"
NPM_REGISTRY: "https://npm.pkg.github.com/"
NODE_ENV: 'test'
STARTUP_TYPE: 'nats'

on:
push:
branches: [ "main" ]
Expand All @@ -18,62 +10,122 @@ on:
jobs:
build:
runs-on: ubuntu-latest
name: run build
outputs:
responseAverage: ${{ steps.newman_test.outputs.responseAverage }}
responseMin: ${{ steps.newman_test.outputs.responseMin }}
responseMax: ${{ steps.newman_test.outputs.responseMax }}
responseSd: ${{ steps.newman_test.outputs.responseSd }}
name: install, build, test
permissions:
packages: write
contents: read
strategy:
matrix:
node-version: [16, 20]
node-version: [20]
redis-version: [6]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- uses: actions/checkout@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
registry-url: ${{ env.NPM_REGISTRY }}
scope: ${{ env.NPM_SCOPE }}
- name: Install dependencies
run: npm ci
- name: Run build
run: npm run build
ref: ext-gh-ci
- uses: pnpm/action-setup@v2
with:
version: 7

lint:
runs-on: ubuntu-latest
name: check style
strategy:
matrix:
node-version: [20]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
- name: Start Arango
uses: xinova/arangodb-action@v1
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
registry-url: ${{ env.NPM_REGISTRY }}
scope: ${{ env.NPM_SCOPE }}
- name: Install dependencies
run: npm ci
- name: Check linting
run: npm run lint
arangodb version: 'latest'

test:
runs-on: ubuntu-latest
name: check tests
strategy:
matrix:
node-version: [20]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
- name: Setup Arango
run: newman run https://raw.githubusercontent.com/frmscoe/postman/indexes/ArangoDB%20Setup.json -e https://raw.githubusercontent.com/frmscoe/postman/indexes/environments/Ekuta-LOCAL.postman_environment.json --timeout-request 10200

- name: Startup Nats
uses: onichandame/nats-action@master
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
registry-url: ${{ env.NPM_REGISTRY }}
scope: ${{ env.NPM_SCOPE }}
port: 4222

- name: Startup Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}

- name: StartUp Nats-Rest Proxy
run: docker pull ghcr.io/cshezi/nats-utilities:latest && docker run --network=host -e NODE_ENV='dev' ghcr.io/cshezi/nats-utilities:latest &

- name: Setup Node.js (.npmrc)
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://npm.pkg.github.com/
scope: '@frmscoe'

- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
run: npm install -g newman && npm install -g newman-reporter-htmlextra && npm ci
env:
GH_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

- name: Run unit tests
run: npm run test
env:
NODE_ENV: 'test'
STARTUP_TYPE: 'nats'

- name: Processor Build
run: npm run build

- name: Processor Start
run: npm run start &
env:
NODE_ENV: 'dev'
STARTUP_TYPE: 'nats'
SERVER_URL: 'nats://localhost:4222'
ACK_POLICY: 'None'
PRODUCER_STREAM: 'temp-rule-sub'
CONSUMER_STREAM: 'CRSP'
STREAM_SUBJECT:
APM_ACTIVE: false
APM_LOGGING: false
FUNCTION_NAME: 'typology-processor'
REDIS_DB: 0
REDIS_AUTH:
REDIS_SERVERS: '[{"host":"127.0.0.1", "port":6379}]'
REDIS_IS_CLUSTER: false
DATABASE_URL: 'http://localhost:8529/'
DATABASE_USER: 'root'
DATABASE_PASSWORD:
DATABASE_NAME: 'networkmap'

- name: Test Processor
run: newman run https://raw.githubusercontent.com/frmscoe/postman/indexes/NATS_RES_CRSP_TEST.postman_collection.json -e https://raw.githubusercontent.com/frmscoe/postman/indexes/environments/Ekuta-LOCAL.postman_environment.json --timeout-request 10200 -r json --reporter-json-export summary.json

- name: Extract Specific Field
id: newman_test
run: |
echo "::set-output name=responseAverage::$(jq -r '.run.timings.responseAverage' summary.json)"
echo "::set-output name=responseMin::$(jq -r '.run.timings.responseMin' summary.json)"
echo "::set-output name=responseMax::$(jq -r '.run.timings.responseMax' summary.json)"
echo "::set-output name=responseSd::$(jq -r '.run.timings.responseSd' summary.json)"
- name: Upload Results
uses: actions/upload-artifact@v3
with:
name: summary.json
path: summary.json


output:
needs: build
runs-on: ubuntu-latest
steps:
- name: Comment on PR

run: |
COMMENT_BODY="<li> Response Average ${{ needs.build.outputs.responseAverage }}ms ⚠️<br /><li>Response Min ${{ needs.build.outputs.responseMin }}ms <br /><li>Response max ${{ needs.build.outputs.responseMax }}ms <br /><li>Response Stardard dev ${{ needs.build.outputs.responseSd }}ms"
API_URL="https://api.github.com/repos/${{github.repository}}/issues/${{github.event.number}}/comments"
curl -X POST \
-H "Authorization: Bearer ${{ secrets.GH_TOKEN }}" \
-H "Content-Type: application/json" \
--data-raw "{\"body\":\"$COMMENT_BODY\"}" \
$API_URL

0 comments on commit 5c025e4

Please sign in to comment.