Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub actions #1

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
93 changes: 93 additions & 0 deletions .github/workflows/authz_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: AuthZ CI

on:
push:
paths:
- apps/authz-node/**
- .github/workflows/**
- Makefile
- jest.config.ts
- jest.preset.js
- .eslintrc.json
- .prettierrc

jobs:
build-and-test:
name: Build and test

runs-on: ubuntu-latest

services:
postgres:
image: postgres:14
ports:
- '5432:5432'
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- '6379:6379'
env:
REDIS_PORT: 6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout
uses: actions/checkout@master

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '20.4.0'

- name: Install dependencies
run: |
make install/ci

- name: Code format
shell: bash
run: |
make format/check
make lint/check

# TODO: Finish once the authz-node has a database.
- name: Setup database and Prisma types
shell: bash
run: |
# make orchestration/test/copy-default-env
# make orchestration/test/db/setup

# Generate the orchestration Prisma client types to prevent the type
# tests to fail.
make orchestration/db/generate-types

- name: Test types
shell: bash
run: |
make authz/test/type

- name: Test unit
shell: bash
run: |
make authz/test/unit

- name: Test integration
shell: bash
run: |
make authz/test/integration

# - name: Test E2E
# shell: bash
# run: |
# make orchestration/test/e2e
89 changes: 89 additions & 0 deletions .github/workflows/orchestration_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Orchestration CI

on:
push:
paths:
- apps/orchestration/**
- .github/workflows/**
- Makefile
- jest.config.ts
- jest.preset.js
- .eslintrc.json
- .prettierrc

jobs:
build-and-test:
name: Build and test

runs-on: ubuntu-latest

services:
postgres:
image: postgres:14
ports:
- '5432:5432'
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis
ports:
- '6379:6379'
env:
REDIS_PORT: 6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout
uses: actions/checkout@master

- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: '20.4.0'

- name: Install dependencies
run: |
make install/ci

- name: Code format
shell: bash
run: |
make format/check
make lint/check

- name: Setup database and Prisma types
shell: bash
run: |
make orchestration/test/copy-default-env
make orchestration/test/db/setup
make orchestration/db/generate-types

- name: Test types
shell: bash
run: |
make orchestration/test/type

- name: Test unit
shell: bash
run: |
make orchestration/test/unit

- name: Test integration
shell: bash
run: |
make orchestration/test/integration

- name: Test E2E
shell: bash
run: |
make orchestration/test/e2e
34 changes: 13 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
include ./apps/orchestration/Makefile
include ./apps/authz-node/Makefile

install/ci:
npm ci

docker/stop:
docker-compose stop

Expand All @@ -12,25 +18,11 @@ format/check:
npx prettier \
--check "apps/**/*.ts" "packages/**/*.ts" "./*.{js,json}"

orchestration/db/generate-types:
npx prisma generate \
--schema ./apps/orchestration/src/persistence/schema/schema.prisma

orchestration/db/migrate:
npx dotenv -e ./apps/orchestration/.env -- \
prisma migrate dev \
--schema ./apps/orchestration/src/persistence/schema/schema.prisma

# Reference: https://www.prisma.io/docs/orm/prisma-migrate/workflows/seeding#seeding-your-database-with-typescript-or-javascript
orchestration/db/seed:
npx dotenv -e ./apps/orchestration/.env -- \
ts-node \
--compiler-options "{\"module\":\"CommonJS\"}" \
./apps/orchestration/src/persistence/seed.ts
lint:
npx nx run-many \
--target lint \
--fix

orchestration/test/db/setup:
npx dotenv -e ./apps/orchestration/.env.test --override -- \
prisma migrate reset \
--schema ./apps/orchestration/src/persistence/schema/schema.prisma \
--skip-seed \
--force
lint/check:
npx nx run-many \
--target lint
56 changes: 1 addition & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,3 @@
# Narval

<a alt="Nx logo" href="https://nx.dev" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-logo.png" width="45"></a>

✨ **This workspace has been generated by [Nx, a Smart, fast and extensible build system.](https://nx.dev)** ✨

## Generate code

If you happen to use Nx plugins, you can leverage code generators that might come with it.

Run `nx list` to get a list of available plugins and whether they have generators. Then run `nx list <plugin-name>` to see what generators are available.

Learn more about [Nx generators on the docs](https://nx.dev/plugin-features/use-code-generators).

## Running tasks

To execute tasks with Nx use the following syntax:

```
nx <target> <project> <...options>
```

You can also run multiple targets:

```
nx run-many -t <target1> <target2>
```

..or add `-p` to filter specific projects

```
nx run-many -t <target1> <target2> -p <proj1> <proj2>
```

Targets can be defined in the `package.json` or `projects.json`. Learn more [in the docs](https://nx.dev/core-features/run-tasks).

## Want better Editor Integration?

Have a look at the [Nx Console extensions](https://nx.dev/nx-console). It provides autocomplete support, a UI for exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.

## Ready to deploy?

Just run `nx build demoapp` to build the application. The build artifacts will be stored in the `dist/` directory, ready to be deployed.

## Set up CI!

Nx comes with local caching already built-in (check your `nx.json`). On CI you might want to go a step further.

- [Set up remote caching](https://nx.dev/core-features/share-your-cache)
- [Set up task distribution across multiple machines](https://nx.dev/nx-cloud/features/distribute-task-execution)
- [Learn more how to setup CI](https://nx.dev/recipes/ci)

## Connect with us!

- [Join the community](https://nx.dev/community)
- [Subscribe to the Nx Youtube Channel](https://www.youtube.com/@nxdevtools)
- [Follow us on Twitter](https://twitter.com/nxdevtools)
[![Orchestration CI](https://github.com/narval-xyz/narval/actions/workflows/ci_orchestration.yml/badge.svg?branch=main)](https://github.com/narval-xyz/narval/actions/workflows/ci_orchestration.yml)
2 changes: 2 additions & 0 deletions apps/authz-node/.env.test.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# IMPORTANT: The variables defined here will override other variables.
# See `./apps/authz-node/jest.setup.ts`.
17 changes: 17 additions & 0 deletions apps/authz-node/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AUTHZ_PROJECT_NAME := apps/authz-node
AUTHZ_PROJECT_DIR := ./apps/authz-node

authz/test/copy-default-env:
cp ${AUTHZ_PROJECT_DIR}/.env.test.default ${AUTHZ_PROJECT_DIR}/.env.test

authz/test/type:
npx nx test:type ${AUTHZ_PROJECT_NAME}

authz/test/unit:
npx nx test:unit ${AUTHZ_PROJECT_NAME}

authz/test/integration:
npx nx test:integration ${AUTHZ_PROJECT_NAME}

authz/test/e2e:
npx nx test:e2e ${AUTHZ_PROJECT_NAME}
2 changes: 1 addition & 1 deletion apps/authz-node/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Config } from 'jest'

const config: Config = {
displayName: 'apps/orchestration',
displayName: 'apps/authz-node',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
Expand Down
9 changes: 9 additions & 0 deletions apps/authz-node/jest.integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Config } from 'jest'
import sharedConfig from './jest.config'

const config: Config = {
...sharedConfig,
testMatch: ['<rootDir>/**/__test__/integration/**/*.spec.ts']
}

