@rahul05ranjan/dhruv-cli 1.2.4 → 1.4.6

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.
Files changed (103) hide show
  1. package/.github/ENTERPRISE.md +275 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.md +45 -17
  3. package/.github/ISSUE_TEMPLATE/documentation_issue.md +61 -0
  4. package/.github/ISSUE_TEMPLATE/feature_request.md +61 -9
  5. package/.github/ISSUE_TEMPLATE/security_vulnerability.md +74 -0
  6. package/.github/dependabot.yml +42 -2
  7. package/.github/pull_request_template.md +13 -0
  8. package/.github/workflows/build-publish.yml +154 -0
  9. package/.github/workflows/ci.yml +251 -18
  10. package/.github/workflows/contribution.yml +169 -27
  11. package/.github/workflows/dependabot-auto-merge.yml +61 -2
  12. package/.github/workflows/deploy.yml +336 -0
  13. package/.github/workflows/monitoring.yml +270 -0
  14. package/.github/workflows/release.yml +229 -0
  15. package/.github/workflows/security.yml +198 -0
  16. package/.releaserc.json +50 -0
  17. package/AGENTS.md +13 -0
  18. package/CHANGELOG.md +8 -0
  19. package/PUBLISHING_FIX.md +92 -0
  20. package/__tests__/core.test.ts +318 -0
  21. package/__tests__/setup.ts +61 -0
  22. package/__tests__/workflows.test.ts +95 -0
  23. package/dist/commands/explain.js +13 -44
  24. package/dist/commands/fix.js +13 -38
  25. package/dist/commands/generate.js +45 -54
  26. package/dist/commands/health.d.ts +1 -0
  27. package/dist/commands/health.js +376 -0
  28. package/dist/commands/init.js +47 -42
  29. package/dist/commands/menu.js +90 -2
  30. package/dist/commands/metrics.d.ts +1 -0
  31. package/dist/commands/metrics.js +51 -0
  32. package/dist/commands/optimize.js +42 -34
  33. package/dist/commands/review.js +52 -48
  34. package/dist/commands/security-check.js +52 -42
  35. package/dist/commands/status.d.ts +1 -0
  36. package/dist/commands/status.js +45 -0
  37. package/dist/commands/suggest.js +13 -39
  38. package/dist/config/config.js +30 -2
  39. package/dist/core/ai.d.ts +77 -2
  40. package/dist/core/ai.js +207 -30
  41. package/dist/core/command-runner.d.ts +17 -0
  42. package/dist/core/command-runner.js +78 -0
  43. package/dist/core/logger.d.ts +40 -0
  44. package/dist/core/logger.js +138 -0
  45. package/dist/core/metrics.d.ts +34 -0
  46. package/dist/core/metrics.js +206 -0
  47. package/dist/core/prompts.d.ts +1 -0
  48. package/dist/core/prompts.js +121 -0
  49. package/dist/core/security.d.ts +34 -0
  50. package/dist/core/security.js +197 -0
  51. package/dist/index.js +40 -2
  52. package/dist/utils/ux.d.ts +3 -0
  53. package/dist/utils/ux.js +15 -0
  54. package/docs/agents/domain.md +51 -0
  55. package/docs/agents/issue-tracker.md +45 -0
  56. package/docs/agents/triage-labels.md +15 -0
  57. package/docs/api/.nojekyll +1 -0
  58. package/docs/api/assets/hierarchy.js +1 -0
  59. package/docs/api/assets/highlight.css +71 -0
  60. package/docs/api/assets/icons.js +18 -0
  61. package/docs/api/assets/icons.svg +1 -0
  62. package/docs/api/assets/main.js +60 -0
  63. package/docs/api/assets/navigation.js +1 -0
  64. package/docs/api/assets/search.js +1 -0
  65. package/docs/api/assets/style.css +1633 -0
  66. package/docs/api/hierarchy.html +1 -0
  67. package/docs/api/index.html +39 -0
  68. package/docs/api/modules.html +1 -0
  69. package/eslint.config.js +170 -0
  70. package/jest.config.json +37 -0
  71. package/lighthouserc.json +22 -0
  72. package/logs/.8a99b6cf655346317fdbf29f4fffcf91131432f3-audit.json +15 -0
  73. package/logs/.eee104bf8fff5ecd38a6a2842df260de6470a7c3-audit.json +15 -0
  74. package/package.json +62 -8
  75. package/src/commands/explain.ts +13 -42
  76. package/src/commands/fix.ts +13 -31
  77. package/src/commands/generate.ts +47 -46
  78. package/src/commands/health.ts +440 -0
  79. package/src/commands/init.ts +48 -42
  80. package/src/commands/menu.ts +86 -2
  81. package/src/commands/metrics.ts +65 -0
  82. package/src/commands/optimize.ts +40 -28
  83. package/src/commands/review.ts +54 -40
  84. package/src/commands/security-check.ts +54 -34
  85. package/src/commands/status.ts +47 -0
  86. package/src/commands/suggest.ts +13 -32
  87. package/src/config/config.ts +35 -2
  88. package/src/core/ai.ts +237 -26
  89. package/src/core/command-runner.ts +105 -0
  90. package/src/core/logger.ts +194 -0
  91. package/src/core/metrics.ts +232 -0
  92. package/src/core/prompts.ts +128 -0
  93. package/src/core/security.ts +243 -0
  94. package/src/index.ts +47 -2
  95. package/src/utils/ux.ts +18 -0
  96. package/test-suite.sh +147 -0
  97. package/tsconfig.json +3 -2
  98. package/typedoc.json +44 -0
  99. package/types/global.d.ts +13 -0
  100. package/validate-workflows.sh +270 -0
  101. package/.eslintignore +0 -1
  102. package/.eslintrc.cjs +0 -43
  103. package/src/core/ai.test.js +0 -40
