pipecraft 0.0.0-releaseit → 0.26.0

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 (183) hide show
  1. package/README.md +126 -108
  2. package/dist/cli/index.d.ts +69 -0
  3. package/dist/cli/index.d.ts.map +1 -1
  4. package/dist/cli/index.js +94 -22
  5. package/dist/cli/index.js.map +1 -1
  6. package/dist/generators/init.tpl.d.ts +70 -0
  7. package/dist/generators/init.tpl.d.ts.map +1 -1
  8. package/dist/generators/init.tpl.js +100 -8
  9. package/dist/generators/init.tpl.js.map +1 -1
  10. package/dist/generators/workflows.tpl.d.ts +86 -0
  11. package/dist/generators/workflows.tpl.d.ts.map +1 -1
  12. package/dist/generators/workflows.tpl.js +101 -9
  13. package/dist/generators/workflows.tpl.js.map +1 -1
  14. package/dist/templates/actions/calculate-version.yml.tpl.d.ts +47 -0
  15. package/dist/templates/actions/calculate-version.yml.tpl.d.ts.map +1 -1
  16. package/dist/templates/actions/calculate-version.yml.tpl.js +72 -3
  17. package/dist/templates/actions/calculate-version.yml.tpl.js.map +1 -1
  18. package/dist/templates/actions/create-pr.yml.tpl.d.ts +14 -0
  19. package/dist/templates/actions/create-pr.yml.tpl.d.ts.map +1 -1
  20. package/dist/templates/actions/create-pr.yml.tpl.js +22 -2
  21. package/dist/templates/actions/create-pr.yml.tpl.js.map +1 -1
  22. package/dist/templates/actions/create-release.yml.tpl.d.ts +18 -0
  23. package/dist/templates/actions/create-release.yml.tpl.d.ts.map +1 -0
  24. package/dist/templates/actions/create-release.yml.tpl.js +141 -0
  25. package/dist/templates/actions/create-release.yml.tpl.js.map +1 -0
  26. package/dist/templates/actions/create-tag.yml.tpl.d.ts +14 -0
  27. package/dist/templates/actions/create-tag.yml.tpl.d.ts.map +1 -1
  28. package/dist/templates/actions/create-tag.yml.tpl.js +22 -2
  29. package/dist/templates/actions/create-tag.yml.tpl.js.map +1 -1
  30. package/dist/templates/actions/detect-changes.yml.tpl.d.ts +70 -0
  31. package/dist/templates/actions/detect-changes.yml.tpl.d.ts.map +1 -1
  32. package/dist/templates/actions/detect-changes.yml.tpl.js +98 -2
  33. package/dist/templates/actions/detect-changes.yml.tpl.js.map +1 -1
  34. package/dist/templates/actions/manage-branch.yml.tpl.d.ts +14 -0
  35. package/dist/templates/actions/manage-branch.yml.tpl.d.ts.map +1 -1
  36. package/dist/templates/actions/manage-branch.yml.tpl.js +22 -2
  37. package/dist/templates/actions/manage-branch.yml.tpl.js.map +1 -1
  38. package/dist/templates/actions/promote-branch.yml.tpl.d.ts +14 -0
  39. package/dist/templates/actions/promote-branch.yml.tpl.d.ts.map +1 -1
  40. package/dist/templates/actions/promote-branch.yml.tpl.js +50 -7
  41. package/dist/templates/actions/promote-branch.yml.tpl.js.map +1 -1
  42. package/dist/templates/workflows/pipeline-path-based.yml.tpl.d.ts +114 -1
  43. package/dist/templates/workflows/pipeline-path-based.yml.tpl.d.ts.map +1 -1
  44. package/dist/templates/workflows/pipeline-path-based.yml.tpl.js +479 -74
  45. package/dist/templates/workflows/pipeline-path-based.yml.tpl.js.map +1 -1
  46. package/dist/types/index.d.ts +231 -8
  47. package/dist/types/index.d.ts.map +1 -1
  48. package/dist/types/index.js +9 -0
  49. package/dist/types/index.js.map +1 -1
  50. package/dist/utils/ast-path-operations.d.ts.map +1 -1
  51. package/dist/utils/ast-path-operations.js +24 -11
  52. package/dist/utils/ast-path-operations.js.map +1 -1
  53. package/dist/utils/config.d.ts +63 -0
  54. package/dist/utils/config.d.ts.map +1 -1
  55. package/dist/utils/config.js +71 -0
  56. package/dist/utils/config.js.map +1 -1
  57. package/dist/utils/github-setup.d.ts +323 -2
  58. package/dist/utils/github-setup.d.ts.map +1 -1
  59. package/dist/utils/github-setup.js +551 -23
  60. package/dist/utils/github-setup.js.map +1 -1
  61. package/dist/utils/idempotency.d.ts +147 -7
  62. package/dist/utils/idempotency.d.ts.map +1 -1
  63. package/dist/utils/idempotency.js +143 -15
  64. package/dist/utils/idempotency.js.map +1 -1
  65. package/dist/utils/logger.d.ts +134 -0
  66. package/dist/utils/logger.d.ts.map +1 -0
  67. package/dist/utils/logger.js +153 -0
  68. package/dist/utils/logger.js.map +1 -0
  69. package/dist/utils/preflight.d.ts +223 -12
  70. package/dist/utils/preflight.d.ts.map +1 -1
  71. package/dist/utils/preflight.js +216 -16
  72. package/dist/utils/preflight.js.map +1 -1
  73. package/dist/utils/versioning.d.ts +160 -8
  74. package/dist/utils/versioning.d.ts.map +1 -1
  75. package/dist/utils/versioning.js +179 -15
  76. package/dist/utils/versioning.js.map +1 -1
  77. package/package.json +26 -5
  78. package/.claude/settings.local.json +0 -35
  79. package/.github/actions/calculate-version/action.yml +0 -106
  80. package/.github/actions/create-pr/action.yml +0 -122
  81. package/.github/actions/create-release/action.yml +0 -74
  82. package/.github/actions/create-tag/action.yml +0 -94
  83. package/.github/actions/detect-changes/action.yml +0 -62
  84. package/.github/actions/manage-branch/action.yml +0 -113
  85. package/.github/actions/promote-branch/action.yml +0 -352
  86. package/.github/example/workflows/job.analyze.code.yml +0 -26
  87. package/.github/example/workflows/job.analyze.docker.yml +0 -32
  88. package/.github/example/workflows/job.app.api.deploy.yml +0 -127
  89. package/.github/example/workflows/job.app.api.test.yml +0 -102
  90. package/.github/example/workflows/job.app.docs.deploy.yml +0 -40
  91. package/.github/example/workflows/job.app.docs.test.yml +0 -50
  92. package/.github/example/workflows/job.app.web.deploy.yml +0 -96
  93. package/.github/example/workflows/job.app.web.test.yml +0 -49
  94. package/.github/example/workflows/job.changes.yml +0 -82
  95. package/.github/example/workflows/job.create-pr.yml +0 -96
  96. package/.github/example/workflows/job.env-check.yml +0 -43
  97. package/.github/example/workflows/job.fast-forward.yml +0 -103
  98. package/.github/example/workflows/job.lint.yml +0 -64
  99. package/.github/example/workflows/job.pr-name.yml +0 -70
  100. package/.github/example/workflows/job.pr-squash-name.yml +0 -27
  101. package/.github/example/workflows/job.tag.yml +0 -38
  102. package/.github/example/workflows/job.version.yml +0 -99
  103. package/.github/example/workflows/lib.plugin-base.publish.yml +0 -59
  104. package/.github/example/workflows/pipe.yml +0 -178
  105. package/.github/example/workflows/scripts/fastforward.sh +0 -51
  106. package/.github/example/workflows/scripts/pipe-cleaner.sh +0 -70
  107. package/.github/scripts/fastforward.sh +0 -51
  108. package/.github/scripts/pipe-cleaner.sh +0 -70
  109. package/.github/workflows/pipeline.yml +0 -220
  110. package/.github/workflows/pr-title-check.yml +0 -70
  111. package/.github/workflows/publish.yml +0 -39
  112. package/.pipecraftrc.json +0 -78
  113. package/.release-it.cjs +0 -71
  114. package/PIPELINE_TESTING_PLAN.md +0 -499
  115. package/TRUNK_FLOW_PLAN.md +0 -401
  116. package/assets/logo_banner.png +0 -0
  117. package/assets/logo_banner.webp +0 -0
  118. package/docs/USER_JOURNEY_ERRORS.md +0 -352
  119. package/eslint.config.js +0 -77
  120. package/examples/basic-config.json +0 -41
  121. package/examples/monorepo-config.json +0 -49
  122. package/examples/usage.md +0 -289
  123. package/scripts/debug-workflows.sh +0 -339
  124. package/scripts/parse-pipeline.js +0 -29
  125. package/scripts/test-job-order.cjs +0 -140
  126. package/scripts/validate-pipeline.cjs +0 -379
  127. package/scripts/verify-job-order.sh +0 -30
  128. package/src/cli/index.ts +0 -414
  129. package/src/generators/init.tpl.ts +0 -126
  130. package/src/generators/workflows.tpl.ts +0 -80
  131. package/src/templates/actions/calculate-version.yml.tpl.ts +0 -124
  132. package/src/templates/actions/create-pr.yml.tpl.ts +0 -147
  133. package/src/templates/actions/create-tag.yml.tpl.ts +0 -112
  134. package/src/templates/actions/detect-changes.yml.tpl.ts +0 -87
  135. package/src/templates/actions/manage-branch.yml.tpl.ts +0 -132
  136. package/src/templates/actions/promote-branch.yml.tpl.ts +0 -364
  137. package/src/templates/workflows/pipeline-path-based.yml.tpl.ts +0 -706
  138. package/src/types/index.ts +0 -64
  139. package/src/utils/README-ast-path-operations.md +0 -390
  140. package/src/utils/ast-path-operations.ts +0 -581
  141. package/src/utils/config.ts +0 -64
  142. package/src/utils/github-setup.ts +0 -558
  143. package/src/utils/idempotency.ts +0 -215
  144. package/src/utils/preflight.ts +0 -306
  145. package/src/utils/versioning.ts +0 -244
  146. package/tests/README.md +0 -229
  147. package/tests/TEST_STRUCTURE.md +0 -256
  148. package/tests/act/run-act-tests.sh +0 -345
  149. package/tests/debugging/debug-utils.ts +0 -538
  150. package/tests/debugging/debug-workflow.test.ts +0 -339
  151. package/tests/debugging/debug-workflows.sh +0 -339
  152. package/tests/debugging/iterative-debug.ts +0 -652
  153. package/tests/debugging/run-debug-tests.sh +0 -431
  154. package/tests/fixtures/basic-config.json +0 -51
  155. package/tests/fixtures/invalid-config.json +0 -9
  156. package/tests/fixtures/pipeline-generated.yml +0 -235
  157. package/tests/fixtures/pipeline-preserve-comments.yml +0 -245
  158. package/tests/fixtures/pipeline-user-modified.yml +0 -245
  159. package/tests/fixtures/test-config.json +0 -58
  160. package/tests/github-live/README.md +0 -250
  161. package/tests/github-local/JOB_WORKFLOW_TESTS.md +0 -296
  162. package/tests/github-local/README.md +0 -240
  163. package/tests/github-local/run-all-tests.sh +0 -422
  164. package/tests/github-local/test-job-workflows.sh +0 -631
  165. package/tests/github-local/test-pipeline-workflow.sh +0 -440
  166. package/tests/integration/generators.test.ts +0 -578
  167. package/tests/integration/path-based-template.test.ts +0 -510
  168. package/tests/integration/simple-path-based.test.ts +0 -415
  169. package/tests/setup.ts +0 -56
  170. package/tests/unit/ast-path-operations-extended.test.ts +0 -302
  171. package/tests/unit/cli.test.ts +0 -541
  172. package/tests/unit/config-extended.test.ts +0 -412
  173. package/tests/unit/config.test.ts +0 -152
  174. package/tests/unit/github-setup.test.ts +0 -189
  175. package/tests/unit/idempotency-isolated.test.ts +0 -297
  176. package/tests/unit/job-order.test.ts +0 -157
  177. package/tests/unit/pipeline-path-based.test.ts +0 -511
  178. package/tests/unit/validate-pipeline.test.ts +0 -384
  179. package/tests/unit/versioning-extended.test.ts +0 -279
  180. package/tests/unit/versioning.test.ts +0 -241
  181. package/tsconfig.debug.json +0 -17
  182. package/tsconfig.json +0 -28
  183. package/vitest.config.ts +0 -51