export default config
28 changes: 28 additions & 0 deletions apps/authz-node/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import dotenv from 'dotenv'
import fs from 'fs'
import nock from 'nock'

const testEnvFile = `${__dirname}/.env.test`
const envFile = `${__dirname}/.env`

// Ensure a test environment variable file exists because of the override config
// loading mechanics below.
if (!fs.existsSync(testEnvFile)) {
throw new Error('No .env.test file found. Please create one by running "make authz/test/copy-default-env".')
}

// We don't want to have two dotenv files that are exactly the same, so we
// override the default with .env.test.
//
// If a .env.test file is not found, the DATABASE_URL will fallback to the
// default. Consequently, you'll lose your development database during the
// integration tests teardown. Hence, the check above.
dotenv.config({ path: envFile })
dotenv.config({ path: testEnvFile, override: true })

// Disable outgoing HTTP requests to avoid flaky tests.
nock.disableNetConnect()

// Enable outgoing HTTP requests to 127.0.0.1 to allow E2E tests with
// supertestwith supertest to work.
nock.enableNetConnect('127.0.0.1')
14 changes: 14 additions & 0 deletions apps/authz-node/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,27 @@
"lintFilePatterns": ["apps/authz-node/**/*.ts"]
}
},

"test:type": {
"executor": "nx:run-commands",
"options": {
"command": "npx tsc --noEmit --project apps/orchestration/tsconfig.app.json"
}
},
"test:unit": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/authz-node/jest.unit.ts"
}
},
"test:integration": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/authz-node/jest.integration.ts"
}
},
"test:e2e": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
Expand Down
5 changes: 5 additions & 0 deletions apps/authz-node/src/app/__test__/integration/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('Example integration test', () => {
it('foo', () => {
expect(1).toEqual(1)
})
})
Loading