pipecraft 0.29.3 → 0.36.14
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/README.md +128 -54
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +68 -25
- package/dist/cli/index.js.map +1 -1
- package/dist/generators/init.tpl.d.ts +4 -4
- package/dist/generators/init.tpl.d.ts.map +1 -1
- package/dist/generators/init.tpl.js +214 -108
- package/dist/generators/init.tpl.js.map +1 -1
- package/dist/generators/workflows.tpl.d.ts +9 -9
- package/dist/generators/workflows.tpl.d.ts.map +1 -1
- package/dist/generators/workflows.tpl.js +33 -36
- package/dist/generators/workflows.tpl.js.map +1 -1
- package/dist/templates/actions/calculate-version.yml.tpl.d.ts +7 -4
- package/dist/templates/actions/calculate-version.yml.tpl.d.ts.map +1 -1
- package/dist/templates/actions/calculate-version.yml.tpl.js +49 -23
- package/dist/templates/actions/calculate-version.yml.tpl.js.map +1 -1
- package/dist/templates/actions/create-pr.yml.tpl.d.ts +5 -2
- package/dist/templates/actions/create-pr.yml.tpl.d.ts.map +1 -1
- package/dist/templates/actions/create-pr.yml.tpl.js +14 -8
- package/dist/templates/actions/create-pr.yml.tpl.js.map +1 -1
- package/dist/templates/actions/create-release.yml.tpl.d.ts +5 -2
- package/dist/templates/actions/create-release.yml.tpl.d.ts.map +1 -1
- package/dist/templates/actions/create-release.yml.tpl.js +16 -11
- package/dist/templates/actions/create-release.yml.tpl.js.map +1 -1
- package/dist/templates/actions/create-tag.yml.tpl.d.ts +5 -2
- package/dist/templates/actions/create-tag.yml.tpl.d.ts.map +1 -1
- package/dist/templates/actions/create-tag.yml.tpl.js +13 -9
- package/dist/templates/actions/create-tag.yml.tpl.js.map +1 -1
- package/dist/templates/actions/detect-changes.yml.tpl.d.ts +17 -51
- package/dist/templates/actions/detect-changes.yml.tpl.d.ts.map +1 -1
- package/dist/templates/actions/detect-changes.yml.tpl.js +130 -110
- package/dist/templates/actions/detect-changes.yml.tpl.js.map +1 -1
- package/dist/templates/actions/manage-branch.yml.tpl.d.ts +5 -2
- package/dist/templates/actions/manage-branch.yml.tpl.d.ts.map +1 -1
- package/dist/templates/actions/manage-branch.yml.tpl.js +13 -9
- package/dist/templates/actions/manage-branch.yml.tpl.js.map +1 -1
- package/dist/templates/actions/promote-branch.yml.tpl.d.ts +5 -2
- package/dist/templates/actions/promote-branch.yml.tpl.d.ts.map +1 -1
- package/dist/templates/actions/promote-branch.yml.tpl.js +39 -92
- package/dist/templates/actions/promote-branch.yml.tpl.js.map +1 -1
- package/dist/templates/release-it.cjs.tpl.d.ts +1 -1
- package/dist/templates/release-it.cjs.tpl.d.ts.map +1 -1
- package/dist/templates/release-it.cjs.tpl.js +38 -29
- package/dist/templates/release-it.cjs.tpl.js.map +1 -1
- package/dist/templates/workflows/enforce-pr-target.yml.tpl.d.ts +1 -1
- package/dist/templates/workflows/enforce-pr-target.yml.tpl.d.ts.map +1 -1
- package/dist/templates/workflows/enforce-pr-target.yml.tpl.js +2 -3
- package/dist/templates/workflows/enforce-pr-target.yml.tpl.js.map +1 -1
- package/dist/templates/workflows/pipeline.yml.tpl.d.ts +2 -2
- package/dist/templates/workflows/pipeline.yml.tpl.d.ts.map +1 -1
- package/dist/templates/workflows/pipeline.yml.tpl.js +337 -84
- package/dist/templates/workflows/pipeline.yml.tpl.js.map +1 -1
- package/dist/templates/workflows/pr-title-check.yml.tpl.d.ts +1 -1
- package/dist/templates/workflows/pr-title-check.yml.tpl.d.ts.map +1 -1
- package/dist/templates/workflows/pr-title-check.yml.tpl.js +101 -22
- package/dist/templates/workflows/pr-title-check.yml.tpl.js.map +1 -1
- package/dist/templates/workflows/shared/index.d.ts +4 -2
- package/dist/templates/workflows/shared/index.d.ts.map +1 -1
- package/dist/templates/workflows/shared/index.js +4 -2
- package/dist/templates/workflows/shared/index.js.map +1 -1
- package/dist/templates/workflows/shared/managed-workflow.d.ts +32 -0
- package/dist/templates/workflows/shared/managed-workflow.d.ts.map +1 -0
- package/dist/templates/workflows/shared/managed-workflow.js +51 -0
- package/dist/templates/workflows/shared/managed-workflow.js.map +1 -0
- package/dist/templates/workflows/shared/operations-changes.d.ts +13 -3
- package/dist/templates/workflows/shared/operations-changes.d.ts.map +1 -1
- package/dist/templates/workflows/shared/operations-changes.js +42 -16
- package/dist/templates/workflows/shared/operations-changes.js.map +1 -1
- package/dist/templates/workflows/shared/operations-domain-jobs.d.ts +18 -1
- package/dist/templates/workflows/shared/operations-domain-jobs.d.ts.map +1 -1
- package/dist/templates/workflows/shared/operations-domain-jobs.js +142 -17
- package/dist/templates/workflows/shared/operations-domain-jobs.js.map +1 -1
- package/dist/templates/workflows/shared/operations-gate.d.ts +6 -0
- package/dist/templates/workflows/shared/operations-gate.d.ts.map +1 -0
- package/dist/templates/workflows/shared/operations-gate.js +116 -0
- package/dist/templates/workflows/shared/operations-gate.js.map +1 -0
- package/dist/templates/workflows/shared/operations-header.d.ts +11 -1
- package/dist/templates/workflows/shared/operations-header.d.ts.map +1 -1
- package/dist/templates/workflows/shared/operations-header.js +66 -7
- package/dist/templates/workflows/shared/operations-header.js.map +1 -1
- package/dist/templates/workflows/shared/operations-tag-promote.d.ts +4 -3
- package/dist/templates/workflows/shared/operations-tag-promote.d.ts.map +1 -1
- package/dist/templates/workflows/shared/operations-tag-promote.js +144 -33
- package/dist/templates/workflows/shared/operations-tag-promote.js.map +1 -1
- package/dist/templates/workflows/shared/operations-version.d.ts +3 -2
- package/dist/templates/workflows/shared/operations-version.d.ts.map +1 -1
- package/dist/templates/workflows/shared/operations-version.js +17 -16
- package/dist/templates/workflows/shared/operations-version.js.map +1 -1
- package/dist/templates/yaml-format-utils.d.ts.map +1 -1
- package/dist/templates/yaml-format-utils.js +1 -5
- package/dist/templates/yaml-format-utils.js.map +1 -1
- package/dist/types/index.d.ts +65 -53
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/action-reference.d.ts +73 -0
- package/dist/utils/action-reference.d.ts.map +1 -0
- package/dist/utils/action-reference.js +120 -0
- package/dist/utils/action-reference.js.map +1 -0
- package/dist/utils/ast-path-operations.d.ts +3 -3
- package/dist/utils/ast-path-operations.d.ts.map +1 -1
- package/dist/utils/ast-path-operations.js +58 -17
- package/dist/utils/ast-path-operations.js.map +1 -1
- package/dist/utils/config.d.ts +16 -5
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +69 -12
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/github-setup.d.ts +7 -7
- package/dist/utils/github-setup.d.ts.map +1 -1
- package/dist/utils/github-setup.js +84 -63
- package/dist/utils/github-setup.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/messaging.d.ts +2 -2
- package/dist/utils/messaging.d.ts.map +1 -1
- package/dist/utils/messaging.js +12 -8
- package/dist/utils/messaging.js.map +1 -1
- package/dist/utils/preflight.d.ts +2 -2
- package/dist/utils/preflight.d.ts.map +1 -1
- package/dist/utils/preflight.js +43 -41
- package/dist/utils/preflight.js.map +1 -1
- package/dist/utils/versioning.d.ts +1 -1
- package/dist/utils/versioning.d.ts.map +1 -1
- package/dist/utils/versioning.js +10 -10
- package/dist/utils/versioning.js.map +1 -1
- package/dist/utils/workflow-semantics.d.ts +61 -0
- package/dist/utils/workflow-semantics.d.ts.map +1 -0
- package/dist/utils/workflow-semantics.js +230 -0
- package/dist/utils/workflow-semantics.js.map +1 -0
- package/package.json +12 -4
- package/src/generators/init.tpl.ts +275 -128
- package/src/generators/workflows.tpl.ts +54 -57
- package/dist/templates/actions/detect-changes-nx.yml.tpl.d.ts +0 -32
- package/dist/templates/actions/detect-changes-nx.yml.tpl.d.ts.map +0 -1
- package/dist/templates/actions/detect-changes-nx.yml.tpl.js +0 -227
- package/dist/templates/actions/detect-changes-nx.yml.tpl.js.map +0 -1
- package/dist/templates/workflows/pipeline-nx.yml.tpl.d.ts +0 -22
- package/dist/templates/workflows/pipeline-nx.yml.tpl.d.ts.map +0 -1
- package/dist/templates/workflows/pipeline-nx.yml.tpl.js +0 -196
- package/dist/templates/workflows/pipeline-nx.yml.tpl.js.map +0 -1
- package/dist/utils/idempotency.d.ts +0 -187
- package/dist/utils/idempotency.d.ts.map +0 -1
- package/dist/utils/idempotency.js +0 -304
- package/dist/utils/idempotency.js.map +0 -1
|
@@ -1,72 +1,68 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workflows Template Generator
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
4
|
* Main orchestrator for generating complete GitHub Actions CI/CD pipeline.
|
|
5
5
|
* This generator creates all necessary workflow files including:
|
|
6
6
|
* - Main pipeline workflow (path-based change detection)
|
|
7
7
|
* - Reusable composite actions (tag creation, versioning, branch management, etc.)
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* The generator supports both initial generation and incremental updates, preserving
|
|
10
10
|
* user modifications to existing workflows through intelligent merging.
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
12
|
* @module generators/workflows.tpl
|
|
13
|
-
*
|
|
13
|
+
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```typescript
|
|
16
16
|
* import { generate } from './generators/workflows.tpl.js'
|
|
17
|
-
*
|
|
17
|
+
*
|
|
18
18
|
* // Initial generation - creates all workflows
|
|
19
19
|
* await generate({
|
|
20
20
|
* cwd: '/path/to/project',
|
|
21
21
|
* config: pipecraftConfig
|
|
22
22
|
* })
|
|
23
|
-
*
|
|
23
|
+
*
|
|
24
24
|
* // Incremental update - merges with existing pipeline
|
|
25
25
|
* await generate({
|
|
26
26
|
* cwd: '/path/to/project',
|
|
27
27
|
* pipelinePath: '.github/workflows/pipeline.yml',
|
|
28
28
|
* config: pipecraftConfig
|
|
29
29
|
* })
|
|
30
|
-
*
|
|
30
|
+
*
|
|
31
31
|
* // Creates:
|
|
32
32
|
* // .github/workflows/pipeline.yml - Main pipeline
|
|
33
|
-
* //
|
|
34
|
-
* //
|
|
35
|
-
* //
|
|
36
|
-
* //
|
|
37
|
-
* //
|
|
38
|
-
* //
|
|
39
|
-
* //
|
|
33
|
+
* // actions/detect-changes/... - Change detection action
|
|
34
|
+
* // actions/calculate-version/... - Version calculation action
|
|
35
|
+
* // actions/create-tag/... - Tag creation action
|
|
36
|
+
* // actions/create-pr/... - PR creation action
|
|
37
|
+
* // actions/manage-branch/... - Branch management action
|
|
38
|
+
* // actions/promote-branch/... - Branch promotion action
|
|
39
|
+
* // actions/create-release/... - Release creation action
|
|
40
40
|
* // .release-it.cjs - Release-it configuration
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
|
-
import {
|
|
45
|
-
import {
|
|
46
|
-
import { PipecraftConfig } from '../types/index.js'
|
|
47
|
-
import { readFileSync, existsSync } from 'fs'
|
|
44
|
+
import { loadJSON, type PinionContext, renderTemplate, toFile, when } from '@featherscloud/pinion'
|
|
45
|
+
import { existsSync, readFileSync } from 'fs'
|
|
48
46
|
import { parse } from 'yaml'
|
|
49
|
-
import {
|
|
50
|
-
|
|
47
|
+
import { generate as generateVersionWorkflow } from '../templates/actions/calculate-version.yml.tpl.js'
|
|
48
|
+
import { generate as generateCreatePRWorkflow } from '../templates/actions/create-pr.yml.tpl.js'
|
|
49
|
+
import { generate as generateReleaseWorkflow } from '../templates/actions/create-release.yml.tpl.js'
|
|
51
50
|
// Import individual workflow templates
|
|
52
51
|
import { generate as generateTagWorkflow } from '../templates/actions/create-tag.yml.tpl.js'
|
|
53
52
|
import { generate as generateChangesWorkflow } from '../templates/actions/detect-changes.yml.tpl.js'
|
|
54
|
-
import { generate as generateChangesNxWorkflow } from '../templates/actions/detect-changes-nx.yml.tpl.js'
|
|
55
|
-
import { generate as generateVersionWorkflow } from '../templates/actions/calculate-version.yml.tpl.js'
|
|
56
|
-
import { generate as generateCreatePRWorkflow } from '../templates/actions/create-pr.yml.tpl.js'
|
|
57
53
|
import { generate as generateBranchWorkflow } from '../templates/actions/manage-branch.yml.tpl.js'
|
|
58
54
|
import { generate as generatePromoteBranchWorkflow } from '../templates/actions/promote-branch.yml.tpl.js'
|
|
59
|
-
import { generate as
|
|
60
|
-
import { generate as generatePathBasedPipeline } from '../templates/workflows/pipeline.yml.tpl.js'
|
|
61
|
-
import { generate as generateNxPipeline } from '../templates/workflows/pipeline-nx.yml.tpl.js'
|
|
55
|
+
import { generate as generateReleaseItConfig } from '../templates/release-it.cjs.tpl.js'
|
|
62
56
|
import { generate as generateEnforcePRTarget } from '../templates/workflows/enforce-pr-target.yml.tpl.js'
|
|
57
|
+
import { generate as generatePipeline } from '../templates/workflows/pipeline.yml.tpl.js'
|
|
63
58
|
import { generate as generatePRTitleCheck } from '../templates/workflows/pr-title-check.yml.tpl.js'
|
|
64
|
-
import {
|
|
59
|
+
import { PipecraftConfig } from '../types/index.js'
|
|
60
|
+
import { logger } from '../utils/logger.js'
|
|
65
61
|
|
|
66
62
|
/**
|
|
67
63
|
* Default fallback configuration when no config file exists.
|
|
68
64
|
* Mirrors `defaultConfig` from init.tpl.ts to ensure consistent behavior.
|
|
69
|
-
*
|
|
65
|
+
*
|
|
70
66
|
* @const
|
|
71
67
|
* @see {@link module:generators/init.tpl~defaultConfig}
|
|
72
68
|
*/
|
|
@@ -94,22 +90,22 @@ const defaultConfig = {
|
|
|
94
90
|
|
|
95
91
|
/**
|
|
96
92
|
* Workflows generator main entry point.
|
|
97
|
-
*
|
|
93
|
+
*
|
|
98
94
|
* Orchestrates the complete workflow generation process:
|
|
99
95
|
* 1. Loads existing pipeline (if specified) for merging
|
|
100
96
|
* 2. Merges configuration with defaults
|
|
101
97
|
* 3. Generates all composite actions in parallel
|
|
102
98
|
* 4. Generates the main pipeline workflow
|
|
103
|
-
*
|
|
99
|
+
*
|
|
104
100
|
* @param {PinionContext & { pipelinePath?: string, outputPipelinePath?: string, config?: any }} ctx - Extended Pinion context
|
|
105
101
|
* @param {string} [ctx.pipelinePath] - Path to existing pipeline for incremental updates
|
|
106
102
|
* @param {string} [ctx.outputPipelinePath] - Custom output path for pipeline (defaults to .github/workflows/pipeline.yml)
|
|
107
103
|
* @param {PipecraftConfig} [ctx.config] - PipeCraft configuration (overrides defaults)
|
|
108
104
|
* @returns {Promise<PinionContext>} Updated context after workflow generation
|
|
109
|
-
*
|
|
105
|
+
*
|
|
110
106
|
* @throws {Error} If workflow files cannot be written
|
|
111
107
|
* @throws {Error} If existing pipeline cannot be parsed
|
|
112
|
-
*
|
|
108
|
+
*
|
|
113
109
|
* @example
|
|
114
110
|
* ```typescript
|
|
115
111
|
* // Initial generation with config
|
|
@@ -121,7 +117,7 @@ const defaultConfig = {
|
|
|
121
117
|
* domains: { api: { paths: ['src/api/**'] } }
|
|
122
118
|
* }
|
|
123
119
|
* })
|
|
124
|
-
*
|
|
120
|
+
*
|
|
125
121
|
* // Update existing pipeline
|
|
126
122
|
* await generate({
|
|
127
123
|
* cwd: '/path/to/project',
|
|
@@ -129,18 +125,20 @@ const defaultConfig = {
|
|
|
129
125
|
* config: updatedConfig
|
|
130
126
|
* })
|
|
131
127
|
* ```
|
|
132
|
-
*
|
|
128
|
+
*
|
|
133
129
|
* @note The generator creates 9 files:
|
|
134
130
|
* - 1 main workflow (pipeline.yml)
|
|
135
|
-
* - 7 composite actions (in
|
|
131
|
+
* - 7 composite actions (in actions/)
|
|
136
132
|
* - 1 release-it configuration (.release-it.cjs)
|
|
137
|
-
*
|
|
133
|
+
*
|
|
138
134
|
* All actions are generated in parallel for performance, followed by
|
|
139
135
|
* the main pipeline which may reference the actions.
|
|
140
136
|
*/
|
|
141
|
-
export const generate = (
|
|
137
|
+
export const generate = (
|
|
138
|
+
ctx: PinionContext & { pipelinePath?: string; outputPipelinePath?: string; config?: any }
|
|
139
|
+
) =>
|
|
142
140
|
Promise.resolve(ctx)
|
|
143
|
-
.then(
|
|
141
|
+
.then(ctx => {
|
|
144
142
|
logger.info('🔧 Generating GitHub Actions...')
|
|
145
143
|
|
|
146
144
|
// Load existing pipeline if provided
|
|
@@ -156,11 +154,20 @@ export const generate = (ctx: PinionContext & { pipelinePath?: string, outputPip
|
|
|
156
154
|
}
|
|
157
155
|
}
|
|
158
156
|
|
|
159
|
-
return {
|
|
157
|
+
return {
|
|
158
|
+
...ctx,
|
|
159
|
+
...defaultConfig,
|
|
160
|
+
...ctx.config,
|
|
161
|
+
...ctx,
|
|
162
|
+
existingPipeline,
|
|
163
|
+
existingPipelineContent,
|
|
164
|
+
outputPipelinePath: ctx.outputPipelinePath
|
|
165
|
+
}
|
|
160
166
|
})
|
|
161
|
-
.then(
|
|
167
|
+
.then(ctx => {
|
|
162
168
|
// Generate individual GitHub Actions and release-it config
|
|
163
169
|
const generators = [
|
|
170
|
+
// Unified detect-changes action works for all stacks
|
|
164
171
|
generateChangesWorkflow(ctx),
|
|
165
172
|
generateTagWorkflow(ctx),
|
|
166
173
|
generateVersionWorkflow(ctx),
|
|
@@ -171,31 +178,21 @@ export const generate = (ctx: PinionContext & { pipelinePath?: string, outputPip
|
|
|
171
178
|
generateReleaseItConfig(ctx)
|
|
172
179
|
]
|
|
173
180
|
|
|
174
|
-
// Add Nx-specific action if Nx is enabled
|
|
175
|
-
if (ctx.config?.nx?.enabled) {
|
|
176
|
-
generators.push(generateChangesNxWorkflow(ctx))
|
|
177
|
-
}
|
|
178
|
-
|
|
179
181
|
return Promise.all(generators).then(() => ctx)
|
|
180
182
|
})
|
|
181
|
-
.then(
|
|
182
|
-
// Generate the main pipeline (
|
|
183
|
-
|
|
184
|
-
logger.info('🔧 Generating Nx-optimized pipeline...')
|
|
185
|
-
return generateNxPipeline(ctx as any)
|
|
186
|
-
} else {
|
|
187
|
-
return generatePathBasedPipeline(ctx)
|
|
188
|
-
}
|
|
183
|
+
.then(ctx => {
|
|
184
|
+
// Generate the main pipeline (path-based change detection)
|
|
185
|
+
return generatePipeline(ctx)
|
|
189
186
|
})
|
|
190
|
-
.then(
|
|
187
|
+
.then(ctx => {
|
|
191
188
|
// Generate the enforce PR target workflow
|
|
192
189
|
return generateEnforcePRTarget(ctx)
|
|
193
190
|
})
|
|
194
|
-
.then(
|
|
191
|
+
.then(ctx => {
|
|
195
192
|
// Generate the PR title check workflow
|
|
196
193
|
return generatePRTitleCheck(ctx)
|
|
197
194
|
})
|
|
198
|
-
.then(
|
|
195
|
+
.then(ctx => {
|
|
199
196
|
logger.success('✅ Generated workflows in: .github/workflows')
|
|
200
197
|
return ctx
|
|
201
|
-
})
|
|
198
|
+
})
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detect Changes Nx Action Template
|
|
3
|
-
*
|
|
4
|
-
* Generates a GitHub composite action that detects which domains have changed
|
|
5
|
-
* using Nx dependency graph analysis with path-based fallback.
|
|
6
|
-
*
|
|
7
|
-
* ## Purpose
|
|
8
|
-
*
|
|
9
|
-
* For Nx monorepos, this action uses `nx show projects --affected` to leverage
|
|
10
|
-
* the dependency graph for intelligent change detection. It maps affected Nx
|
|
11
|
-
* projects to configured domains and falls back to path-based detection when
|
|
12
|
-
* Nx is unavailable.
|
|
13
|
-
*
|
|
14
|
-
* ## Generated Action Location
|
|
15
|
-
*
|
|
16
|
-
* `.github/actions/detect-changes-nx/action.yml`
|
|
17
|
-
*
|
|
18
|
-
* @module templates/actions/detect-changes-nx.yml.tpl
|
|
19
|
-
*/
|
|
20
|
-
import { PinionContext } from '@featherscloud/pinion';
|
|
21
|
-
/**
|
|
22
|
-
* Generator entry point for detect-changes-nx composite action.
|
|
23
|
-
*
|
|
24
|
-
* Generates the `.github/actions/detect-changes-nx/action.yml` file with Nx-aware
|
|
25
|
-
* change detection logic. This action is used by Nx-enabled pipelines.
|
|
26
|
-
*
|
|
27
|
-
* @param {PinionContext} ctx - Pinion generator context
|
|
28
|
-
* @param {Record<string, DomainConfig>} ctx.domains - Domain configurations
|
|
29
|
-
* @returns {Promise<PinionContext>} Updated context after file generation
|
|
30
|
-
*/
|
|
31
|
-
export declare const generate: (ctx: PinionContext) => Promise<any>;
|
|
32
|
-
//# sourceMappingURL=detect-changes-nx.yml.tpl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"detect-changes-nx.yml.tpl.d.ts","sourceRoot":"","sources":["../../../src/templates/actions/detect-changes-nx.yml.tpl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,EAA0B,MAAM,uBAAuB,CAAA;AAmN7E;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,aAAa,iBAU+D,CAAA"}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detect Changes Nx Action Template
|
|
3
|
-
*
|
|
4
|
-
* Generates a GitHub composite action that detects which domains have changed
|
|
5
|
-
* using Nx dependency graph analysis with path-based fallback.
|
|
6
|
-
*
|
|
7
|
-
* ## Purpose
|
|
8
|
-
*
|
|
9
|
-
* For Nx monorepos, this action uses `nx show projects --affected` to leverage
|
|
10
|
-
* the dependency graph for intelligent change detection. It maps affected Nx
|
|
11
|
-
* projects to configured domains and falls back to path-based detection when
|
|
12
|
-
* Nx is unavailable.
|
|
13
|
-
*
|
|
14
|
-
* ## Generated Action Location
|
|
15
|
-
*
|
|
16
|
-
* `.github/actions/detect-changes-nx/action.yml`
|
|
17
|
-
*
|
|
18
|
-
* @module templates/actions/detect-changes-nx.yml.tpl
|
|
19
|
-
*/
|
|
20
|
-
import { toFile, renderTemplate } from '@featherscloud/pinion';
|
|
21
|
-
import fs from 'fs';
|
|
22
|
-
import { logger } from '../../utils/logger.js';
|
|
23
|
-
/**
|
|
24
|
-
* Generates the detect-changes-nx composite action YAML content.
|
|
25
|
-
*
|
|
26
|
-
* Creates a GitHub Actions composite action that:
|
|
27
|
-
* - Checks for Nx availability in the repository
|
|
28
|
-
* - Uses `nx show projects --affected` for dependency graph analysis
|
|
29
|
-
* - Maps affected projects to domains
|
|
30
|
-
* - Falls back to path-based detection if Nx isn't available
|
|
31
|
-
* - Outputs Nx-specific information (affected projects, Nx availability)
|
|
32
|
-
*
|
|
33
|
-
* @param {any} ctx - Context containing domains configuration
|
|
34
|
-
* @param {Record<string, DomainConfig>} ctx.domains - Domain configurations with path patterns
|
|
35
|
-
* @returns {string} YAML content for the composite action
|
|
36
|
-
*/
|
|
37
|
-
const changesNxActionTemplate = (ctx) => {
|
|
38
|
-
const domainOutputs = Object.entries(ctx.domains).map((entry) => {
|
|
39
|
-
const [domainName, domainConfig] = entry;
|
|
40
|
-
return ` ${domainName}:
|
|
41
|
-
description: 'Whether ${domainName} domain has changes'
|
|
42
|
-
value: \${{ steps.merge.outputs.${domainName} }}`;
|
|
43
|
-
}).join('\n');
|
|
44
|
-
const domainFilters = Object.entries(ctx.domains).map((entry) => {
|
|
45
|
-
const [domainName, domainConfig] = entry;
|
|
46
|
-
return ` ${domainName}:\n - '${domainConfig.paths.join("'\\n - '")}'`;
|
|
47
|
-
}).join('\n');
|
|
48
|
-
// Generate Nx pattern matching logic for each domain
|
|
49
|
-
const domainNames = Object.keys(ctx.domains);
|
|
50
|
-
const nxPatternMatching = domainNames.map(domainName => {
|
|
51
|
-
return ` # Check ${domainName} domain patterns
|
|
52
|
-
if echo "$project" | grep -qE "(${domainName}|$(echo "${domainName}" | sed 's/-/[-_]/g'))"; then
|
|
53
|
-
${domainName.toUpperCase()}_AFFECTED=true
|
|
54
|
-
echo " ✅ $project matches ${domainName} domain"
|
|
55
|
-
fi`;
|
|
56
|
-
}).join('\n');
|
|
57
|
-
const nxFlagInit = domainNames.map(domainName => ` ${domainName.toUpperCase()}_AFFECTED=false`).join('\n');
|
|
58
|
-
const nxOutputs = domainNames.map(domainName => ` echo "${domainName}=$${domainName.toUpperCase()}_AFFECTED" >> $GITHUB_OUTPUT`).join('\n');
|
|
59
|
-
const nxFallbackOutputs = domainNames.map(domainName => ` echo "${domainName}=false" >> $GITHUB_OUTPUT`).join('\n');
|
|
60
|
-
const pathFilterOutputs = domainNames.map(domainName => ` echo "${domainName}=\${{ contains(steps.filter.outputs.changes, '${domainName}') }}" >> $GITHUB_OUTPUT`).join('\n');
|
|
61
|
-
const nxMergeOutputs = domainNames.map(domainName => ` echo "${domainName}=\${{ steps.nx-filter.outputs.${domainName} }}" >> $GITHUB_OUTPUT`).join('\n');
|
|
62
|
-
const resultEchoes = domainNames.map(domainName => ` echo " ${domainName}: \${{ steps.merge.outputs.${domainName} }}"`).join('\n');
|
|
63
|
-
// Generate the composite action YAML
|
|
64
|
-
return `name: 'Detect Changes with Nx Support'
|
|
65
|
-
description: 'Enhanced change detection using Nx dependency graph with path-based fallback'
|
|
66
|
-
author: 'Pipecraft'
|
|
67
|
-
|
|
68
|
-
inputs:
|
|
69
|
-
baseRef:
|
|
70
|
-
description: 'Base reference to compare against'
|
|
71
|
-
required: false
|
|
72
|
-
default: 'main'
|
|
73
|
-
useNx:
|
|
74
|
-
description: 'Whether to use Nx dependency graph for change detection'
|
|
75
|
-
required: false
|
|
76
|
-
default: 'true'
|
|
77
|
-
|
|
78
|
-
outputs:
|
|
79
|
-
${domainOutputs}
|
|
80
|
-
nxAvailable:
|
|
81
|
-
description: 'Whether Nx is available in the repository'
|
|
82
|
-
value: \${{ steps.nx-check.outputs.available }}
|
|
83
|
-
affectedProjects:
|
|
84
|
-
description: 'Comma-separated list of affected Nx projects'
|
|
85
|
-
value: \${{ steps.nx-filter.outputs.affectedProjects }}
|
|
86
|
-
|
|
87
|
-
runs:
|
|
88
|
-
using: 'composite'
|
|
89
|
-
steps:
|
|
90
|
-
- name: Checkout Code
|
|
91
|
-
uses: actions/checkout@v4
|
|
92
|
-
with:
|
|
93
|
-
fetch-depth: 0
|
|
94
|
-
|
|
95
|
-
- name: Set Base Branch
|
|
96
|
-
id: set-base
|
|
97
|
-
shell: bash
|
|
98
|
-
run: |
|
|
99
|
-
base_branch=\${{ inputs.baseRef || 'main' }}
|
|
100
|
-
echo "base_branch=$base_branch" >> $GITHUB_OUTPUT
|
|
101
|
-
echo "base_branch=$base_branch" >> $GITHUB_ENV
|
|
102
|
-
|
|
103
|
-
- name: Check for Nx
|
|
104
|
-
id: nx-check
|
|
105
|
-
shell: bash
|
|
106
|
-
run: |
|
|
107
|
-
if [ -f "nx.json" ] || ([ -f "package.json" ] && grep -q '"nx"' package.json); then
|
|
108
|
-
echo "available=true" >> $GITHUB_OUTPUT
|
|
109
|
-
echo "🔍 Nx detected in repository"
|
|
110
|
-
else
|
|
111
|
-
echo "available=false" >> $GITHUB_OUTPUT
|
|
112
|
-
echo "⚠️ Nx not detected, falling back to path-based detection"
|
|
113
|
-
fi
|
|
114
|
-
|
|
115
|
-
- name: Setup Node.js
|
|
116
|
-
if: steps.nx-check.outputs.available == 'true' && inputs.useNx == 'true'
|
|
117
|
-
uses: actions/setup-node@v4
|
|
118
|
-
with:
|
|
119
|
-
node-version: '20'
|
|
120
|
-
|
|
121
|
-
- name: Install Dependencies
|
|
122
|
-
if: steps.nx-check.outputs.available == 'true' && inputs.useNx == 'true'
|
|
123
|
-
shell: bash
|
|
124
|
-
run: |
|
|
125
|
-
echo "📦 Installing dependencies for Nx..."
|
|
126
|
-
if [ -f "pnpm-lock.yaml" ]; then
|
|
127
|
-
corepack enable
|
|
128
|
-
pnpm install --frozen-lockfile || pnpm install
|
|
129
|
-
elif [ -f "yarn.lock" ]; then
|
|
130
|
-
yarn install --frozen-lockfile || yarn install
|
|
131
|
-
elif [ -f "package-lock.json" ]; then
|
|
132
|
-
npm ci || npm install
|
|
133
|
-
else
|
|
134
|
-
npm install
|
|
135
|
-
fi
|
|
136
|
-
|
|
137
|
-
- name: Detect Changes with Nx (if available)
|
|
138
|
-
id: nx-filter
|
|
139
|
-
if: steps.nx-check.outputs.available == 'true' && inputs.useNx == 'true'
|
|
140
|
-
shell: bash
|
|
141
|
-
run: |
|
|
142
|
-
echo "🚀 Using Nx dependency graph for change detection"
|
|
143
|
-
|
|
144
|
-
# Get affected projects using Nx
|
|
145
|
-
if command -v npx >/dev/null 2>&1; then
|
|
146
|
-
# Get list of affected projects (newline-separated)
|
|
147
|
-
AFFECTED_PROJECTS_RAW=$(npx nx show projects --affected --base=\${{ steps.set-base.outputs.base_branch }} 2>/dev/null || echo "")
|
|
148
|
-
|
|
149
|
-
# Convert newlines to commas for storage
|
|
150
|
-
AFFECTED_PROJECTS=$(echo "$AFFECTED_PROJECTS_RAW" | tr '\\n' ',' | sed 's/,$//')
|
|
151
|
-
echo "affectedProjects=$AFFECTED_PROJECTS" >> $GITHUB_OUTPUT
|
|
152
|
-
|
|
153
|
-
if [ -n "$AFFECTED_PROJECTS" ]; then
|
|
154
|
-
echo "📦 Affected Nx projects: $AFFECTED_PROJECTS"
|
|
155
|
-
|
|
156
|
-
# Initialize domain flags
|
|
157
|
-
${nxFlagInit}
|
|
158
|
-
|
|
159
|
-
# Check each affected project against domain patterns (comma-separated)
|
|
160
|
-
IFS=',' read -ra PROJECTS <<< "$AFFECTED_PROJECTS"
|
|
161
|
-
for project in "\${PROJECTS[@]}"; do
|
|
162
|
-
project=$(echo "$project" | xargs) # trim whitespace
|
|
163
|
-
${nxPatternMatching}
|
|
164
|
-
done
|
|
165
|
-
|
|
166
|
-
# Set outputs
|
|
167
|
-
${nxOutputs}
|
|
168
|
-
|
|
169
|
-
else
|
|
170
|
-
echo "No affected projects detected"
|
|
171
|
-
${nxFallbackOutputs}
|
|
172
|
-
fi
|
|
173
|
-
else
|
|
174
|
-
echo "⚠️ npx not available, falling back to path-based detection"
|
|
175
|
-
${nxFallbackOutputs}
|
|
176
|
-
echo "affectedProjects=" >> $GITHUB_OUTPUT
|
|
177
|
-
fi
|
|
178
|
-
|
|
179
|
-
- name: Detect Changes with Paths Filter (fallback)
|
|
180
|
-
uses: dorny/paths-filter@v3
|
|
181
|
-
id: filter
|
|
182
|
-
if: steps.nx-check.outputs.available != 'true' || inputs.useNx != 'true'
|
|
183
|
-
with:
|
|
184
|
-
base: \${{ steps.set-base.outputs.base_branch }}
|
|
185
|
-
filters: |
|
|
186
|
-
${domainFilters}
|
|
187
|
-
|
|
188
|
-
- name: Merge filter outputs
|
|
189
|
-
id: merge
|
|
190
|
-
shell: bash
|
|
191
|
-
run: |
|
|
192
|
-
# Use Nx results if available, otherwise use path filter results
|
|
193
|
-
if [ "\${{ steps.nx-check.outputs.available }}" == "true" ] && [ "\${{ inputs.useNx }}" == "true" ]; then
|
|
194
|
-
${nxMergeOutputs}
|
|
195
|
-
echo "🔍 Using Nx dependency analysis results"
|
|
196
|
-
echo "📦 Affected projects: \${{ steps.nx-filter.outputs.affectedProjects }}"
|
|
197
|
-
else
|
|
198
|
-
${pathFilterOutputs}
|
|
199
|
-
echo "📁 Using path-based change detection"
|
|
200
|
-
fi
|
|
201
|
-
|
|
202
|
-
echo "📋 Change Detection Results:"
|
|
203
|
-
${resultEchoes}
|
|
204
|
-
echo " nx-available: \${{ steps.nx-check.outputs.available }}"
|
|
205
|
-
`;
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* Generator entry point for detect-changes-nx composite action.
|
|
209
|
-
*
|
|
210
|
-
* Generates the `.github/actions/detect-changes-nx/action.yml` file with Nx-aware
|
|
211
|
-
* change detection logic. This action is used by Nx-enabled pipelines.
|
|
212
|
-
*
|
|
213
|
-
* @param {PinionContext} ctx - Pinion generator context
|
|
214
|
-
* @param {Record<string, DomainConfig>} ctx.domains - Domain configurations
|
|
215
|
-
* @returns {Promise<PinionContext>} Updated context after file generation
|
|
216
|
-
*/
|
|
217
|
-
export const generate = (ctx) => Promise.resolve(ctx)
|
|
218
|
-
.then((ctx) => {
|
|
219
|
-
// Check if file exists to determine merge status
|
|
220
|
-
const filePath = '.github/actions/detect-changes-nx/action.yml';
|
|
221
|
-
const exists = fs.existsSync(filePath);
|
|
222
|
-
const status = exists ? '🔄 Merged with existing' : '📝 Created new';
|
|
223
|
-
logger.verbose(`${status} ${filePath}`);
|
|
224
|
-
return ctx;
|
|
225
|
-
})
|
|
226
|
-
.then(renderTemplate(changesNxActionTemplate, toFile('.github/actions/detect-changes-nx/action.yml')));
|
|
227
|
-
//# sourceMappingURL=detect-changes-nx.yml.tp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,SAAS;;;;EAIT,iBAAiB;;;;EAIjB,iBAAiB;;;;;;;;;;;EAWjB,aAAa;;;;;;;;EAQb,cAAc;;;;EAId,iBAAiB;;;;;EAKjB,YAAY;;CAEb,CAAC;AACF,CAAC,CAAA;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAkB,EAAE,EAAE,CAC7C,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;KACjB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IACZ,iDAAiD;IACjD,MAAM,QAAQ,GAAG,8CAA8C,CAAA;IAC/D,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,gBAAgB,CAAA;IACpE,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,IAAI,QAAQ,EAAE,CAAC,CAAA;IACvC,OAAO,GAAG,CAAA;AACZ,CAAC,CAAC;KACD,IAAI,CAAC,cAAc,CAAC,uBAAuB,EAAE,MAAM,CAAC,8CAA8C,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Nx Pipeline Template
|
|
3
|
-
*
|
|
4
|
-
* Generates an Nx-optimized workflow that uses `nx affected` to intelligently test
|
|
5
|
-
* only changed projects. Runs all Nx tasks sequentially in a single job, leveraging
|
|
6
|
-
* Nx's built-in caching and parallel execution.
|
|
7
|
-
*
|
|
8
|
-
* This is Option 1 (Sequential Strategy) - simple, fast, and leverages Nx's intelligence.
|
|
9
|
-
*/
|
|
10
|
-
import { PinionContext } from '@featherscloud/pinion';
|
|
11
|
-
import { PipecraftConfig } from '../../types/index.js';
|
|
12
|
-
interface NxPipelineContext extends PinionContext {
|
|
13
|
-
config: PipecraftConfig;
|
|
14
|
-
branchFlow: string[];
|
|
15
|
-
outputPipelinePath?: string;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Main generator that handles merging with existing workflow
|
|
19
|
-
*/
|
|
20
|
-
export declare const generate: (ctx: NxPipelineContext) => Promise<any>;
|
|
21
|
-
export {};
|
|
22
|
-
//# sourceMappingURL=pipeline-nx.yml.tpl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline-nx.yml.tpl.d.ts","sourceRoot":"","sources":["../../../src/templates/workflows/pipeline-nx.yml.tpl.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,aAAa,EAA0B,MAAM,uBAAuB,CAAA;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAiBtD,UAAU,iBAAkB,SAAQ,aAAa;IAC/C,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAqFD;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,KAAK,iBAAiB,iBAwH2F,CAAA"}
|