Skip to content

Commit

Permalink
feat(agent): initialise agent library (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
arpentnoir authored Mar 21, 2023
1 parent 4c891d5 commit e5fa0ad
Show file tree
Hide file tree
Showing 18 changed files with 2,243 additions and 59 deletions.
133 changes: 133 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name:

on:
push:
branches:
- master
pull_request:

env:
HUSKY: 0

jobs:
main:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ github.workspace }}
strategy:
matrix:
node-version: [16]
npm-version: [8]
yarn-version: ['1.22.x']
pnpm-version: [7]
steps:
- name: Checkout [Pull Request]
uses: actions/checkout@v2
if: ${{ github.event_name == 'pull_request' }}
with:
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 0

- name: Checkout [Default Branch]
uses: actions/checkout@v2
if: ${{ github.event_name != 'pull_request' }}
with:
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 0

- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
with:
main-branch-name: ${{ github.base_ref }}

- name: Detect package manager
id: package_manager
run: |
echo "::set-output name=name::$([[ -f ./yarn.lock ]] && echo "yarn" || ([[ -f ./pnpm-lock.yaml ]] && echo "pnpm") || echo "npm")"
- name: Set node/npm/yarn versions using volta
uses: volta-cli/action@fdf4cf319494429a105efaa71d0e5ec67f338c6e
with:
node-version: '${{ matrix.node-version }}'
npm-version: '${{ matrix.npm-version }}'
yarn-version: '${{ matrix.yarn-version }}'

- name: Install PNPM
if: steps.package_manager.outputs.name == 'pnpm'
uses: pnpm/[email protected]
with:
version: '${{ matrix.pnpm-version }}'

- name: Print node/npm/yarn/pnpm versions
id: versions
run: |
node_ver=$( node --version )
yarn_ver=$( yarn --version || true )
pnpm_ver=$( pnpm --version || true )
echo "Node: ${node_ver:1}"
echo "NPM: $(npm --version )"
if [[ $yarn_ver != '' ]]; then echo "Yarn: $yarn_ver"; fi
if [[ $pnpm_ver != '' ]]; then echo "PNPM: $pnpm_ver"; fi
echo "::set-output name=node_version::${node_ver:1}"
- name: Use the node_modules cache if available [npm]
if: steps.package_manager.outputs.name == 'npm'
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-
- name: Use the node_modules cache if available [pnpm]
if: steps.package_manager.outputs.name == 'pnpm'
uses: actions/cache@v2
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-
- name: Get yarn cache directory path
if: steps.package_manager.outputs.name == 'yarn'
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Use the node_modules cache if available [yarn]
if: steps.package_manager.outputs.name == 'yarn'
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-node-${{ steps.versions.outputs.node_version }}-
- name: Install dependencies
run: |
if [ "${{ steps.package_manager.outputs.name == 'yarn' }}" == "true" ]; then
echo "Running yarn install --frozen-lockfile"
yarn install --frozen-lockfile
elif [ "${{ steps.package_manager.outputs.name == 'pnpm' }}" == "true" ]; then
echo "Running pnpm install --frozen-lockfile"
pnpm install --frozen-lockfile
else
echo "Running npm ci"
npm ci
fi
- run: |
npx nx workspace-lint
npx nx format:check
npx nx affected --target lint --parallel 3
npx nx affected --target test --parallel 3 --ci --code-coverage
npx nx affected --target build --parallel 3
- name: Release
if: ${{ success() && (github.event_name != 'pull_request' || github.event.action == 'closed' && github.event.pull_request.merged == true) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npx nx affected --target release
3 changes: 3 additions & 0 deletions libs/agent/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
}
18 changes: 18 additions & 0 deletions libs/agent/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
11 changes: 11 additions & 0 deletions libs/agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# agent

This library was generated with [Nx](https://nx.dev).

## Running unit tests

Run `nx test agent` to execute the unit tests via [Jest](https://jestjs.io).

## Running lint

Run `nx lint agent` to execute the lint via [ESLint](https://eslint.org/).
15 changes: 15 additions & 0 deletions libs/agent/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable */
export default {
displayName: 'agent',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
},
},
transform: {
'^.+\\.[tj]sx?$': 'ts-jest',
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/agent',
};
12 changes: 12 additions & 0 deletions libs/agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@vckit/agent",
"version": "0.0.1-semantic-release",
"repository": {
"type": "git",
"url": "https://github.com/uncefact/project-vckit.git",
"directory":"libs/agent"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
}
42 changes: 42 additions & 0 deletions libs/agent/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "agent",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "libs/agent/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/libs/agent",
"main": "libs/agent/src/index.ts",
"tsConfig": "libs/agent/tsconfig.lib.json",
"assets": ["libs/agent/*.md"]
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["libs/agent/**/*.ts"]
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "libs/agent/jest.config.ts",
"passWithNoTests": true
}
},
"release": {
"executor": "nx:run-commands",
"outputs": [],
"options": {
"command": "npx semantic-release-plus --extends ./packages/agent/release.config.js",
"parallel": false
}
}
},
"tags": []
}
29 changes: 29 additions & 0 deletions libs/agent/release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const name = 'agent';
const srcRoot = `libs/${name}`;

