Skip to content

Commit c855e3a

Browse files
committed
add CI config
1 parent 9b018bd commit c855e3a

File tree

7 files changed

+241
-6
lines changed

7 files changed

+241
-6
lines changed

.github/workflows/ci.yml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
# Permissions needed to push to gh-pages
9+
permissions:
10+
contents: write
11+
pages: write
12+
13+
jobs:
14+
openapi-client-generation:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: '20.x'
23+
cache: 'npm'
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Verify OpenAPI client generation
29+
run: |
30+
# Store hash of essential generated files
31+
find src -type f \( -name "*.ts" -o -name "*.json" \) -not -path "*/\.*" -exec sha256sum {} \; | sort > generated_files.hash
32+
# Generate again
33+
npm run generate
34+
# Compare hashes of essential files
35+
find src -type f \( -name "*.ts" -o -name "*.json" \) -not -path "*/\.*" -exec sha256sum {} \; | sort > new_generated_files.hash
36+
if ! diff generated_files.hash new_generated_files.hash; then
37+
echo "ERROR: Generated files differ from committed files."
38+
echo "This usually means that the OpenAPI client code needs to be regenerated."
39+
echo "Please run 'npm run generate' locally and commit the changes."
40+
echo ""
41+
echo "Differences found in the following files:"
42+
diff generated_files.hash new_generated_files.hash || true
43+
exit 1
44+
fi
45+
46+
test:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
51+
- name: Set up Node.js
52+
uses: actions/setup-node@v4
53+
with:
54+
node-version: '20.x'
55+
cache: 'npm'
56+
57+
- name: Install dependencies
58+
run: npm ci
59+
60+
- name: Set up Julia
61+
uses: julia-actions/setup-julia@v2
62+
63+
- name: Cache Julia packages
64+
uses: julia-actions/cache@v2
65+
66+
- name: Clone RxInferServer
67+
run: |
68+
git clone https://github.com/lazydynamics/RxInferServer.git
69+
cd RxInferServer
70+
71+
- name: Build RxInferServer
72+
uses: julia-actions/julia-buildpkg@v1
73+
74+
- name: Start RxInferServer in background and execute tests
75+
run: |
76+
cd RxInferServer
77+
make docker
78+
make dev &
79+
cd ..
80+
npm test
81+
82+
docs:
83+
runs-on: ubuntu-latest
84+
permissions:
85+
contents: write
86+
steps:
87+
- uses: actions/checkout@v4
88+
89+
- name: Set up Node.js
90+
uses: actions/setup-node@v4
91+
with:
92+
node-version: '20.x'
93+
cache: 'npm'
94+
95+
- name: Install dependencies
96+
run: npm ci
97+
98+
- name: Set up Julia
99+
uses: julia-actions/setup-julia@v2
100+
101+
- name: Cache Julia packages
102+
uses: julia-actions/cache@v2
103+
104+
- name: Clone RxInferServer
105+
run: |
106+
git clone https://github.com/lazydynamics/RxInferServer.git
107+
cd RxInferServer
108+
109+
- name: Build RxInferServer
110+
uses: julia-actions/julia-buildpkg@v1
111+
112+
- name: Start RxInferServer in background and build docs
113+
run: |
114+
cd RxInferServer
115+
make docker
116+
make dev &
117+
cd ..
118+
npm run docs
119+
120+
- name: Deploy documentation
121+
if: github.ref == 'refs/heads/main'
122+
uses: peaceiris/actions-gh-pages@v3
123+
with:
124+
github_token: ${{ secrets.GITHUB_TOKEN }}
125+
publish_dir: ./docs/build
126+
publish_branch: gh-pages

jest.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { pathsToModuleNameMapper } = require('ts-jest');
2+
const { compilerOptions } = require('./tsconfig');
3+
4+
/** @type {import('ts-jest').JestConfigWithTsJest} */
5+
module.exports = {
6+
preset: 'ts-jest',
7+
testEnvironment: 'node',
8+
testMatch: ['**/test/**/*.ts'],
9+
collectCoverage: true,
10+
coverageDirectory: 'coverage',
11+
coverageReporters: ['text', 'lcov'],
12+
verbose: true,
13+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/src/' }),
14+
moduleDirectories: ['node_modules', 'src'],
15+
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
16+
};

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
"version": "1.1.0",
44
"description": "A client to connect to RxInferServer",
55
"main": "dist/index.js",
6+
"module": "dist/index.mjs",
67
"types": "dist/index.d.ts",
8+
"browser": "dist/index.browser.js",
79
"scripts": {
8-
"build": "tsc",
10+
"build": "tsc && npm run build:browser",
11+
"build:browser": "esbuild src/index.ts --bundle --platform=browser --outfile=dist/index.browser.js --format=esm",
912
"generate": "openapi-ts",
10-
"docs": "typedoc --out docs/build src",
13+
"docs": "node scripts/wait-for-server.js && typedoc --out docs/build src",
1114
"docs:serve": "npx serve docs",
12-
"test": "echo \"Error: no test specified\" && exit 1"
15+
"test": "node scripts/wait-for-server.js && jest",
16+
"test:watch": "jest --watch",
17+
"test:coverage": "jest --coverage"
1318
},
1419
"repository": {
1520
"type": "git",
@@ -30,7 +35,11 @@
3035
},
3136
"devDependencies": {
3237
"@hey-api/openapi-ts": "^0.66.4",
38+
"@types/jest": "^29.5.14",
3339
"@types/node": "^20.11.24",
40+
"esbuild": "^0.20.2",
41+
"jest": "^29.7.0",
42+
"ts-jest": "^29.3.2",
3443
"typedoc": "^0.28.2",
3544
"typescript": "^5.3.3"
3645
}

