@verekia/warden 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verekia/warden",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Linter that checks repositories share consistent configs and tool versions.",
5
5
  "bin": {
6
6
  "warden": "./src/index.ts"
@@ -41,8 +41,7 @@
41
41
  "enabled": true,
42
42
  "files": [
43
43
  ".oxfmtrc.json",
44
- ".oxlintrc.json",
45
- ".github/workflows/ci.yml"
44
+ ".oxlintrc.json"
46
45
  ]
47
46
  },
48
47
  "matchingDependencyVersions": {
@@ -102,6 +101,11 @@
102
101
  "wardenScript": {
103
102
  "enabled": true,
104
103
  "package": "@verekia/warden"
104
+ },
105
+ "ciWorkflow": {
106
+ "enabled": true,
107
+ "file": ".github/workflows/ci.yml",
108
+ "runs": "bun run all"
105
109
  }
106
110
  }
107
111
  }
@@ -0,0 +1,58 @@
1
+ import type { CheckResult, Project, WardenConfig } from '../types.ts'
2
+
3
+ type Step = { run?: unknown }
4
+ type Job = { steps?: unknown }
5
+ type Workflow = { jobs?: Record<string, unknown> }
6
+
7
+ const DEFAULT_FILE = '.github/workflows/ci.yml'
8
+ const DEFAULT_RUNS = 'bun run all'
9
+
10
+ const collectRunCommands = (workflow: Workflow): string[] => {
11
+ const commands: string[] = []
12
+ for (const job of Object.values(workflow.jobs ?? {})) {
13
+ const steps = (job as Job)?.steps
14
+ if (!Array.isArray(steps)) continue
15
+ for (const step of steps as Step[]) {
16
+ if (typeof step?.run === 'string') commands.push(step.run)
17
+ }
18
+ }
19
+ return commands
20
+ }
21
+
22
+ export const ciWorkflow = async (
23
+ projects: Project[],
24
+ options: NonNullable<NonNullable<WardenConfig['checks']>['ciWorkflow']>,
25
+ ): Promise<CheckResult> => {
26
+ const messages: string[] = []
27
+ let passed = true
28
+
29
+ const file = options.file ?? DEFAULT_FILE
30
+ const runs = options.runs ?? DEFAULT_RUNS
31
+
32
+ for (const project of projects) {
33
+ const handle = Bun.file(`${project.path}/${file}`)
34
+ if (!(await handle.exists())) {
35
+ passed = false
36
+ messages.push(`${project.name}: missing ${file}`)
37
+ continue
38
+ }
39
+ if (!runs) continue
40
+
41
+ let workflow: Workflow
42
+ try {
43
+ workflow = Bun.YAML.parse(await handle.text()) as Workflow
44
+ } catch (err) {
45
+ passed = false
46
+ messages.push(`${project.name}: ${file} is not valid YAML (${(err as Error).message})`)
47
+ continue
48
+ }
49
+
50
+ const commands = collectRunCommands(workflow)
51
+ if (!commands.some(cmd => cmd.includes(runs))) {
52
+ passed = false
53
+ messages.push(`${project.name}: ${file} has no step running ${JSON.stringify(runs)}`)
54
+ }
55
+ }
56
+
57
+ return { name: 'ciWorkflow', passed, messages }
58
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  import { existsSync } from 'node:fs'
3
3
 
4
+ import { ciWorkflow } from './checks/ci-workflow.ts'
4
5
  import { configFilesPresent } from './checks/config-files-present.ts'
5
6
  import { exactDependencyVersions } from './checks/exact-dependency-versions.ts'
6
7
  import { matchingDependencyVersions } from './checks/matching-dependency-versions.ts'
@@ -79,6 +80,9 @@ if (enabled(checks.nextConfig)) {
79
80
  if (enabled(checks.wardenScript)) {
80
81
  results.push(wardenScript(projects, checks.wardenScript ?? {}))
81
82
  }
83
+ if (enabled(checks.ciWorkflow)) {
84
+ results.push(await ciWorkflow(projects, checks.ciWorkflow ?? {}))
85
+ }
82
86
 
83
87
  for (const result of results) {
84
88
  const tag = result.passed ? '[PASS]' : '[FAIL]'
package/src/types.ts CHANGED
@@ -21,6 +21,7 @@ export type WardenConfig = {
21
21
  devDependencies?: Record<string, string>
22
22
  }
23
23
  wardenScript?: { enabled?: boolean; package?: string }
24
+ ciWorkflow?: { enabled?: boolean; file?: string; runs?: string }
24
25
  }
25
26
  }
26
27