@@ -6,14 +6,73 @@ on:
6
6
  - opened
7
7
  - synchronize
8
8
  - reopened
9
+ - ready_for_review
10
+
11
+ permissions:
12
+ contents: write
13
+ pull-requests: write
14
+ checks: read
9
15
 
10
16
  jobs:
17
+ auto-approve:
18
+ name: Auto Approve Dependabot PRs
19
+ if: github.actor == 'dependabot[bot]' && github.event.pull_request.draft == false
20
+ runs-on: ubuntu-latest
21
+ timeout-minutes: 5
22
+ steps:
23
+ - name: Harden Runner
24
+ uses: step-security/harden-runner@v2
25
+ with:
26
+ egress-policy: audit
27
+
28
+ - name: Approve Dependabot PRs
29
+ uses: hmarr/auto-approve-action@v4
30
+ with:
31
+ github-token: ${{ secrets.GITHUB_TOKEN }}
32
+
11
33
  auto-merge:
12
- if: github.actor == 'dependabot[bot]'
34
+ name: Auto Merge Dependabot PRs
35
+ needs: auto-approve
36
+ if: github.actor == 'dependabot[bot]' && github.event.pull_request.draft == false
13
37
  runs-on: ubuntu-latest
38
+ timeout-minutes: 10
14
39
  steps:
15
- - name: Enable auto-merge for Dependabot PRs
40
+ - name: Harden Runner
41
+ uses: step-security/harden-runner@v2
42
+ with:
43
+ egress-policy: audit
44
+
45
+ - name: Get Dependabot metadata
46
+ id: metadata
47
+ uses: dependabot/fetch-metadata@v1
48
+ with:
49
+ github-token: ${{ secrets.GITHUB_TOKEN }}
50
+
51
+ - name: Enable auto-merge for patch updates
52
+ if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
16
53
  uses: peter-evans/enable-pull-request-automerge@v3
17
54
  with:
18
55
  token: ${{ secrets.GITHUB_TOKEN }}
19
56
  merge-method: squash