scripts/wait-for-server.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env node
2+
3+
const axios = require('axios');
4+
const { setTimeout } = require('timers/promises');
5+
6+
const isRunningInCI = () => {
7+
const ciEnvVars = [
8+
'CI', // Generic CI
9+
'GITHUB_ACTIONS', // GitHub Actions
10+
'GITLAB_CI', // GitLab CI
11+
'CIRCLECI', // Circle CI
12+
'JENKINS_URL', // Jenkins
13+
'TRAVIS', // Travis CI
14+
'TF_BUILD', // Azure Pipelines
15+
'TEAMCITY_VERSION' // TeamCity
16+
];
17+
return ciEnvVars.some(varName => process.env[varName]);
18+
};
19+
20+
const waitForServer = async (timeout = null, retryInterval = null) => {
21+
const isCI = isRunningInCI();
22+
timeout = timeout || (isCI ? 300 : 30); // 5 minutes in CI, 30 seconds locally
23+
retryInterval = retryInterval || (isCI ? 10 : 1); // 10 seconds in CI, 1 second locally
24+
25+
const startTime = Date.now();
26+
const envType = isCI ? "CI" : "local";
27+
28+
console.log(`Waiting for RxInferServer to become available (${envType} environment)...`);
29+
30+
while (Date.now() - startTime < timeout * 1000) {
31+
try {
32+
const response = await axios.get('http://localhost:8000/v1/ping');
33+
if (response.data.status === 'ok') {
34+
console.log("RxInferServer is available!");
35+
return true;
36+
}
37+
} catch (error) {
38+
// Ignore errors and retry
39+
}
40+
41+
console.log(`Server not available yet. Will retry in ${retryInterval} seconds...`);
42+
await setTimeout(retryInterval * 1000);
43+
}
44+
45+
console.log(`Error: RxInferServer did not become available within ${timeout} seconds (${envType} environment)`);
46+
return false;
47+
};
48+
49+
waitForServer()
50+
.then(success => process.exit(success ? 0 : 1))
51+
.catch(error => {
52+
console.error('Error:', error);
53+
process.exit(1);
54+
});

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
* @packageDocumentation
44
*/
55

6-
export * from './client/index';
6+
export * from './client/index';
7+
8+
export class RxInferClient {
9+
constructor() { }
10+
}

test/client.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { RxInferClient } from '../src';
2+
3+
describe('RxInferClient', () => {
4+
let client: RxInferClient;
5+
6+
beforeEach(() => {
7+
client = new RxInferClient();
8+
});
9+
10+
it('should instantiate the client', () => {
11+
expect(client).toBeInstanceOf(RxInferClient);
12+
});
13+
14+
it('should ping the server', async () => {
15+
// Mock the ping method if it exists in your client
16+
// This is a placeholder test that will need to be updated
17+
// once the OpenAPI client is generated
18+
expect(client).toBeDefined();
19+
});
20+
});

tsconfig.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
{
22
"compilerOptions": {
33
"target": "es2018",
4-
"module": "commonjs",
4+
"module": "esnext",
55
"declaration": true,
66
"outDir": "./dist",
77
"strict": true,
88
"esModuleInterop": true,
99
"skipLibCheck": true,
1010
"forceConsistentCasingInFileNames": true,
11-
"moduleResolution": "node"
11+
"moduleResolution": "node",
12+
"baseUrl": ".",
13+
"paths": {
14+
"@/*": ["src/*"]
15+
},
16+
"lib": ["es2018", "dom"],
17+
"types": ["node", "jest"]
1218
},
1319
"include": ["src/**/*"],
1420
"exclude": ["node_modules", "dist"]

0 commit comments

Comments
 (0)