module.exports = {
extends: 'release.config.base.js',
pkgRoot: `dist/${srcRoot}`,
tagFormat: name + '-v${version}',
commitPaths: [`${srcRoot}/*`],
plugins: [
'@semantic-release/commit-analyser',
'@semantic-release/release-notes-generator',
[
'@semantic-release/changelog',
{
changelogFile: `${srcRoot}CHANGELOG.md`
},
],
'@semantic-release/npm',
[
'@semantic-release/git',
{
assets: [`${srcRoot}/package.json`, `${srcRoot}/CHANGELOG.md`],
message:
`release (version): Release ${name}` +
'$nextRelease.version [skip ci] \n\n${nextRelease.notes}',
}
]
]
}
1 change: 1 addition & 0 deletions libs/agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/agent';
7 changes: 7 additions & 0 deletions libs/agent/src/lib/agent.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { agent } from './agent';

describe('agent', () => {
it('should work', () => {
expect(agent()).toEqual('agent');
});
});
3 changes: 3 additions & 0 deletions libs/agent/src/lib/agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function agent(): string {
return 'agent';
}
19 changes: 19 additions & 0 deletions libs/agent/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
10 changes: 10 additions & 0 deletions libs/agent/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": []
},
"include": ["**/*.ts"],
"exclude": ["jest.config.ts", "**/*.spec.ts"]
}
20 changes: 20 additions & 0 deletions libs/agent/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"**/*.test.ts",
"**/*.spec.ts",
"**/*.test.tsx",
"**/*.spec.tsx",
"**/*.test.js",
"**/*.spec.js",
"**/*.test.jsx",
"**/*.spec.jsx",
"**/*.d.ts"
]
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"react-pdf": "5.7.2",
"react-router-dom": "^6.4.2",
"regenerator-runtime": "0.13.7",
"semantic-release-npm-github": "^4.0.0",
"semantic-release-plus": "^20.0.0",
"shortid": "^2.2.16",
"styled-components": "5.3.5",
"supertest": "^6.3.1",
Expand All @@ -91,6 +93,7 @@
"@nrwl/eslint-plugin-nx": "15.0.4",
"@nrwl/express": "15.0.4",
"@nrwl/jest": "15.0.4",
"@nrwl/js": "15.0.4",
"@nrwl/linter": "15.0.4",
"@nrwl/node": "15.0.4",
"@nrwl/react": "15.0.4",
Expand Down
3 changes: 3 additions & 0 deletions release.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: 'semantic-release-npm-github-publish'
}
5 changes: 3 additions & 2 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"@dvp/api-interfaces": ["libs/api-interfaces/src/index.ts"],
"@dvp/api-client": ["libs/api-client/src/index.ts"],
"@dvp/api-interfaces": ["libs/api-interfaces/src/index.ts"],
"@dvp/server-common": ["libs/server-common/src/index.ts"],
"@dvp/vc-ui": ["libs/vc-ui/src/index.ts"]
"@dvp/vc-ui": ["libs/vc-ui/src/index.ts"],
"@vckit/agent": ["libs/agent/src/index.ts"]
},
"esModuleInterop": true
},
Expand Down
Loading

0 comments on commit e5fa0ad

Please sign in to comment.