57
+
58
+ - name: Enable auto-merge for minor updates
59
+ if: steps.metadata.outputs.update-type == 'version-update:semver-minor' && contains(steps.metadata.outputs.dependency-names, '@types/')
60
+ uses: peter-evans/enable-pull-request-automerge@v3
61
+ with:
62
+ token: ${{ secrets.GITHUB_TOKEN }}
63
+ merge-method: squash
64
+
65
+ - name: Comment on major updates
66
+ if: steps.metadata.outputs.update-type == 'version-update:semver-major'
67
+ uses: peter-evans/create-or-update-comment@v4
68
+ with:
69
+ issue-number: ${{ github.event.pull_request.number }}
70
+ body: |
71
+ 🚨 **Major Version Update Detected**
72
+
73
+ This PR updates a dependency to a new major version. Please review the changelog and test thoroughly before merging.
74
+
75
+ **Dependency:** ${{ steps.metadata.outputs.dependency-names }}
76
+ **Update Type:** ${{ steps.metadata.outputs.update-type }}
77
+
78
+ This PR will not be auto-merged and requires manual review.
@@ -0,0 +1,336 @@
1
+ name: Deployment Pipeline
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+ inputs:
8
+ environment:
9
+ description: 'Deployment environment'
10
+ required: true
11
+ default: 'staging'
12
+ type: choice
13
+ options:
14
+ - staging
15
+ - production
16
+ version:
17
+ description: 'Version to deploy (leave empty for latest)'
18
+ required: false
19
+ type: string
20
+
21
+ permissions:
22
+ contents: read
23
+ packages: write
24
+ deployments: write
25
+ id-token: write
26
+
27
+ env:
28
+ NODE_VERSION: '22.14.0'
29
+ REGISTRY_URL: 'https://registry.npmjs.org'
30
+
31
+ jobs:
32
+ pre-deployment:
33
+ name: Pre-deployment Checks
34
+ runs-on: ubuntu-latest
35
+ timeout-minutes: 15
36
+ outputs:
37
+ version: ${{ steps.version.outputs.version }}
38
+ environment: ${{ steps.environment.outputs.environment }}
39
+ steps:
40
+ - name: Harden Runner
41
+ uses: step-security/harden-runner@v2
42
+ with:
43
+ egress-policy: audit
44
+
45
+ - uses: actions/checkout@v4
46
+
47
+ - name: Determine version
48
+ id: version
49
+ run: |
50
+ if [[ "${{ github.event_name }}" == "release" ]]; then
51
+ VERSION="${{ github.event.release.tag_name }}"
52
+ elif [[ -n "${{ github.event.inputs.version }}" ]]; then
53
+ VERSION="${{ github.event.inputs.version }}"
54
+ else
55
+ VERSION=$(cat package.json | jq -r '.version')
56
+ fi
57
+ echo "version=${VERSION}" >> $GITHUB_OUTPUT
58
+ echo "Deploying version: ${VERSION}"
59
+
60
+ - name: Determine environment
61
+ id: environment
62
+ run: |
63
+ if [[ "${{ github.event_name }}" == "release" ]]; then
64
+ if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then
65
+ ENVIRONMENT="staging"
66
+ else
67
+ ENVIRONMENT="production"
68
+ fi
69
+ else
70
+ ENVIRONMENT="${{ github.event.inputs.environment }}"
71
+ fi
72
+ echo "environment=${ENVIRONMENT}" >> $GITHUB_OUTPUT
73
+ echo "Deploying to environment: ${ENVIRONMENT}"
74
+
75
+ - name: Set up Node.js
76
+ uses: actions/setup-node@v4
77
+ with:
78
+ node-version: ${{ env.NODE_VERSION }}
79
+ cache: 'npm'
80
+ registry-url: ${{ env.REGISTRY_URL }}
81
+
82
+ - name: Install dependencies
83
+ run: npm ci --prefer-offline --no-audit
84
+
85
+ - name: Run comprehensive tests
86
+ run: |
87
+ npm run test:ci
88
+ npm run lint
89
+ npm run build
90
+
91
+ - name: Security scan
92
+ run: npm audit --audit-level=moderate
93
+
94
+ - name: Package validation
95
+ run: |
96
+ npm pack --dry-run
97
+ echo "Package size check..."
98
+ npm pack
99
+ ls -lah *.tgz
100
+
101
+ deploy-staging:
102
+ name: Deploy to Staging
103
+ runs-on: ubuntu-latest
104
+ needs: pre-deployment
105
+ if: needs.pre-deployment.outputs.environment == 'staging' || (github.event_name == 'release' && github.event.release.prerelease)
106
+ timeout-minutes: 20
107
+ environment:
108
+ name: staging
109
+ url: https://staging.example.com
110
+ steps:
111
+ - name: Harden Runner
112
+ uses: step-security/harden-runner@v2
113
+ with:
114
+ egress-policy: audit
115
+
116
+ - uses: actions/checkout@v4
117
+
118
+ - name: Set up Node.js
119
+ uses: actions/setup-node@v4
120
+ with:
121
+ node-version: ${{ env.NODE_VERSION }}
122
+ cache: 'npm'
123
+ registry-url: ${{ env.REGISTRY_URL }}
124
+
125
+ - name: Install dependencies
126
+ run: npm ci --prefer-offline --no-audit
127
+
128
+ - name: Install npm with trusted publishing support
129
+ run: npm install --global npm@11.17.0
130
+
131
+ - name: Build for staging
132
+ run: |
133
+ NODE_ENV=staging npm run build
134
+ npm run docs
135
+
136
+ - name: Deploy to staging NPM registry
137
+ if: github.event_name == 'release' && github.event.release.prerelease
138
+ # npm 11.5.1+ authenticates using the workflow's OIDC identity.
139
+ run: npm publish --tag beta --access public --provenance
140
+
141
+ - name: Deploy documentation to staging
142
+ uses: peaceiris/actions-gh-pages@v4
143
+ with:
144
+ github_token: ${{ secrets.GITHUB_TOKEN }}
145
+ publish_dir: ./docs
146
+ publish_branch: gh-pages-staging
147
+ destination_dir: staging
148
+
149
+ - name: Staging health check
150
+ run: |
151
+ echo "Running staging health checks..."
152
+ # Add your staging health check commands here
153
+ curl -f https://staging.example.com/health || echo "Health check failed"
154
+
155
+ - name: Notify staging deployment
156
+ uses: 8398a7/action-slack@v3
157
+ if: always()
158
+ continue-on-error: true
159
+ with:
160
+ status: ${{ job.status }}
161
+ channel: '#deployments'
162
+ text: |
163
+ 🚀 Staging Deployment ${{ job.status }}
164
+
165
+ **Version:** ${{ needs.pre-deployment.outputs.version }}
166
+ **Branch:** ${{ github.ref_name }}
167
+ **Commit:** ${{ github.sha }}
168
+ env:
169
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
170
+
171
+ deploy-production:
172
+ name: Deploy to Production
173
+ runs-on: ubuntu-latest
174
+ needs: [pre-deployment, deploy-staging]
175
+ if: needs.pre-deployment.outputs.environment == 'production' && (github.event_name == 'release' && !github.event.release.prerelease)
176
+ timeout-minutes: 30
177
+ environment:
178
+ name: production
179
+ url: https://www.npmjs.com/package/dhruv-cli
180
+ steps:
181
+ - name: Harden Runner
182
+ uses: step-security/harden-runner@v2
183
+ with:
184
+ egress-policy: audit
185
+
186
+ - uses: actions/checkout@v4
187
+
188
+ - name: Set up Node.js
189
+ uses: actions/setup-node@v4
190
+ with:
191
+ node-version: ${{ env.NODE_VERSION }}
192
+ cache: 'npm'
193
+ registry-url: ${{ env.REGISTRY_URL }}
194
+
195
+ - name: Install dependencies
196
+ run: npm ci --prefer-offline --no-audit
197
+
198
+ - name: Install npm with trusted publishing support
199
+ run: npm install --global npm@11.17.0
200
+
201
+ - name: Build for production
202
+ run: |
203
+ NODE_ENV=production npm run build
204
+ npm run docs
205
+
206
+ - name: Final production tests
207
+ run: |
208
+ npm run test:ci
209
+ npm run lint
210
+ npm audit --audit-level=moderate
211
+
212
+ - name: Deploy to NPM
213
+ # OIDC trusted publisher (no token: see staging step above).
214
+ run: npm publish --access public --provenance
215
+
216
+ - name: Deploy documentation to production
217
+ uses: peaceiris/actions-gh-pages@v4
218
+ with:
219
+ github_token: ${{ secrets.GITHUB_TOKEN }}
220
+ publish_dir: ./docs
221
+ publish_branch: gh-pages
222
+ enable_jekyll: false
223
+
224
+ - name: Create deployment artifact
225
+ run: |
226
+ mkdir -p artifacts
227
+ cp -r dist/* artifacts/
228
+ cp package.json artifacts/
229
+ cp README.md artifacts/
230
+ tar -czf deployment-${{ needs.pre-deployment.outputs.version }}.tar.gz artifacts/
231
+
232
+ - name: Upload deployment artifact
233
+ uses: actions/upload-artifact@v4
234
+ with:
235
+ name: deployment-${{ needs.pre-deployment.outputs.version }}
236
+ path: deployment-${{ needs.pre-deployment.outputs.version }}.tar.gz
237
+ retention-days: 90
238
+
239
+ - name: Production health check
240
+ run: |
241
+ echo "Waiting for NPM propagation..."
242
+ sleep 60
243
+
244
+ echo "Verifying NPM package..."
245
+ npm view dhruv-cli version
246
+
247
+ echo "Testing package installation..."
248
+ npm install -g dhruv-cli@${{ needs.pre-deployment.outputs.version }}
249
+ dhruv-cli --version
250
+
251
+ - name: Update GitHub release
252
+ uses: actions/github-script@v7
253
+ with:
254
+ script: |
255
+ await github.rest.repos.updateRelease({
256
+ owner: context.repo.owner,
257
+ repo: context.repo.repo,
258
+ release_id: ${{ github.event.release.id }},
259
+ body: ${{ github.event.release.body }} + '\n\n---\n\n✅ **Successfully deployed to production**\n\n- 📦 NPM: https://www.npmjs.com/package/dhruv-cli\n- 📚 Documentation: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}\n- 🔍 Health Status: ✅ All systems operational'
260
+ });
261
+
262
+ - name: Notify production deployment
263
+ uses: 8398a7/action-slack@v3
264
+ if: always()
265
+ continue-on-error: true
266
+ with:
267
+ status: ${{ job.status }}
268
+ channel: '#releases'
269
+ text: |
270
+ 🎉 Production Deployment ${{ job.status }}
271
+
272
+ **Version:** ${{ needs.pre-deployment.outputs.version }}
273
+ **NPM:** https://www.npmjs.com/package/dhruv-cli
274
+ **Docs:** https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
275
+ **Release:** ${{ github.event.release.html_url }}
276
+ env:
277
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
278
+
279
+ rollback:
280
+ name: Rollback Capability
281
+ runs-on: ubuntu-latest
282
+ if: failure() && (needs.deploy-staging.result == 'failure' || needs.deploy-production.result == 'failure')
283
+ needs: [pre-deployment, deploy-staging, deploy-production]
284
+ timeout-minutes: 10
285
+ steps:
286
+ - name: Harden Runner
287
+ uses: step-security/harden-runner@v2
288
+ with:
289
+ egress-policy: audit
290
+
291
+ - uses: actions/checkout@v4
292
+
293
+ - name: Create rollback issue
294
+ uses: actions/github-script@v7
295
+ with:
296
+ script: |
297
+ const title = `🚨 Deployment Failure - Rollback Required`;
298
+ const body = `
299
+ ## Deployment Failure Alert
300
+
301
+ A deployment has failed and may require rollback procedures.
302
+
303
+ ### Failure Details
304
+ - **Version:** ${{ needs.pre-deployment.outputs.version }}
305
+ - **Environment:** ${{ needs.pre-deployment.outputs.environment }}
306
+ - **Workflow:** ${{ github.workflow }}
307
+ - **Run ID:** ${{ github.run_id }}
308
+
309
+ ### Failed Jobs
310
+ - Deploy Staging: ${{ needs.deploy-staging.result }}
311
+ - Deploy Production: ${{ needs.deploy-production.result }}
312
+
313
+ ### Immediate Actions Required
314
+ - [ ] Assess impact of deployment failure
315
+ - [ ] Determine if rollback is necessary
316
+ - [ ] Execute rollback procedures if needed
317
+ - [ ] Investigate root cause
318
+ - [ ] Fix underlying issues
319
+
320
+ ### Rollback Commands
321
+ \`\`\`bash
322
+ # If NPM package was published, deprecate if necessary
323
+ npm deprecate dhruv-cli@${{ needs.pre-deployment.outputs.version }} "Deployment failed, please use previous version"
324
+ \`\`\`
325
+
326
+ **This issue was automatically created by the deployment pipeline.**
327
+ `;
328
+
329
+ await github.rest.issues.create({
330
+ owner: context.repo.owner,
331
+ repo: context.repo.repo,
332
+ title: title,
333
+ body: body,
334
+ labels: ['deployment', 'urgent', 'rollback'],
335
+ assignees: ['${{ github.repository_owner }}']
336
+ });
@@ -0,0 +1,270 @@
1
+ name: Monitoring & Health Check
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 * * *' # Daily at midnight UTC
6
+ - cron: '0 12 * * *' # Daily at noon UTC
7
+ workflow_dispatch:
8
+ push:
9
+ branches: [main]
10
+ paths:
11
+ - 'package.json'
12
+ - 'src/**'
13
+
14
+ permissions:
15
+ contents: read
16
+ issues: write
17
+ security-events: write
18
+
19
+ jobs:
20
+ health-check:
21
+ name: Application Health Check
22
+ runs-on: ubuntu-latest
23
+ timeout-minutes: 10
24
+ steps:
25
+ - name: Harden Runner
26
+ uses: step-security/harden-runner@v2
27
+ with:
28
+ egress-policy: audit
29
+
30
+ - uses: actions/checkout@v4
31
+
32
+ - name: Set up Node.js
33
+ uses: actions/setup-node@v4
34
+ with:
35
+ node-version: '20.8.1'
36
+ cache: 'npm'
37
+
38
+ - name: Install dependencies
39
+ run: npm ci --prefer-offline --no-audit
40
+
41
+ - name: Build application
42
+ run: npm run build
43
+
44
+ - name: Test CLI functionality
45
+ run: |
46
+ echo "Testing CLI help command"
47
+ node dist/index.js --help || echo "CLI help failed"
48
+
49
+ echo "Testing CLI version command"
50
+ node dist/index.js --version || echo "CLI version failed"
51
+
52
+ echo "Testing CLI status command"
53
+ node dist/index.js status || echo "CLI status failed"
54
+
55
+ - name: Performance benchmark
56
+ run: |
57
+ echo "Running performance tests..."
58
+ time node dist/index.js --version
59
+
60
+ # Memory usage check
61
+ echo "Checking memory usage..."
62
+ /usr/bin/time -v node dist/index.js --help 2>&1 | grep "Maximum resident set size" || echo "Memory check failed"
63
+
64
+ - name: Check bundle size
65
+ run: |
66
+ echo "Checking bundle sizes..."
67
+ du -h dist/ | sort -hr
68
+
69
+ # Check if any bundle exceeds size limits
70
+ find dist/ -name "*.js" -size +1M -exec echo "WARNING: Large bundle found: {}" \;
71
+
72
+ dependency-security:
73
+ name: Dependency Security Scan
74
+ runs-on: ubuntu-latest
75
+ timeout-minutes: 15
76
+ steps:
77
+ - name: Harden Runner
78
+ uses: step-security/harden-runner@v2
79
+ with:
80
+ egress-policy: audit
81
+
82
+ - uses: actions/checkout@v4
83
+
84
+ - name: Set up Node.js
85
+ uses: actions/setup-node@v4
86
+ with:
87
+ node-version: '20.8.1'
88
+ cache: 'npm'
89
+
90
+ - name: Install dependencies
91
+ run: npm ci --prefer-offline --no-audit
92
+
93
+ - name: Run npm audit
94
+ run: |
95
+ echo "Running npm security audit..."
96
+ npm audit --audit-level=moderate || echo "Audit found issues"
97
+
98
+ - name: Check for known vulnerabilities
99
+ uses: anchore/scan-action@v3
100
+ continue-on-error: true
101
+ with:
102
+ path: "."
103
+ fail-build: false
104
+ output-format: sarif
105
+
106
+ - name: Upload SARIF results
107
+ if: always()
108
+ uses: github/codeql-action/upload-sarif@v3
109
+ continue-on-error: true
110
+ with:
111
+ sarif_file: results.sarif
112
+
113
+ - name: License compliance check
114
+ run: |
115
+ echo "Checking license compliance..."
116
+ npx license-checker --summary || echo "License checker not available"
117
+
118
+ availability-monitor:
119
+ name: Service Availability Monitor
120
+ runs-on: ubuntu-latest
121
+ timeout-minutes: 10
122
+ if: github.event_name == 'schedule'
123
+ steps:
124
+ - name: Harden Runner
125
+ uses: step-security/harden-runner@v2
126
+ with:
127
+ egress-policy: audit
128
+
129
+ - name: Check NPM package availability
130
+ run: |
131
+ echo "Checking NPM package availability..."
132
+ curl -f https://registry.npmjs.org/dhruv-cli || echo "NPM package check failed"
133
+
134
+ - name: Check GitHub repository health
135
+ run: |
136
+ echo "Checking GitHub repository health..."
137
+ curl -f https://api.github.com/repos/${{ github.repository }} || echo "GitHub API check failed"
138
+
139
+ - name: Check documentation site
140
+ run: |
141
+ echo "Checking documentation availability..."
142
+ curl -f https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/ || echo "Documentation site check failed"
143
+
144
+ quality-metrics:
145
+ name: Code Quality Metrics
146
+ runs-on: ubuntu-latest
147
+ timeout-minutes: 20
148
+ steps:
149
+ - name: Harden Runner
150
+ uses: step-security/harden-runner@v2
151
+ with:
152
+ egress-policy: audit
153
+
154
+ - uses: actions/checkout@v4
155
+ with:
156
+ fetch-depth: 0
157
+
158
+ - name: Set up Node.js
159
+ uses: actions/setup-node@v4
160
+ with:
161
+ node-version: '20.8.1'
162
+ cache: 'npm'
163
+
164
+ - name: Install dependencies
165
+ run: npm ci --prefer-offline --no-audit
166
+
167
+ - name: Run test coverage
168
+ run: npm run test:ci
169
+
170
+ - name: Upload coverage to Codecov
171
+ uses: codecov/codecov-action@v4
172
+ with:
173
+ file: ./coverage/lcov.info
174
+ flags: unittests
175
+ name: codecov-umbrella
176
+ fail_ci_if_error: false
177
+
178
+ - name: Code complexity analysis
179
+ run: |
180
+ echo "Running code complexity analysis..."
181
+ npx complexity-report src/ --format json > complexity.json || echo "Complexity analysis failed"
182
+ cat complexity.json | jq '.reports[] | select(.complexity.cyclomatic > 10)' || echo "No high complexity functions found"
183
+
184
+ - name: Technical debt analysis
185
+ run: |
186
+ echo "Analyzing technical debt..."
187
+ # Count TODO/FIXME comments
188
+ find src/ -name "*.ts" -exec grep -c "TODO\|FIXME\|HACK" {} + | awk -F: '{sum+=$2} END {print "Technical debt items:", sum}'
189
+
190
+ # Check for code smells
191
+ find src/ -name "*.ts" -exec wc -l {} + | sort -nr | head -10
192
+
193
+ create-issue-on-failure:
194
+ name: Create Issue on Failure
195
+ runs-on: ubuntu-latest
196
+ needs: [health-check, dependency-security, availability-monitor, quality-metrics]
197
+ if: always() && (needs.health-check.result == 'failure' || needs.dependency-security.result == 'failure' || needs.availability-monitor.result == 'failure' || needs.quality-metrics.result == 'failure')
198
+ timeout-minutes: 5
199
+ steps:
200
+ - name: Harden Runner
201
+ uses: step-security/harden-runner@v2
202
+ with:
203
+ egress-policy: audit
204
+
205
+ - uses: actions/checkout@v4
206
+
207
+ - name: Create failure issue
208
+ uses: actions/github-script@v7
209
+ with:
210
+ script: |
211
+ const title = `🚨 Monitoring Alert: Workflow Failure Detected`;
212
+ const body = `
213
+ ## Monitoring Alert
214
+
215
+ A monitoring workflow has failed. Please investigate immediately.
216
+
217
+ ### Failure Details
218
+ - **Workflow**: ${{ github.workflow }}
219
+ - **Run ID**: ${{ github.run_id }}
220
+ - **Commit**: ${{ github.sha }}
221
+ - **Trigger**: ${{ github.event_name }}
222
+ - **Time**: ${new Date().toISOString()}
223
+
224
+ ### Job Results
225
+ - Health Check: ${{ needs.health-check.result }}
226
+ - Dependency Security: ${{ needs.dependency-security.result }}
227
+ - Availability Monitor: ${{ needs.availability-monitor.result }}
228
+ - Quality Metrics: ${{ needs.quality-metrics.result }}
229
+
230
+ ### Action Required
231
+ - [ ] Check workflow logs: [View Run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
232
+ - [ ] Investigate failures
233
+ - [ ] Fix underlying issues
234
+ - [ ] Verify fixes work
235
+ - [ ] Close this issue when resolved
236
+
237
+ **This issue was automatically created by the monitoring workflow.**
238
+ `;
239
+
240
+ // Check if similar issue already exists
241
+ const issues = await github.rest.issues.listForRepo({
242
+ owner: context.repo.owner,
243
+ repo: context.repo.repo,
244
+ labels: ['monitoring', 'automated'],
245
+ state: 'open'
246
+ });
247
+
248
+ const existingIssue = issues.data.find(issue =>
249
+ issue.title.includes('Monitoring Alert') &&
250
+ issue.body.includes('${{ github.run_id }}')
251
+ );
252
+
253
+ if (!existingIssue) {
254
+ await github.rest.issues.create({
255
+ owner: context.repo.owner,
256
+ repo: context.repo.repo,
257
+ title: title,
258
+ body: body,
259
+ labels: ['bug', 'monitoring', 'automated', 'urgent'],
260
+ assignees: ['${{ github.repository_owner }}']
261
+ });
262
+ }
263
+
264
+ - name: Send failure notification
265
+ if: always() && (needs.health-check.result == 'failure' || needs.dependency-security.result == 'failure' || needs.availability-monitor.result == 'failure' || needs.quality-metrics.result == 'failure')
266
+ uses: actions/github-script@v7
267
+ with:
268
+ script: |
269
+ console.log('Failure notification system activated');
270
+ // Additional notification logic can be added here