-
Notifications
You must be signed in to change notification settings - Fork 25
Add PR validation workflow #26
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [ "main" ] | ||
| push: | ||
| branches: [ "main" ] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| cli: | ||
| name: CLI build and test | ||
| runs-on: ubuntu-latest | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: cli | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22.x | ||
| cache: npm | ||
| cache-dependency-path: cli/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Build | ||
| run: npm run build | ||
|
|
||
| - name: Test | ||
| run: npm test | ||
|
|
||
| - name: Smoke test CLI commands with cached fixture | ||
| run: npm run smoke:fixture | ||
|
|
||
| - name: Smoke test live catalog | ||
| if: github.event_name != 'pull_request' | ||
| run: npm run smoke:live | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import { execFile } from 'node:child_process'; | ||
| import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { promisify } from 'node:util'; | ||
| import { normalizeCatalog } from '../dist/data/normalize.js'; | ||
|
|
||
| const execFileAsync = promisify(execFile); | ||
| const cliRoot = fileURLToPath(new URL('..', import.meta.url)); | ||
| const commandTimeoutMs = 60_000; | ||
| const eventId = 'build-2025'; | ||
|
|
||
| function assert(condition, message) { | ||
| if (!condition) throw new Error(message); | ||
| } | ||
|
|
||
| async function runCli(args, cacheDir) { | ||
| return execFileAsync(process.execPath, ['dist/index.js', ...args], { | ||
| cwd: cliRoot, | ||
| env: { ...process.env, MSEVENTS_CACHE_DIR: cacheDir }, | ||
| timeout: commandTimeoutMs, | ||
| }); | ||
|
TianqiZhang marked this conversation as resolved.
|
||
| } | ||
|
|
||
| const cacheDir = await mkdtemp(join(tmpdir(), 'msevents-fixture-smoke-')); | ||
|
|
||
| try { | ||
| const raw = JSON.parse(await readFile('test/fixtures/build-2025-sample.json', 'utf8')); | ||
| const sessions = normalizeCatalog(raw, eventId); | ||
| assert(sessions.length > 0, 'Expected fixture to contain sessions'); | ||
|
|
||
| await mkdir(cacheDir, { recursive: true }); | ||
| await writeFile(join(cacheDir, `${eventId}-sessions.json`), JSON.stringify(sessions)); | ||
| await writeFile(join(cacheDir, `${eventId}-meta.json`), JSON.stringify({ | ||
| eventId, | ||
| fetchedAt: '2026-01-01T00:00:00.000Z', | ||
| checkedAt: '2026-01-01T00:00:00.000Z', | ||
| nextCheckAt: '2099-01-01T00:00:00.000Z', | ||
| sessionCount: sessions.length, | ||
| lastCheckStatus: 'updated', | ||
| consecutiveFailures: 0, | ||
| }, null, 2)); | ||
|
|
||
| await runCli(['--help'], cacheDir); | ||
|
|
||
| const { stdout: searchStdout } = await runCli([ | ||
| 'sessions', | ||
| '--query', | ||
| 'Foundry', | ||
| '--event', | ||
| eventId, | ||
| '--limit', | ||
| '1', | ||
| '--json', | ||
| ], cacheDir); | ||
| const results = JSON.parse(searchStdout); | ||
| assert(Array.isArray(results), 'Expected search output to be an array'); | ||
| assert(results.length === 1, `Expected one search result, got ${results.length}`); | ||
| assert(results[0].event === eventId, `Expected ${eventId} search result, got ${results[0].event}`); | ||
|
|
||
| const sessionCode = sessions.find((session) => session.sessionCode)?.sessionCode; | ||
| assert(sessionCode, 'No cached session code found'); | ||
|
|
||
| const { stdout: sessionStdout } = await runCli([ | ||
| 'session', | ||
| sessionCode, | ||
| '--event', | ||
| eventId, | ||
| '--json', | ||
| ], cacheDir); | ||
| const session = JSON.parse(sessionStdout); | ||
| assert(!Array.isArray(session), `Expected one session for ${sessionCode}`); | ||
| assert(session.sessionCode === sessionCode, `Expected session ${sessionCode}, got ${session.sessionCode}`); | ||
| assert(session.event === eventId, `Expected ${eventId} session, got ${session.event}`); | ||
| } finally { | ||
| await rm(cacheDir, { recursive: true, force: true }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { execFile } from 'node:child_process'; | ||
| import { mkdtemp, readFile, rm } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| const execFileAsync = promisify(execFile); | ||
| const cliRoot = fileURLToPath(new URL('..', import.meta.url)); | ||
| const commandTimeoutMs = 60_000; | ||
| const liveRefreshAttempts = 3; | ||
| const liveRefreshRetryDelayMs = 5_000; | ||
| const eventId = 'build-2026'; | ||
|
|
||
| function assert(condition, message) { | ||
| if (!condition) throw new Error(message); | ||
| } | ||
|
|
||
| async function runCli(args, cacheDir) { | ||
| return execFileAsync(process.execPath, ['dist/index.js', ...args], { | ||
| cwd: cliRoot, | ||
| env: { ...process.env, MSEVENTS_CACHE_DIR: cacheDir }, | ||
| timeout: commandTimeoutMs, | ||
| }); | ||
|
TianqiZhang marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function formatError(error) { | ||
| if (error && typeof error === 'object') { | ||
| const message = error.message ?? String(error); | ||
| const stderr = error.stderr ? `\n${error.stderr}` : ''; | ||
| return `${message}${stderr}`; | ||
| } | ||
| return String(error); | ||
| } | ||
|
|
||
| async function delay(ms) { | ||
| await new Promise((resolve) => { | ||
| setTimeout(resolve, ms); | ||
| }); | ||
| } | ||
|
|
||
| async function retryLiveRefresh(cacheDir) { | ||
| let lastError; | ||
| for (let attempt = 1; attempt <= liveRefreshAttempts; attempt += 1) { | ||
| try { | ||
| return await runCli(['refresh', '--event', eventId, '--force'], cacheDir); | ||
| } catch (error) { | ||
| lastError = error; | ||
| if (attempt === liveRefreshAttempts) break; | ||
| process.stderr.write( | ||
| `Live catalog refresh failed on attempt ${attempt}/${liveRefreshAttempts}: ${formatError(error)}\n` + | ||
| `Retrying in ${liveRefreshRetryDelayMs / 1000}s...\n`, | ||
| ); | ||
| await delay(liveRefreshRetryDelayMs); | ||
| } | ||
| } | ||
|
|
||
| throw lastError; | ||
| } | ||
|
|
||
| const cacheDir = await mkdtemp(join(tmpdir(), 'msevents-live-smoke-')); | ||
|
|
||
| try { | ||
| const refresh = await retryLiveRefresh(cacheDir); | ||
| process.stderr.write(refresh.stderr); | ||
|
|
||
| const { stdout: statusStdout } = await runCli(['status', '--json'], cacheDir); | ||
| const statuses = JSON.parse(statusStdout); | ||
| const status = statuses.find((item) => item.eventId === eventId); | ||
| assert(status?.meta?.sessionCount > 0, `Expected ${eventId} live catalog cache with sessions`); | ||
|
|
||
| const sessions = JSON.parse(await readFile(join(cacheDir, `${eventId}-sessions.json`), 'utf8')); | ||
| const sessionCode = sessions.find((session) => session.sessionCode)?.sessionCode; | ||
| assert(sessionCode, 'No live session code found'); | ||
|
|
||
| const { stdout: searchStdout } = await runCli([ | ||
| 'sessions', | ||
| '--query', | ||
| sessionCode, | ||
| '--event', | ||
| eventId, | ||
| '--limit', | ||
| '1', | ||
| '--json', | ||
| ], cacheDir); | ||
| const results = JSON.parse(searchStdout); | ||
| assert( | ||
| Array.isArray(results) | ||
| && results.some((session) => session.sessionCode === sessionCode && session.event === eventId), | ||
| `Expected ${eventId} search result for ${sessionCode}`, | ||
| ); | ||
|
|
||
| const { stdout: sessionStdout } = await runCli([ | ||
| 'session', | ||
| sessionCode, | ||
| '--event', | ||
| eventId, | ||
| '--json', | ||
| ], cacheDir); | ||
| const session = JSON.parse(sessionStdout); | ||
| assert(!Array.isArray(session), `Expected one session for ${sessionCode}`); | ||
| assert(session.sessionCode === sessionCode, `Expected session ${sessionCode}, got ${session.sessionCode}`); | ||
| assert(session.event === eventId, `Expected ${eventId} session, got ${session.event}`); | ||
| } finally { | ||
| await rm(cacheDir, { recursive: true, force: true }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.