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

gh-action-test #5

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9bc3ab2
Add GitHub Actions workflow for linting.
junhaoliao Aug 28, 2024
a0065e3
gh-action-test: violation 1.
junhaoliao Aug 29, 2024
44082e7
gh-action-test: violation 2.
junhaoliao Aug 29, 2024
15c4c96
gh-action-test: violation 3.
junhaoliao Aug 29, 2024
78b0d0c
gh-action-test: violation 4.
junhaoliao Aug 29, 2024
43108c8
Use ataylorme/eslint-annotate-action@v3 for lint annotation instead.
junhaoliao Aug 31, 2024
5f31719
Merge branch 'main' into gh-action-test
junhaoliao Aug 31, 2024
8731db7
continue-on-error on eslint report
junhaoliao Aug 31, 2024
d488099
Merge branch 'main' into gh-action-test
junhaoliao Aug 31, 2024
9b3e77c
Use ataylorme/eslint-annotate-action@v3 for lint annotation instead.
junhaoliao Aug 31, 2024
a8cada1
continue-on-error on eslint report
junhaoliao Aug 31, 2024
15c635c
Apply suggestions from code review
junhaoliao Aug 31, 2024
26556bd
Merge branch 'gh-action'
junhaoliao Aug 31, 2024
a342e1e
Remove permissions contents: "read" and pull-requests: "write".
junhaoliao Aug 31, 2024
a32c35a
Merge branch 'main' into gh-action-test
junhaoliao Aug 31, 2024
1b9f3e9
Add back permissions contents: "read".
junhaoliao Aug 31, 2024
8081398
Add checks: "write" permission.
junhaoliao Aug 31, 2024
8a0e445
Merge branch 'main' into gh-action-test
junhaoliao Aug 31, 2024
1c81b9d
Pull out workerPostReq() from <StateContextProvider/> FC body.
junhaoliao Aug 31, 2024
5fd8fc7
Suppress warnings for long-term TODO comments.
junhaoliao Aug 31, 2024
26cc596
Output eslint report as `eslint-report.json` instead of `eslint_repor…
junhaoliao Sep 2, 2024
347b421
Move 'checks: "write"' and 'contents: "read"' permissions to the job …
junhaoliao Sep 2, 2024
8219025
Merge branch 'gh-action' into gh-action-test
junhaoliao Sep 2, 2024
0726e59
make violation
junhaoliao Sep 2, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "lint"

on:
pull_request:
types: ["opened", "reopened"]
push:
schedule:
# Run at midnight UTC every day with 15 minutes delay added to avoid high load periods
- cron: "15 0 * * *"
workflow_dispatch:

permissions:
# So the workflow can cancel in-progress jobs
actions: "write"

concurrency:
group: "${{github.workflow}}-${{github.ref}}"
# Cancel in-progress jobs for efficiency
cancel-in-progress: true

jobs:
lint-check:
runs-on: "ubuntu-latest"
permissions:
# So `eslint-annotate-action` can create / update status checks
checks: "write"
# So `eslint-annotate-action` can get pull request files
contents: "read"
steps:
- uses: "actions/checkout@v4"
with:
submodules: "recursive"
- uses: "actions/setup-node@v4"
with:
node-version: 22
- run: "npm --prefix new-log-viewer/ clean-install"
- run: "npm --prefix new-log-viewer/ run lint:ci"
continue-on-error: true
- uses: "ataylorme/eslint-annotate-action@v3"
with:
fail-on-error: true
fail-on-warning: true
only-pr-files: true
report-json: "./new-log-viewer/eslint-report.json"
4 changes: 4 additions & 0 deletions new-log-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"main": "src/index.tsx",
"scripts": {
"build": "webpack --config webpack.prod.js",
"lint": "npm run lint:check",
"lint:ci": "npm run lint:check -- --output-file eslint-report.json --format json",
"lint:check": "eslint src webpack.*.js",
"lint:fix": "npm run lint:check -- --fix",
"start": "webpack serve --open --config webpack.dev.js"
},
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions new-log-viewer/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import UrlContextProvider from "./contexts/UrlContextProvider";


// TODO: violation 1

Check warning on line 6 in new-log-viewer/src/App.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/App.tsx#L6

[no-warning-comments] Unexpected 'todo' comment: 'TODO: violation 1'.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected 'todo' comment: 'TODO: violation 1'. no-warning-comments


/**
* Renders the main application.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const createMonacoEditor = (
const editor = monaco.editor.create(
editorContainer,
{
// eslint-disable-next-line no-warning-comments
// TODO: Add custom observer to debounce automatic layout
automaticLayout: true,
maxTokenizationLineLength: 30_000,
Expand Down
1 change: 1 addition & 0 deletions new-log-viewer/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
getLastItemNumInPrevChunk,
} from "../utils/math";
import Editor from "./Editor";
import {goToPositionAndCenter} from "./Editor/MonacoInstance/utils";

Check failure on line 32 in new-log-viewer/src/components/Layout.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/components/Layout.tsx#L32

[import/newline-after-import] Expected 2 empty lines after import statement not followed by another import.

// TODO: violation

Check warning on line 34 in new-log-viewer/src/components/Layout.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/components/Layout.tsx#L34

[no-warning-comments] Unexpected 'todo' comment: 'TODO: violation'.

const formFields = [
{
Expand Down
33 changes: 21 additions & 12 deletions new-log-viewer/src/contexts/StateContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ const getLastLogEventNum = (beginLineNumToLogEventNum: BeginLineNumToLogEventNum
return lastLogEventNum;
};

/**
* Sends a post message to a worker with the given code and arguments. This wrapper around
* `worker.postMessage()` ensures type safety for both the request code and its corresponding
* arguments.
*
* @param worker
* @param code
* @param args
*/
const workerPostReq = <T extends WORKER_REQ_CODE>(
worker: Worker,
code: T,
args: WorkerReq<T>
) => {
worker.postMessage({code, args});
};

/**
* Provides state management for the application. This provider must be wrapped by
* UrlContextProvider to function correctly.
Expand All @@ -116,13 +133,6 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {

const mainWorkerRef = useRef<null|Worker>(null);

const mainWorkerPostReq = useCallback(<T extends WORKER_REQ_CODE>(
code: T,
args: WorkerReq<T>
) => {
mainWorkerRef.current?.postMessage({code, args});
}, []);

const handleMainWorkerResp = useCallback((ev: MessageEvent<MainWorkerRespMessage>) => {
const {code, args} = ev.data;
console.log(`[MainWorker -> Renderer] code=${code}`);
Expand All @@ -138,6 +148,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
setNumEvents(args.numEvents);
break;
case WORKER_RESP_CODE.NOTIFICATION:
// eslint-disable-next-line no-warning-comments
// TODO: notifications should be shown in the UI when the NotificationProvider
// is added
console.error(args.logLevel, args.message);
Expand All @@ -156,15 +167,14 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
new URL("../services/MainWorker.ts", import.meta.url)
);
mainWorkerRef.current.onmessage = handleMainWorkerResp;
mainWorkerPostReq(WORKER_REQ_CODE.LOAD_FILE, {
workerPostReq(mainWorkerRef.current, WORKER_REQ_CODE.LOAD_FILE, {
fileSrc: fileSrc,
pageSize: getConfig(CONFIG_KEY.PAGE_SIZE),
cursor: cursor,
decoderOptions: getConfig(CONFIG_KEY.DECODER_OPTIONS),
});
}, [
handleMainWorkerResp,
mainWorkerPostReq,
]);

// Synchronize `logEventNumRef` with `logEventNum`.
Expand All @@ -183,7 +193,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {

// On `logEventNum` update, clamp it then switch page if necessary or simply update the URL.
useEffect(() => {
if (URL_HASH_PARAMS_DEFAULT.logEventNum === logEventNum) {
if (null === mainWorkerRef.current || URL_HASH_PARAMS_DEFAULT.logEventNum === logEventNum) {
return;
}

Expand All @@ -202,7 +212,7 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
// NOTE: We don't need to call `updateLogEventNumInUrl()` since it's called when
// handling the `WORKER_RESP_CODE.PAGE_DATA` response (the response to
// `WORKER_REQ_CODE.LOAD_PAGE` requests) .
mainWorkerPostReq(WORKER_REQ_CODE.LOAD_PAGE, {
workerPostReq(mainWorkerRef.current, WORKER_REQ_CODE.LOAD_PAGE, {
cursor: {code: CURSOR_CODE.PAGE_NUM, args: {pageNum: newPageNum}},
decoderOptions: getConfig(CONFIG_KEY.DECODER_OPTIONS),
});
Expand All @@ -213,7 +223,6 @@ const StateContextProvider = ({children}: StateContextProviderProps) => {
}, [
numEvents,
logEventNum,
mainWorkerPostReq,
]);

// On `filePath` update, load file.
Expand Down
2 changes: 2 additions & 0 deletions new-log-viewer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import "./index.css";


// TODO: violation 2

Check warning on line 9 in new-log-viewer/src/index.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/index.tsx#L9

[no-warning-comments] Unexpected 'todo' comment: 'TODO: violation 2'.

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const root = createRoot(document.getElementById("root")!);
root.render(
Expand Down
3 changes: 3 additions & 0 deletions new-log-viewer/src/services/LogFileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import JsonlDecoder from "./decoders/JsonlDecoder";


// TODO: violation 4 - this should interrupt the check for violation 3

Check warning on line 19 in new-log-viewer/src/services/LogFileManager.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/services/LogFileManager.ts#L19

[no-warning-comments] Unexpected 'todo' comment: 'TODO: violation 4 - this should...'.

/**
* Loads a file from a given source.
*
Expand All @@ -32,6 +34,7 @@
fileName = getBasenameFromUrlOrDefault(fileSrc);
fileData = await getUint8ArrayFrom(fileSrc, () => null);
} else {
// eslint-disable-next-line no-warning-comments
// TODO: support file loading via Open / Drag-n-drop
throw new Error("Read from file not yet supported");
}
Expand Down
3 changes: 3 additions & 0 deletions new-log-viewer/src/services/MainWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import LogFileManager from "./LogFileManager";


// TODO: violation 3 - i will push another one soon so the check for this commit would not finish

Check warning on line 15 in new-log-viewer/src/services/MainWorker.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

new-log-viewer/src/services/MainWorker.ts#L15

[no-warning-comments] Unexpected 'todo' comment: 'TODO: violation 3 - i will push another...'.


/* eslint-disable import/no-named-as-default-member */
dayjs.extend(dayjsUtc);
dayjs.extend(dayjsTimezone);
Expand Down
1 change: 1 addition & 0 deletions new-log-viewer/src/services/decoders/JsonlDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class JsonlDecoder implements Decoder {
return null;
}

// eslint-disable-next-line no-warning-comments
// TODO We could probably optimize this to avoid checking `#invalidLogEventIdxToRawLine` on
// every iteration.
const results: DecodeResultType[] = [];
Expand Down
1 change: 1 addition & 0 deletions new-log-viewer/src/services/formatters/LogbackFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class LogbackFormatter implements Formatter {
* @return The formatted string.
*/
#formatVariables (formatString: string, logEvent: JsonObject): string {
// eslint-disable-next-line no-warning-comments
// TODO These don't handle the case where a variable value may contain a '%' itself
for (const key of this.#keys) {
if (false === (key in logEvent)) {
Expand Down
Loading