Skip to content

Commit 22d8a40

Browse files
authored
Added GH Action with PR checks for build validity (#8)
* Cleaned up logger * Added GH Action to do PR checks * Consolidated GH Action * Making pnpm happy * Move TS type check after build so types are ready * Resolved issue with new noOpLogger type
1 parent 30eae4e commit 22d8a40

File tree

5 files changed

+125
-7
lines changed

5 files changed

+125
-7
lines changed

.github/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# GitHub Actions Workflows
2+
3+
This directory contains GitHub Actions workflows that automate various tasks for the MessariKit project.
4+
5+
## Workflows
6+
7+
### PR Checks (`pr-checks.yml`)
8+
9+
This workflow runs on pull requests and pushes to master branches (main, master, develop). It ensures that:
10+
11+
- Code passes linting
12+
- API spec validation and generation works
13+
- All packages build successfully
14+
- Tests pass
15+
- TypeScript types check correctly
16+
- Dependencies can be installed without conflicts
17+
18+
## Contributing
19+
20+
When contributing to this project, your PR will automatically be validated by these workflows. Make sure that all checks pass before requesting a review.
21+
22+
## Customizing
23+
24+
To modify these workflows:
25+
26+
1. Edit the YAML files in this directory
27+
2. Commit your changes
28+
3. Push to your branch
29+
4. Create a PR to get your changes reviewed

.github/workflows/pr-checks.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
branches: [ master ]
6+
push:
7+
branches: [ master ]
8+
9+
jobs:
10+
# Runs linter, tsc type-check, api type generation + validation, pkg build, and tests
11+
build-checks:
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [18.x]
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
28+
- name: Setup PNPM
29+
uses: pnpm/action-setup@v2
30+
with:
31+
version: latest
32+
run_install: false
33+
34+
- name: Get pnpm store directory
35+
id: pnpm-cache
36+
shell: bash
37+
run: |
38+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
39+
40+
- name: Setup pnpm cache
41+
uses: actions/cache@v3
42+
with:
43+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
44+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
45+
restore-keys: |
46+
${{ runner.os }}-pnpm-store-
47+
48+
- name: Install dependencies
49+
run: pnpm install
50+
51+
- name: Lint code
52+
run: pnpm lint:fix
53+
54+
- name: API validation and generation
55+
run: pnpm api:build
56+
57+
- name: Build all packages
58+
run: pnpm build
59+
60+
- name: Check TypeScript
61+
run: pnpm -r exec tsc --noEmit
62+
63+
- name: Run tests
64+
run: pnpm test
65+
66+
dependency-check:
67+
runs-on: ubuntu-latest
68+
69+
strategy:
70+
matrix:
71+
node-version: [18.x]
72+
73+
steps:
74+
- uses: actions/checkout@v3
75+
76+
- name: Use Node.js ${{ matrix.node-version }}
77+
uses: actions/setup-node@v3
78+
with:
79+
node-version: ${{ matrix.node-version }}
80+
81+
- name: Setup PNPM
82+
uses: pnpm/action-setup@v2
83+
with:
84+
version: latest
85+
run_install: false
86+
87+
- name: Check for dependency issues
88+
run: pnpm install --frozen-lockfile
89+

packages/api/src/client/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import type {
3131
getAssetListResponse,
3232
getAssetListParameters,
3333
} from "@messari-kit/types";
34-
import { LogLevel, type Logger, makeConsoleLogger, createFilteredLogger, makeNoOpLogger } from "../logging";
34+
import { LogLevel, type Logger, makeConsoleLogger, createFilteredLogger, noOpLogger } from "../logging";
3535
import type { PaginatedResult, RequestOptions, ClientEventMap, ClientEventType, ClientEventHandler } from "./types";
3636

3737
/**
@@ -255,7 +255,7 @@ export abstract class MessariClientBase {
255255
*/
256256
public disableLogging(): void {
257257
this.isLoggingDisabled = true;
258-
this.logger = makeNoOpLogger();
258+
this.logger = noOpLogger;
259259
}
260260

261261
/**

packages/api/src/client/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import type {
5353
} from "@messari-kit/types";
5454
import type { Agent } from "node:http";
5555
import { pick } from "../utils";
56-
import { LogLevel, type Logger, makeConsoleLogger, createFilteredLogger, makeNoOpLogger } from "../logging";
56+
import { LogLevel, type Logger, makeConsoleLogger, createFilteredLogger, noOpLogger } from "../logging";
5757
import { RequestTimeoutError } from "../error";
5858
import type {
5959
ClientEventHandler,
@@ -108,10 +108,10 @@ export class MessariClient extends MessariClientBase {
108108
// Handle logger initialization with disableLogging option
109109
this.isLoggingDisabled = !!options.disableLogging;
110110
if (this.isLoggingDisabled) {
111-
this.logger = makeNoOpLogger();
111+
this.logger = noOpLogger;
112112
} else {
113113
const baseLogger = options.logger || makeConsoleLogger("messari-client");
114-
this.logger = options.logLevel ? createFilteredLogger(baseLogger, options.logLevel) : createFilteredLogger(baseLogger, LogLevel.INFO);
114+
this.logger = createFilteredLogger(baseLogger, options.logLevel ?? LogLevel.INFO);
115115
}
116116

117117
this.defaultHeaders = {

packages/api/src/logging.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ export const createFilteredLogger = (logger: Logger, minLevel: LogLevel): Logger
6868
};
6969

7070
/**
71-
* Creates a logger that does nothing (no-op).
71+
* Returns a logger that does nothing (no-op).
7272
* Use this when you want to completely disable logging.
7373
* @returns A no-op logger.
7474
*/
75-
export const makeNoOpLogger: Logger = () => {};
75+
export const noOpLogger: Logger = () => {};

0 commit comments

Comments
 (0)