@@ -1,240 +0,0 @@
1
- # GitHub Actions Local Testing
2
-
3
- This directory contains tests for running GitHub Actions workflows locally using [Act](https://github.com/nektos/act).
4
-
5
- ## 🎯 Purpose
6
-
7
- Local GitHub Actions testing allows us to:
8
- - Test workflows locally without pushing to GitHub
9
- - Debug workflow issues in a controlled environment
10
- - Validate workflow syntax and logic before deployment
11
- - Test different scenarios and edge cases quickly
12
- - Iterate on workflow changes without GitHub API limits
13
-
14
- ## 📁 Structure
15
-
16
- ```
17
- tests/github-local/
18
- ├── README.md # This file
19
- ├── run-local-tests.sh # Main test runner script
20
- ├── setup-test-env.sh # Environment setup script
21
- ├── test-workflows.sh # Individual workflow testing
22
- ├── fixtures/ # Test data and configurations
23
- │ ├── test-configs/ # Test configurations
24
- │ ├── mock-data/ # Mock data for workflows
25
- │ └── expected-outputs/ # Expected test outputs
26
- └── helpers/ # Test helper scripts
27
- ├── act-runner.sh # Act execution helper
28
- └── workflow-validator.sh # Workflow validation helper
29
- ```
30
-
31
- ## 🚀 Quick Start
32
-
33
- ### Prerequisites
34
- ```bash
35
- # Install Act
36
- curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
37
-
38
- # Or via package manager
39
- brew install act # macOS
40
- choco install act # Windows
41
- ```
42
-
43
- ### Running Tests
44
- ```bash
45
- # Run all local tests
46
- ./tests/github-local/run-local-tests.sh
47
-
48
- # Test specific workflow
49
- ./tests/github-local/test-workflows.sh --workflow pipeline.yml
50
-
51
- # Run with verbose output
52
- ./tests/github-local/run-local-tests.sh --verbose
53
-
54
- # Run with debug mode
55
- ./tests/github-local/run-local-tests.sh --debug
56
- ```
57
-
58
- ## 🔧 Configuration
59
-
60
- ### Act Configuration
61
- Create `.actrc` file in project root:
62
- ```yaml
63
- # Act configuration
64
- -P ubuntu-latest=catthehacker/ubuntu:act-latest
65
- -P ubuntu-20.04=catthehacker/ubuntu:act-20.04
66
- -P ubuntu-18.04=catthehacker/ubuntu:act-18.04
67
- ```
68
-
69
- ### Test Environment
70
- ```bash
71
- # Set up test environment
72
- ./tests/github-local/setup-test-env.sh
73
-
74
- # This creates:
75
- # - Test configuration files
76
- # - Mock GitHub environment
77
- # - Test data and fixtures
78
- # - Expected output files
79
- ```
80
-
81
- ## 📋 Test Workflows
82
-
83
- ### Supported Workflows
84
- - **pipeline.yml**: Main workflow orchestration
85
- - **job.changes.yml**: Change detection workflow
86
- - **job.version.yml**: Version management workflow
87
- - **job.tag.yml**: Tag creation workflow
88
- - **job.createpr.yml**: PR creation workflow
89
- - **job.branch.yml**: Branch management workflow
90
- - **job.apps.yml**: Application-specific workflows
91
-
92
- ### Test Scenarios
93
- 1. **Basic Execution**: Test workflow runs without errors
94
- 2. **Environment Variables**: Test with different env vars
95
- 3. **Conditional Logic**: Test workflow conditions and branches
96
- 4. **Job Dependencies**: Test job dependency chains
97
- 5. **Error Handling**: Test failure scenarios
98
- 6. **Performance**: Test execution time and resource usage
99
-
100
- ## 🧪 Test Examples
101
-
102
- ### Basic Workflow Test
103
- ```bash
104
- # Test main pipeline
105
- act -W .github/workflows/pipeline.yml --dry-run
106
-
107
- # Test with specific event
108
- act push -W .github/workflows/pipeline.yml --dry-run
109
-
110
- # Test with environment variables
111
- act -W .github/workflows/pipeline.yml --env GITHUB_REF=refs/heads/main --dry-run
112
- ```
113
-
114
- ### Advanced Testing
115
- ```bash
116
- # Test with secrets
117
- act -W .github/workflows/pipeline.yml --secret GITHUB_TOKEN=your_token
118
-
119
- # Test with artifacts
120
- act -W .github/workflows/pipeline.yml --artifact-server-path /tmp/artifacts
121
-
122
- # Test with matrix strategy
123
- act -W .github/workflows/pipeline.yml --matrix os:ubuntu-latest --matrix node:18
124
- ```
125
-
126
- ## 🔍 Debugging
127
-
128
- ### Common Issues
129
- 1. **Docker not running**: Ensure Docker is running
130
- 2. **Permission issues**: Check file permissions
131
- 3. **Environment variables**: Verify all required env vars are set
132
- 4. **Workflow syntax**: Check YAML syntax and GitHub Actions syntax
133
-
134
- ### Debug Commands
135
- ```bash
136
- # List available workflows
137
- act --list
138
-
139
- # Show workflow details
140
- act -W .github/workflows/pipeline.yml --list
141
-
142
- # Run with verbose output
143
- act -W .github/workflows/pipeline.yml --verbose
144
-
145
- # Run with debug output
146
- act -W .github/workflows/pipeline.yml --debug
147
- ```
148
-
149
- ## 📊 Test Results
150
-
151
- ### Output Format
152
- ```
153
- ✅ Workflow: pipeline.yml
154
- ✅ Job: changes (2.3s)
155
- ✅ Job: versioning (1.8s)
156
- ✅ Job: deployments (4.2s)
157
- ⚠️ Job: testing (skipped - no changes)
158
-
159
- ❌ Workflow: job.changes.yml
160
- ❌ Job: changes (failed - missing env var)
161
- 📝 Error: GITHUB_TOKEN not set
162
- ```
163
-
164
- ### Performance Metrics
165
- - **Execution Time**: Track workflow execution time
166
- - **Resource Usage**: Monitor CPU and memory usage
167
- - **Job Dependencies**: Validate dependency chains
168
- - **Error Rates**: Track failure rates and patterns
169
-
170
- ## 🔄 Continuous Integration
171
-
172
- ### GitHub Actions Integration
173
- ```yaml
174
- name: Local Act Tests
175
- on: [push, pull_request]
176
- jobs:
177
- local-tests:
178
- runs-on: ubuntu-latest
179
- steps:
180
- - uses: actions/checkout@v4
181
- - name: Install Act
182
- run: curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
183
- - name: Run Local Tests
184
- run: ./tests/github-local/run-local-tests.sh
185
- ```
186
-
187
- ### Local Development
188
- ```bash
189
- # Watch mode for development
190
- ./tests/github-local/run-local-tests.sh --watch
191
-
192
- # Run specific test suite
193
- ./tests/github-local/run-local-tests.sh --suite pipeline
194
-
195
- # Run with coverage
196
- ./tests/github-local/run-local-tests.sh --coverage
197
- ```
198
-
199
- ## 📚 Best Practices
200
-
201
- ### Test Organization
202
- 1. **Group related tests**: Organize tests by workflow type
203
- 2. **Use fixtures**: Create reusable test data
204
- 3. **Mock external services**: Avoid external dependencies
205
- 4. **Test edge cases**: Include error scenarios and edge cases
206
-
207
- ### Performance
208
- 1. **Parallel execution**: Run independent tests in parallel
209
- 2. **Resource management**: Monitor Docker resource usage
210
- 3. **Cleanup**: Clean up test artifacts after runs
211
- 4. **Caching**: Use Docker layer caching for faster builds
212
-
213
- ### Maintenance
214
- 1. **Regular updates**: Keep Act and test dependencies updated
215
- 2. **Documentation**: Document test scenarios and expected outcomes
216
- 3. **Monitoring**: Track test performance and reliability
217
- 4. **Feedback**: Collect feedback from test results
218
-
219
- ## 🆘 Troubleshooting
220
-
221
- ### Common Problems
222
- ```bash
223
- # Act not found
224
- export PATH=$PATH:/usr/local/bin
225
-
226
- # Docker permission denied
227
- sudo usermod -aG docker $USER
228
-
229
- # Workflow syntax errors
230
- act -W .github/workflows/pipeline.yml --dry-run --verbose
231
-
232
- # Environment variable issues
233
- act -W .github/workflows/pipeline.yml --env-file .env
234
- ```
235
-
236
- ### Getting Help
237
- - [Act Documentation](https://github.com/nektos/act)
238
- - [GitHub Actions Documentation](https://docs.github.com/en/actions)
239
- - [Docker Documentation](https://docs.docker.com/)
240
- - [Project Issues](https://github.com/your-org/pipecraft/issues)
@@ -1,422 +0,0 @@
1
- #!/bin/bash
2
-
3
- # Comprehensive GitHub Actions Testing Suite
4
- # Runs all GitHub Actions tests using Act
5
-
6
- set -euo pipefail
7
-
8
- # Colors for output
9
- RED='\033[0;31m'
10
- GREEN='\033[0;32m'
11
- YELLOW='\033[1;33m'
12
- BLUE='\033[0;34m'
13
- PURPLE='\033[0;35m'
14
- CYAN='\033[0;36m'
15
- NC='\033[0m' # No Color
16
-
17
- # Configuration
18
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
20
- OUTPUT_DIR="$SCRIPT_DIR/output"
21
- VERBOSE=false
22
- DEBUG=false
23
- CLEANUP=true
24
- SKIP_JOB_TESTS=false
25
- SKIP_PIPELINE_TESTS=false
26
-
27
- # Function to print colored output
28
- print_status() {
29
- local status=$1
30
- local message=$2
31
-
32
- case $status in
33
- "SUCCESS") echo -e "${GREEN}✓${NC} $message" ;;
34
- "FAILURE") echo -e "${RED}✗${NC} $message" ;;
35
- "WARNING") echo -e "${YELLOW}⚠${NC} $message" ;;
36
- "INFO") echo -e "${BLUE}ℹ${NC} $message" ;;
37
- "DEBUG") echo -e "${PURPLE}🐛${NC} $message" ;;
38
- *) echo -e "${CYAN}?${NC} $message" ;;
39
- esac
40
- }
41
-
42
- # Function to show usage
43
- show_usage() {
44
- cat << EOF
45
- Usage: $0 [OPTIONS]
46
-
47
- Comprehensive GitHub Actions Testing Suite
48
-
49
- OPTIONS:
50
- -j, --skip-job-tests Skip individual job workflow tests
51
- -p, --skip-pipeline-tests Skip pipeline workflow tests
52
- -v, --verbose Verbose output
53
- -d, --debug Debug mode with extra logging
54
- -c, --no-cleanup Don't clean up test artifacts
55
- -h, --help Show this help message
56
-
57
- EXAMPLES:
58
- $0 # Run all tests
59
- $0 -j # Skip job tests, run pipeline tests
60
- $0 -p # Skip pipeline tests, run job tests
61
- $0 -v -d # Verbose debug mode
62
- $0 --no-cleanup # Run tests, keep artifacts
63
-
64
- EOF
65
- }
66
-
67
- # Function to check prerequisites
68
- check_prerequisites() {
69
- print_status "INFO" "Checking prerequisites..."
70
-
71
- local missing_deps=()
72
-
73
- # Check for required commands
74
- if ! command -v act &> /dev/null; then
75
- missing_deps+=("act")
76
- fi
77
-
78
- if ! command -v docker &> /dev/null; then
79
- missing_deps+=("docker")
80
- fi
81
-
82
- if ! command -v jq &> /dev/null; then
83
- missing_deps+=("jq")
84
- fi
85
-
86
- if [ ${#missing_deps[@]} -gt 0 ]; then
87
- print_status "FAILURE" "Missing dependencies: ${missing_deps[*]}"
88
- echo -e "${YELLOW}Please install missing dependencies:${NC}"
89
- for dep in "${missing_deps[@]}"; do
90
- case $dep in
91
- "act") echo " - Act: curl https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash" ;;
92
- "docker") echo " - Docker: https://docs.docker.com/get-docker/" ;;
93
- "jq") echo " - jq: brew install jq (macOS) or apt-get install jq (Ubuntu)" ;;
94
- esac
95
- done
96
- exit 1
97
- fi
98
-
99
- # Check if Docker is running
100
- if ! docker info &> /dev/null; then
101
- print_status "FAILURE" "Docker is not running"
102
- echo -e "${YELLOW}Please start Docker and try again${NC}"
103
- exit 1
104
- fi
105
-
106
- print_status "SUCCESS" "All prerequisites satisfied"
107
- }
108
-
109
- # Function to setup test environment
110
- setup_test_environment() {
111
- print_status "INFO" "Setting up test environment..."
112
-
113
- # Create output directory
114
- mkdir -p "$OUTPUT_DIR"
115
-
116
- # Create test configuration
117
- cat > "$PROJECT_ROOT/.actrc" << EOF
118
- # Act configuration for testing
119
- -P ubuntu-latest=catthehacker/ubuntu:act-latest
120
- -P ubuntu-20.04=catthehacker/ubuntu:act-20.04
121
- -P ubuntu-18.04=catthehacker/ubuntu:act-18.04
122
- EOF
123
-
124
- # Create test environment file
125
- cat > "$PROJECT_ROOT/.env" << EOF
126
- # Test environment variables
127
- GITHUB_ACTIONS=true
128
- GITHUB_WORKFLOW=test-workflow
129
- GITHUB_RUN_ID=123456789
130
- GITHUB_RUN_NUMBER=1
131
- GITHUB_ACTOR=test-user
132
- GITHUB_REPOSITORY=test-org/test-repo
133
- GITHUB_EVENT_NAME=push
134
- GITHUB_SHA=abc123def456
135
- GITHUB_REF=refs/heads/main
136
- GITHUB_HEAD_REF=""
137
- GITHUB_BASE_REF=""
138
- GITHUB_WORKSPACE=$PROJECT_ROOT
139
- GITHUB_TOKEN=test-token
140
- EOF
141
-
142
- print_status "SUCCESS" "Test environment setup complete"
143
- }
144
-
145
- # Function to run job workflow tests
146
- run_job_tests() {
147
- if [ "$SKIP_JOB_TESTS" = true ]; then
148
- print_status "WARNING" "Skipping job workflow tests"
149
- return 0
150
- fi
151
-
152
- print_status "INFO" "Running job workflow tests..."
153
-
154
- local test_script="$SCRIPT_DIR/test-job-workflows.sh"
155
- if [ ! -f "$test_script" ]; then
156
- print_status "FAILURE" "Job test script not found: $test_script"
157
- return 1
158
- fi
159
-
160
- local test_args=()
161
- if [ "$VERBOSE" = true ]; then
162
- test_args+=("-v")
163
- fi
164
- if [ "$DEBUG" = true ]; then
165
- test_args+=("-d")
166
- fi
167
- if [ "$CLEANUP" = false ]; then
168
- test_args+=("-c")
169
- fi
170
-
171
- if "$test_script" "${test_args[@]}"; then
172
- print_status "SUCCESS" "Job workflow tests passed"
173
- return 0
174
- else
175
- print_status "FAILURE" "Job workflow tests failed"
176
- return 1
177
- fi
178
- }
179
-
180
- # Function to run pipeline workflow tests
181
- run_pipeline_tests() {
182
- if [ "$SKIP_PIPELINE_TESTS" = true ]; then
183
- print_status "WARNING" "Skipping pipeline workflow tests"
184
- return 0
185
- fi
186
-
187
- print_status "INFO" "Running pipeline workflow tests..."
188
-
189
- local test_script="$SCRIPT_DIR/test-pipeline-workflow.sh"
190
- if [ ! -f "$test_script" ]; then
191
- print_status "FAILURE" "Pipeline test script not found: $test_script"
192
- return 1
193
- fi
194
-
195
- local test_args=()
196
- if [ "$VERBOSE" = true ]; then
197
- test_args+=("-v")
198
- fi
199
- if [ "$DEBUG" = true ]; then
200
- test_args+=("-d")
201
- fi
202
- if [ "$CLEANUP" = false ]; then
203
- test_args+=("-c")
204
- fi
205
-
206
- if "$test_script" "${test_args[@]}"; then
207
- print_status "SUCCESS" "Pipeline workflow tests passed"
208
- return 0
209
- else
210
- print_status "FAILURE" "Pipeline workflow tests failed"
211
- return 1
212
- fi
213
- }
214
-
215
- # Function to run workflow generation tests
216
- run_generation_tests() {
217
- print_status "INFO" "Running workflow generation tests..."
218
-
219
- # Check if workflows exist
220
- local workflows_dir="$PROJECT_ROOT/.github/workflows"
221
- if [ ! -d "$workflows_dir" ]; then
222
- print_status "FAILURE" "Workflows directory not found: $workflows_dir"
223
- return 1
224
- fi
225
-
226
- # Check for required workflow files
227
- local required_workflows=(
228
- "pipeline.yml"
229
- "job.changes.yml"
230
- "job.version.yml"
231
- "job.tag.yml"
232
- "job.createpr.yml"
233
- "job.branch.yml"
234
- "job.apps.yml"
235
- )
236
-
237
- local missing_workflows=()
238
- for workflow in "${required_workflows[@]}"; do
239
- if [ ! -f "$workflows_dir/$workflow" ]; then
240
- missing_workflows+=("$workflow")
241
- fi
242
- done
243
-
244
- if [ ${#missing_workflows[@]} -gt 0 ]; then
245
- print_status "FAILURE" "Missing workflow files: ${missing_workflows[*]}"
246
- echo -e "${YELLOW}Please generate workflows first using: ./pipecraft generate${NC}"
247
- return 1
248
- fi
249
-
250
- print_status "SUCCESS" "All required workflow files found"
251
- return 0
252
- }
253
-
254
- # Function to run syntax validation tests
255
- run_syntax_tests() {
256
- print_status "INFO" "Running workflow syntax validation..."
257
-
258
- local workflows_dir="$PROJECT_ROOT/.github/workflows"
259
- local syntax_errors=0
260
-
261
- # Check each workflow file for syntax errors
262
- find "$workflows_dir" -name "*.yml" -o -name "*.yaml" | while read -r workflow_file; do
263
- local workflow_name=$(basename "$workflow_file")
264
-
265
- # Basic YAML syntax check
266
- if ! python3 -c "import yaml; yaml.safe_load(open('$workflow_file'))" 2>/dev/null; then
267
- print_status "FAILURE" "Syntax error in $workflow_name"
268
- syntax_errors=$((syntax_errors + 1))
269
- else
270
- print_status "SUCCESS" "Syntax valid: $workflow_name"
271
- fi
272
- done
273
-
274
- if [ $syntax_errors -gt 0 ]; then
275
- print_status "FAILURE" "Found $syntax_errors syntax errors"
276
- return 1
277
- else
278
- print_status "SUCCESS" "All workflow files have valid syntax"
279
- return 0
280
- fi
281
- }
282
-
283
- # Function to run all tests
284
- run_all_tests() {
285
- print_status "INFO" "Running comprehensive GitHub Actions test suite..."
286
-
287
- local failed_tests=0
288
- local total_tests=0
289
-
290
- # Test scenarios
291
- local test_scenarios=(
292
- "run_generation_tests:Workflow Generation"
293
- "run_syntax_tests:Workflow Syntax"
294
- "run_job_tests:Job Workflows"
295
- "run_pipeline_tests:Pipeline Workflow"
296
- )
297
-
298
- for test in "${test_scenarios[@]}"; do
299
- IFS=':' read -r test_function test_name <<< "$test"
300
- total_tests=$((total_tests + 1))
301
-
302
- print_status "INFO" "Running $test_name tests..."
303
- if $test_function; then
304
- print_status "SUCCESS" "✅ $test_name tests passed"
305
- else
306
- print_status "FAILURE" "❌ $test_name tests failed"
307
- failed_tests=$((failed_tests + 1))
308
- fi
309
- done
310
-
311
- # Summary
312
- echo ""
313
- print_status "INFO" "Test Suite Summary:"
314
- echo " Total test suites: $total_tests"
315
- echo " Passed: $((total_tests - failed_tests))"
316
- echo " Failed: $failed_tests"
317
-
318
- if [ $failed_tests -gt 0 ]; then
319
- print_status "FAILURE" "Some test suites failed"
320
- return 1
321
- else
322
- print_status "SUCCESS" "All test suites passed"
323
- return 0
324
- fi
325
- }
326
-
327
- # Function to cleanup test artifacts
328
- cleanup_test_artifacts() {
329
- if [ "$CLEANUP" = true ]; then
330
- print_status "INFO" "Cleaning up test artifacts..."
331
-
332
- # Remove test files
333
- rm -f "$PROJECT_ROOT/.actrc"
334
- rm -f "$PROJECT_ROOT/.env"
335
-
336
- # Clean up output directory
337
- if [ -d "$OUTPUT_DIR" ]; then
338
- rm -rf "$OUTPUT_DIR"
339
- fi
340
-
341
- print_status "SUCCESS" "Cleanup complete"
342
- fi
343
- }
344
-
345
- # Function to show test results
346
- show_test_results() {
347
- if [ -d "$OUTPUT_DIR" ]; then
348
- echo ""
349
- print_status "INFO" "Test Results:"
350
- echo " Output directory: $OUTPUT_DIR"
351
-
352
- if [ "$VERBOSE" = true ]; then
353
- echo " Log files:"
354
- find "$OUTPUT_DIR" -name "*.log" -exec basename {} \; | while read -r log_file; do
355
- echo " - $log_file"
356
- done
357
- fi
358
- fi
359
- }
360
-
361
- # Parse command line arguments
362
- while [[ $# -gt 0 ]]; do
363
- case $1 in
364
- -j|--skip-job-tests)
365
- SKIP_JOB_TESTS=true
366
- shift
367
- ;;
368
- -p|--skip-pipeline-tests)
369
- SKIP_PIPELINE_TESTS=true
370
- shift
371
- ;;
372
- -v|--verbose)
373
- VERBOSE=true
374
- shift
375
- ;;
376
- -d|--debug)
377
- DEBUG=true
378
- shift
379
- ;;
380
- -c|--no-cleanup)
381
- CLEANUP=false
382
- shift
383
- ;;
384
- -h|--help)
385
- show_usage
386
- exit 0
387
- ;;
388
- *)
389
- echo -e "${RED}Unknown option: $1${NC}" >&2
390
- show_usage
391
- exit 1
392
- ;;
393
- esac
394
- done
395
-
396
- # Main execution
397
- main() {
398
- echo -e "${BLUE}Comprehensive GitHub Actions Testing Suite${NC}"
399
- echo -e "${CYAN}==========================================${NC}"
400
- echo ""
401
-
402
- # Check prerequisites
403
- check_prerequisites
404
-
405
- # Setup test environment
406
- setup_test_environment
407
-
408
- # Run all tests
409
- run_all_tests
410
-
411
- # Show results
412
- show_test_results
413
-
414
- # Cleanup
415
- cleanup_test_artifacts
416
-
417
- echo ""
418
- print_status "SUCCESS" "Comprehensive testing complete!"
419
- }
420
-
421
- # Run main function
422
- main "$@"