@invarn/cibuild 1.3.16 → 1.3.17

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 (242) hide show
  1. package/dist/cli.cjs +1 -1
  2. package/dist/src/cli.d.ts +3 -0
  3. package/dist/src/cli.d.ts.map +1 -0
  4. package/dist/src/cli.js +987 -0
  5. package/dist/src/commands/android-scanner.d.ts +32 -0
  6. package/dist/src/commands/android-scanner.d.ts.map +1 -0
  7. package/dist/src/commands/android-scanner.js +667 -0
  8. package/dist/src/commands/build.d.ts +5 -0
  9. package/dist/src/commands/build.d.ts.map +1 -0
  10. package/dist/src/commands/build.js +1096 -0
  11. package/dist/src/commands/edit.d.ts +3 -0
  12. package/dist/src/commands/edit.d.ts.map +1 -0
  13. package/dist/src/commands/edit.js +651 -0
  14. package/dist/src/commands/file-secret-collector.d.ts +37 -0
  15. package/dist/src/commands/file-secret-collector.d.ts.map +1 -0
  16. package/dist/src/commands/file-secret-collector.js +199 -0
  17. package/dist/src/commands/github-workflow.d.ts +5 -0
  18. package/dist/src/commands/github-workflow.d.ts.map +1 -0
  19. package/dist/src/commands/github-workflow.js +45 -0
  20. package/dist/src/commands/ios-scanner.d.ts +27 -0
  21. package/dist/src/commands/ios-scanner.d.ts.map +1 -0
  22. package/dist/src/commands/ios-scanner.js +337 -0
  23. package/dist/src/commands/reset.d.ts +7 -0
  24. package/dist/src/commands/reset.d.ts.map +1 -0
  25. package/dist/src/commands/reset.js +81 -0
  26. package/dist/src/commands/secrets-sync-workflow.d.ts +15 -0
  27. package/dist/src/commands/secrets-sync-workflow.d.ts.map +1 -0
  28. package/dist/src/commands/secrets-sync-workflow.js +255 -0
  29. package/dist/src/commands/secrets-upload.d.ts +21 -0
  30. package/dist/src/commands/secrets-upload.d.ts.map +1 -0
  31. package/dist/src/commands/secrets-upload.js +177 -0
  32. package/dist/src/commands/secrets-upload.test.d.ts +5 -0
  33. package/dist/src/commands/secrets-upload.test.d.ts.map +1 -0
  34. package/dist/src/commands/secrets-upload.test.js +60 -0
  35. package/dist/src/config.d.ts +3 -0
  36. package/dist/src/config.d.ts.map +1 -0
  37. package/dist/src/config.js +46 -0
  38. package/dist/src/envman/cli.d.ts +21 -0
  39. package/dist/src/envman/cli.d.ts.map +1 -0
  40. package/dist/src/envman/cli.js +240 -0
  41. package/dist/src/envman/envman.d.ts +83 -0
  42. package/dist/src/envman/envman.d.ts.map +1 -0
  43. package/dist/src/envman/envman.js +361 -0
  44. package/dist/src/envman/envman.test.d.ts +5 -0
  45. package/dist/src/envman/envman.test.d.ts.map +1 -0
  46. package/dist/src/envman/envman.test.js +236 -0
  47. package/dist/src/envman/index.d.ts +23 -0
  48. package/dist/src/envman/index.d.ts.map +1 -0
  49. package/dist/src/envman/index.js +23 -0
  50. package/dist/src/envman/types.d.ts +55 -0
  51. package/dist/src/envman/types.d.ts.map +1 -0
  52. package/dist/src/envman/types.js +12 -0
  53. package/dist/src/lib.d.ts +27 -0
  54. package/dist/src/lib.d.ts.map +1 -0
  55. package/dist/src/lib.js +32 -0
  56. package/dist/src/pipeline.d.ts +3 -0
  57. package/dist/src/pipeline.d.ts.map +1 -0
  58. package/dist/src/pipeline.js +57 -0
  59. package/dist/src/runner.d.ts +17 -0
  60. package/dist/src/runner.d.ts.map +1 -0
  61. package/dist/src/runner.js +234 -0
  62. package/dist/src/types.d.ts +57 -0
  63. package/dist/src/types.d.ts.map +1 -0
  64. package/dist/src/types.js +2 -0
  65. package/dist/src/yaml/bitrise-compat.d.ts +65 -0
  66. package/dist/src/yaml/bitrise-compat.d.ts.map +1 -0
  67. package/dist/src/yaml/bitrise-compat.js +206 -0
  68. package/dist/src/yaml/bitrise-compat.test.d.ts +5 -0
  69. package/dist/src/yaml/bitrise-compat.test.d.ts.map +1 -0
  70. package/dist/src/yaml/bitrise-compat.test.js +347 -0
  71. package/dist/src/yaml/converter.d.ts +33 -0
  72. package/dist/src/yaml/converter.d.ts.map +1 -0
  73. package/dist/src/yaml/converter.js +222 -0
  74. package/dist/src/yaml/converter.test.d.ts +5 -0
  75. package/dist/src/yaml/converter.test.d.ts.map +1 -0
  76. package/dist/src/yaml/converter.test.js +348 -0
  77. package/dist/src/yaml/e2e.test.d.ts +6 -0
  78. package/dist/src/yaml/e2e.test.d.ts.map +1 -0
  79. package/dist/src/yaml/e2e.test.js +446 -0
  80. package/dist/src/yaml/env-resolver.d.ts +120 -0
  81. package/dist/src/yaml/env-resolver.d.ts.map +1 -0
  82. package/dist/src/yaml/env-resolver.js +405 -0
  83. package/dist/src/yaml/env-resolver.test.d.ts +5 -0
  84. package/dist/src/yaml/env-resolver.test.d.ts.map +1 -0
  85. package/dist/src/yaml/env-resolver.test.js +502 -0
  86. package/dist/src/yaml/interactive-prompts.d.ts +71 -0
  87. package/dist/src/yaml/interactive-prompts.d.ts.map +1 -0
  88. package/dist/src/yaml/interactive-prompts.js +258 -0
  89. package/dist/src/yaml/missing-env-handler.d.ts +45 -0
  90. package/dist/src/yaml/missing-env-handler.d.ts.map +1 -0
  91. package/dist/src/yaml/missing-env-handler.js +64 -0
  92. package/dist/src/yaml/parser.d.ts +33 -0
  93. package/dist/src/yaml/parser.d.ts.map +1 -0
  94. package/dist/src/yaml/parser.js +145 -0
  95. package/dist/src/yaml/pipeline-with-secrets.d.ts +25 -0
  96. package/dist/src/yaml/pipeline-with-secrets.d.ts.map +1 -0
  97. package/dist/src/yaml/pipeline-with-secrets.js +76 -0
  98. package/dist/src/yaml/platform-detector.d.ts +83 -0
  99. package/dist/src/yaml/platform-detector.d.ts.map +1 -0
  100. package/dist/src/yaml/platform-detector.js +188 -0
  101. package/dist/src/yaml/platform-detector.test.d.ts +5 -0
  102. package/dist/src/yaml/platform-detector.test.d.ts.map +1 -0
  103. package/dist/src/yaml/platform-detector.test.js +414 -0
  104. package/dist/src/yaml/preflight-validation.d.ts +40 -0
  105. package/dist/src/yaml/preflight-validation.d.ts.map +1 -0
  106. package/dist/src/yaml/preflight-validation.js +152 -0
  107. package/dist/src/yaml/secrets-manager.d.ts +77 -0
  108. package/dist/src/yaml/secrets-manager.d.ts.map +1 -0
  109. package/dist/src/yaml/secrets-manager.js +219 -0
  110. package/dist/src/yaml/step-validator.d.ts +54 -0
  111. package/dist/src/yaml/step-validator.d.ts.map +1 -0
  112. package/dist/src/yaml/step-validator.js +403 -0
  113. package/dist/src/yaml/steps/android-sign.d.ts +35 -0
  114. package/dist/src/yaml/steps/android-sign.d.ts.map +1 -0
  115. package/dist/src/yaml/steps/android-sign.js +147 -0
  116. package/dist/src/yaml/steps/android-version.d.ts +26 -0
  117. package/dist/src/yaml/steps/android-version.d.ts.map +1 -0
  118. package/dist/src/yaml/steps/android-version.js +128 -0
  119. package/dist/src/yaml/steps/android-version.test.d.ts +5 -0
  120. package/dist/src/yaml/steps/android-version.test.d.ts.map +1 -0
  121. package/dist/src/yaml/steps/android-version.test.js +196 -0
  122. package/dist/src/yaml/steps/android.d.ts +95 -0
  123. package/dist/src/yaml/steps/android.d.ts.map +1 -0
  124. package/dist/src/yaml/steps/android.js +916 -0
  125. package/dist/src/yaml/steps/app-store-deploy.d.ts +48 -0
  126. package/dist/src/yaml/steps/app-store-deploy.d.ts.map +1 -0
  127. package/dist/src/yaml/steps/app-store-deploy.js +162 -0
  128. package/dist/src/yaml/steps/base.d.ts +238 -0
  129. package/dist/src/yaml/steps/base.d.ts.map +1 -0
  130. package/dist/src/yaml/steps/base.js +345 -0
  131. package/dist/src/yaml/steps/bitrise-android-tools.d.ts +26 -0
  132. package/dist/src/yaml/steps/bitrise-android-tools.d.ts.map +1 -0
  133. package/dist/src/yaml/steps/bitrise-android-tools.js +198 -0
  134. package/dist/src/yaml/steps/bitrise-android-tools.test.d.ts +5 -0
  135. package/dist/src/yaml/steps/bitrise-android-tools.test.d.ts.map +1 -0
  136. package/dist/src/yaml/steps/bitrise-android-tools.test.js +280 -0
  137. package/dist/src/yaml/steps/bitrise-apk-info.d.ts +22 -0
  138. package/dist/src/yaml/steps/bitrise-apk-info.d.ts.map +1 -0
  139. package/dist/src/yaml/steps/bitrise-apk-info.js +144 -0
  140. package/dist/src/yaml/steps/bitrise-apk-info.test.d.ts +5 -0
  141. package/dist/src/yaml/steps/bitrise-apk-info.test.d.ts.map +1 -0
  142. package/dist/src/yaml/steps/bitrise-apk-info.test.js +331 -0
  143. package/dist/src/yaml/steps/bitrise-slack.d.ts +49 -0
  144. package/dist/src/yaml/steps/bitrise-slack.d.ts.map +1 -0
  145. package/dist/src/yaml/steps/bitrise-slack.js +280 -0
  146. package/dist/src/yaml/steps/bitrise-slack.test.d.ts +5 -0
  147. package/dist/src/yaml/steps/bitrise-slack.test.d.ts.map +1 -0
  148. package/dist/src/yaml/steps/bitrise-slack.test.js +484 -0
  149. package/dist/src/yaml/steps/bitrise-ssh.d.ts +27 -0
  150. package/dist/src/yaml/steps/bitrise-ssh.d.ts.map +1 -0
  151. package/dist/src/yaml/steps/bitrise-ssh.js +134 -0
  152. package/dist/src/yaml/steps/bitrise-ssh.test.d.ts +5 -0
  153. package/dist/src/yaml/steps/bitrise-ssh.test.d.ts.map +1 -0
  154. package/dist/src/yaml/steps/bitrise-ssh.test.js +205 -0
  155. package/dist/src/yaml/steps/cache.d.ts +52 -0
  156. package/dist/src/yaml/steps/cache.d.ts.map +1 -0
  157. package/dist/src/yaml/steps/cache.js +351 -0
  158. package/dist/src/yaml/steps/fastlane.d.ts +27 -0
  159. package/dist/src/yaml/steps/fastlane.d.ts.map +1 -0
  160. package/dist/src/yaml/steps/fastlane.js +79 -0
  161. package/dist/src/yaml/steps/file.d.ts +27 -0
  162. package/dist/src/yaml/steps/file.d.ts.map +1 -0
  163. package/dist/src/yaml/steps/file.js +35 -0
  164. package/dist/src/yaml/steps/flutter.d.ts +63 -0
  165. package/dist/src/yaml/steps/flutter.d.ts.map +1 -0
  166. package/dist/src/yaml/steps/flutter.js +215 -0
  167. package/dist/src/yaml/steps/git-clone.d.ts +26 -0
  168. package/dist/src/yaml/steps/git-clone.d.ts.map +1 -0
  169. package/dist/src/yaml/steps/git-clone.js +111 -0
  170. package/dist/src/yaml/steps/google-play-deploy.d.ts +37 -0
  171. package/dist/src/yaml/steps/google-play-deploy.d.ts.map +1 -0
  172. package/dist/src/yaml/steps/google-play-deploy.js +193 -0
  173. package/dist/src/yaml/steps/google-play-deploy.test.d.ts +5 -0
  174. package/dist/src/yaml/steps/google-play-deploy.test.d.ts.map +1 -0
  175. package/dist/src/yaml/steps/google-play-deploy.test.js +310 -0
  176. package/dist/src/yaml/steps/index.d.ts +10 -0
  177. package/dist/src/yaml/steps/index.d.ts.map +1 -0
  178. package/dist/src/yaml/steps/index.js +1361 -0
  179. package/dist/src/yaml/steps/ios-deps.d.ts +43 -0
  180. package/dist/src/yaml/steps/ios-deps.d.ts.map +1 -0
  181. package/dist/src/yaml/steps/ios-deps.js +141 -0
  182. package/dist/src/yaml/steps/ios-deps.test.d.ts +5 -0
  183. package/dist/src/yaml/steps/ios-deps.test.d.ts.map +1 -0
  184. package/dist/src/yaml/steps/ios-deps.test.js +90 -0
  185. package/dist/src/yaml/steps/ios-signing.d.ts +31 -0
  186. package/dist/src/yaml/steps/ios-signing.d.ts.map +1 -0
  187. package/dist/src/yaml/steps/ios-signing.js +144 -0
  188. package/dist/src/yaml/steps/ios-version.d.ts +47 -0
  189. package/dist/src/yaml/steps/ios-version.d.ts.map +1 -0
  190. package/dist/src/yaml/steps/ios-version.js +151 -0
  191. package/dist/src/yaml/steps/linting.d.ts +47 -0
  192. package/dist/src/yaml/steps/linting.d.ts.map +1 -0
  193. package/dist/src/yaml/steps/linting.js +148 -0
  194. package/dist/src/yaml/steps/phase2.test.d.ts +6 -0
  195. package/dist/src/yaml/steps/phase2.test.d.ts.map +1 -0
  196. package/dist/src/yaml/steps/phase2.test.js +197 -0
  197. package/dist/src/yaml/steps/phase3.test.d.ts +5 -0
  198. package/dist/src/yaml/steps/phase3.test.d.ts.map +1 -0
  199. package/dist/src/yaml/steps/phase3.test.js +144 -0
  200. package/dist/src/yaml/steps/phase4.test.d.ts +5 -0
  201. package/dist/src/yaml/steps/phase4.test.d.ts.map +1 -0
  202. package/dist/src/yaml/steps/phase4.test.js +166 -0
  203. package/dist/src/yaml/steps/phase5.test.d.ts +6 -0
  204. package/dist/src/yaml/steps/phase5.test.d.ts.map +1 -0
  205. package/dist/src/yaml/steps/phase5.test.js +263 -0
  206. package/dist/src/yaml/steps/registry.d.ts +88 -0
  207. package/dist/src/yaml/steps/registry.d.ts.map +1 -0
  208. package/dist/src/yaml/steps/registry.js +125 -0
  209. package/dist/src/yaml/steps/registry.test.d.ts +5 -0
  210. package/dist/src/yaml/steps/registry.test.d.ts.map +1 -0
  211. package/dist/src/yaml/steps/registry.test.js +235 -0
  212. package/dist/src/yaml/steps/release.d.ts +50 -0
  213. package/dist/src/yaml/steps/release.d.ts.map +1 -0
  214. package/dist/src/yaml/steps/release.js +154 -0
  215. package/dist/src/yaml/steps/script.d.ts +23 -0
  216. package/dist/src/yaml/steps/script.d.ts.map +1 -0
  217. package/dist/src/yaml/steps/script.js +63 -0
  218. package/dist/src/yaml/steps/spec-validation.test.d.ts +6 -0
  219. package/dist/src/yaml/steps/spec-validation.test.d.ts.map +1 -0
  220. package/dist/src/yaml/steps/spec-validation.test.js +130 -0
  221. package/dist/src/yaml/steps/steps.test.d.ts +6 -0
  222. package/dist/src/yaml/steps/steps.test.d.ts.map +1 -0
  223. package/dist/src/yaml/steps/steps.test.js +474 -0
  224. package/dist/src/yaml/steps/test-config.d.ts +3 -0
  225. package/dist/src/yaml/steps/test-config.d.ts.map +1 -0
  226. package/dist/src/yaml/steps/test-config.js +16 -0
  227. package/dist/src/yaml/steps/xcode-new.test.d.ts +5 -0
  228. package/dist/src/yaml/steps/xcode-new.test.d.ts.map +1 -0
  229. package/dist/src/yaml/steps/xcode-new.test.js +211 -0
  230. package/dist/src/yaml/steps/xcode.d.ts +222 -0
  231. package/dist/src/yaml/steps/xcode.d.ts.map +1 -0
  232. package/dist/src/yaml/steps/xcode.js +999 -0
  233. package/dist/src/yaml/types.d.ts +68 -0
  234. package/dist/src/yaml/types.d.ts.map +1 -0
  235. package/dist/src/yaml/types.js +5 -0
  236. package/dist/src/yaml/validation-types.d.ts +96 -0
  237. package/dist/src/yaml/validation-types.d.ts.map +1 -0
  238. package/dist/src/yaml/validation-types.js +8 -0
  239. package/dist/src/yaml/yaml-updater.d.ts +24 -0
  240. package/dist/src/yaml/yaml-updater.d.ts.map +1 -0
  241. package/dist/src/yaml/yaml-updater.js +128 -0
  242. package/package.json +16 -4
@@ -0,0 +1,331 @@
1
+ /**
2
+ * Unit tests for Bitrise apk-info step
3
+ */
4
+ import { describe, test, expect } from '@jest/globals';
5
+ import { BitriseApkInfoStepExecutor } from './bitrise-apk-info.js';
6
+ describe('BitriseApkInfoStepExecutor', () => {
7
+ const mockConfig = {
8
+ artifactsDir: '/ci/artifacts',
9
+ interpreters: {
10
+ python: '/usr/bin/python3',
11
+ ruby: '/usr/bin/ruby',
12
+ node: '/usr/bin/node',
13
+ bash: '/bin/bash',
14
+ },
15
+ maxConcurrentJobs: 4,
16
+ paths: {
17
+ buildsDir: '/ci/builds',
18
+ cacheDir: '/ci/cache',
19
+ derivedDataDir: '/ci/derived_data',
20
+ },
21
+ };
22
+ describe('Basic functionality', () => {
23
+ test('should create APK metadata extraction script with auto-detection', async () => {
24
+ const executor = new BitriseApkInfoStepExecutor();
25
+ const env = {};
26
+ const inputs = {};
27
+ const result = await executor.execute(inputs, env, mockConfig);
28
+ expect(result.kind).toBe('script');
29
+ expect(result.name).toBe('apk-info');
30
+ expect(result.script).toContain('Extracting APK metadata');
31
+ expect(result.script).toContain('Auto-detect APK file');
32
+ });
33
+ test('should include Bitrise mapping message', async () => {
34
+ const executor = new BitriseApkInfoStepExecutor();
35
+ const env = {};
36
+ const inputs = {};
37
+ const result = await executor.execute(inputs, env, mockConfig);
38
+ expect(result.script).toContain('Bitrise apk-info step → CI Build APK metadata extraction');
39
+ });
40
+ });
41
+ describe('APK path handling', () => {
42
+ test('should use apk_path when provided', async () => {
43
+ const executor = new BitriseApkInfoStepExecutor();
44
+ const env = {};
45
+ const inputs = {
46
+ apk_path: './app/build/outputs/apk/release/app-release.apk',
47
+ };
48
+ const result = await executor.execute(inputs, env, mockConfig);
49
+ expect(result.script).toContain('./app/build/outputs/apk/release/app-release.apk');
50
+ expect(result.script).toContain('User specified APK path');
51
+ });
52
+ test('should error if specified APK file not found', async () => {
53
+ const executor = new BitriseApkInfoStepExecutor();
54
+ const env = {};
55
+ const inputs = {
56
+ apk_path: './nonexistent.apk',
57
+ };
58
+ const result = await executor.execute(inputs, env, mockConfig);
59
+ expect(result.script).toContain('if [ ! -f "$APK_FILE" ]; then');
60
+ expect(result.script).toContain('APK file not found');
61
+ expect(result.script).toContain('exit 1');
62
+ });
63
+ });
64
+ describe('APK auto-detection', () => {
65
+ test('should auto-detect APK in build/outputs/apk/', async () => {
66
+ const executor = new BitriseApkInfoStepExecutor();
67
+ const env = {};
68
+ const inputs = {};
69
+ const result = await executor.execute(inputs, env, mockConfig);
70
+ expect(result.script).toContain('if [ -d "build/outputs/apk" ]; then');
71
+ expect(result.script).toContain('Auto-detect APK file in build/outputs/apk/');
72
+ });
73
+ test('should find most recently modified APK', async () => {
74
+ const executor = new BitriseApkInfoStepExecutor();
75
+ const env = {};
76
+ const inputs = {};
77
+ const result = await executor.execute(inputs, env, mockConfig);
78
+ expect(result.script).toContain('find build/outputs/apk -name "*.apk"');
79
+ expect(result.script).toContain('ls -t | head -n 1');
80
+ expect(result.script).toContain('most recently modified');
81
+ });
82
+ test('should error if no APK files found', async () => {
83
+ const executor = new BitriseApkInfoStepExecutor();
84
+ const env = {};
85
+ const inputs = {};
86
+ const result = await executor.execute(inputs, env, mockConfig);
87
+ expect(result.script).toContain('No APK files found in build/outputs/apk/');
88
+ expect(result.script).toContain('exit 1');
89
+ });
90
+ test('should error if build/outputs/apk/ directory not found', async () => {
91
+ const executor = new BitriseApkInfoStepExecutor();
92
+ const env = {};
93
+ const inputs = {};
94
+ const result = await executor.execute(inputs, env, mockConfig);
95
+ expect(result.script).toContain('build/outputs/apk/ directory not found');
96
+ expect(result.script).toContain('Please specify apk_path input');
97
+ });
98
+ });
99
+ describe('aapt/aapt2 detection', () => {
100
+ test('should check for aapt2 first', async () => {
101
+ const executor = new BitriseApkInfoStepExecutor();
102
+ const env = {};
103
+ const inputs = {};
104
+ const result = await executor.execute(inputs, env, mockConfig);
105
+ expect(result.script).toContain('if command -v aapt2 >/dev/null 2>&1; then');
106
+ expect(result.script).toContain('AAPT_CMD="aapt2"');
107
+ expect(result.script).toContain('Using aapt2 for APK analysis');
108
+ });
109
+ test('should fall back to aapt if aapt2 not found', async () => {
110
+ const executor = new BitriseApkInfoStepExecutor();
111
+ const env = {};
112
+ const inputs = {};
113
+ const result = await executor.execute(inputs, env, mockConfig);
114
+ expect(result.script).toContain('elif command -v aapt >/dev/null 2>&1; then');
115
+ expect(result.script).toContain('AAPT_CMD="aapt"');
116
+ expect(result.script).toContain('Using aapt for APK analysis');
117
+ });
118
+ test('should error if neither aapt nor aapt2 found', async () => {
119
+ const executor = new BitriseApkInfoStepExecutor();
120
+ const env = {};
121
+ const inputs = {};
122
+ const result = await executor.execute(inputs, env, mockConfig);
123
+ expect(result.script).toContain('aapt or aapt2 not found');
124
+ expect(result.script).toContain('Install Android SDK build-tools');
125
+ expect(result.script).toContain('exit 1');
126
+ });
127
+ });
128
+ describe('Metadata extraction', () => {
129
+ test('should run aapt dump badging', async () => {
130
+ const executor = new BitriseApkInfoStepExecutor();
131
+ const env = {};
132
+ const inputs = {};
133
+ const result = await executor.execute(inputs, env, mockConfig);
134
+ expect(result.script).toContain('$AAPT_CMD dump badging "$APK_FILE"');
135
+ expect(result.script).toContain('AAPT_OUTPUT=');
136
+ });
137
+ test('should extract package name', async () => {
138
+ const executor = new BitriseApkInfoStepExecutor();
139
+ const env = {};
140
+ const inputs = {};
141
+ const result = await executor.execute(inputs, env, mockConfig);
142
+ expect(result.script).toContain('# Extract package name');
143
+ expect(result.script).toContain('PACKAGE_NAME=');
144
+ expect(result.script).toContain('echo "Package name: $PACKAGE_NAME"');
145
+ });
146
+ test('should extract version code', async () => {
147
+ const executor = new BitriseApkInfoStepExecutor();
148
+ const env = {};
149
+ const inputs = {};
150
+ const result = await executor.execute(inputs, env, mockConfig);
151
+ expect(result.script).toContain('# Extract version code');
152
+ expect(result.script).toContain('VERSION_CODE=');
153
+ expect(result.script).toContain('echo "Version code: $VERSION_CODE"');
154
+ });
155
+ test('should extract version name', async () => {
156
+ const executor = new BitriseApkInfoStepExecutor();
157
+ const env = {};
158
+ const inputs = {};
159
+ const result = await executor.execute(inputs, env, mockConfig);
160
+ expect(result.script).toContain('# Extract version name');
161
+ expect(result.script).toContain('VERSION_NAME=');
162
+ expect(result.script).toContain('echo "Version name: $VERSION_NAME"');
163
+ });
164
+ test('should extract minimum SDK version', async () => {
165
+ const executor = new BitriseApkInfoStepExecutor();
166
+ const env = {};
167
+ const inputs = {};
168
+ const result = await executor.execute(inputs, env, mockConfig);
169
+ expect(result.script).toContain('# Extract minimum SDK version');
170
+ expect(result.script).toContain('MIN_SDK=');
171
+ expect(result.script).toContain('echo "Minimum SDK: $MIN_SDK"');
172
+ });
173
+ test('should extract target SDK version', async () => {
174
+ const executor = new BitriseApkInfoStepExecutor();
175
+ const env = {};
176
+ const inputs = {};
177
+ const result = await executor.execute(inputs, env, mockConfig);
178
+ expect(result.script).toContain('# Extract target SDK version');
179
+ expect(result.script).toContain('TARGET_SDK=');
180
+ expect(result.script).toContain('echo "Target SDK: $TARGET_SDK"');
181
+ });
182
+ });
183
+ describe('File size display', () => {
184
+ test('should display file size in human-readable format', async () => {
185
+ const executor = new BitriseApkInfoStepExecutor();
186
+ const env = {};
187
+ const inputs = {};
188
+ const result = await executor.execute(inputs, env, mockConfig);
189
+ expect(result.script).toContain('du -h "$APK_FILE"');
190
+ expect(result.script).toContain('FILE_SIZE=');
191
+ expect(result.script).toContain('echo "Size: $FILE_SIZE"');
192
+ });
193
+ test('should display file path', async () => {
194
+ const executor = new BitriseApkInfoStepExecutor();
195
+ const env = {};
196
+ const inputs = {};
197
+ const result = await executor.execute(inputs, env, mockConfig);
198
+ expect(result.script).toContain('echo "File: $APK_FILE"');
199
+ });
200
+ });
201
+ describe('Environment variable export', () => {
202
+ test('should export APK_FILE_PATH', async () => {
203
+ const executor = new BitriseApkInfoStepExecutor();
204
+ const env = {};
205
+ const inputs = {};
206
+ const result = await executor.execute(inputs, env, mockConfig);
207
+ expect(result.script).toContain('export APK_FILE_PATH="$APK_FILE"');
208
+ expect(result.script).toContain('APK_FILE_PATH=$APK_FILE_PATH');
209
+ });
210
+ test('should export APK_PACKAGE_NAME', async () => {
211
+ const executor = new BitriseApkInfoStepExecutor();
212
+ const env = {};
213
+ const inputs = {};
214
+ const result = await executor.execute(inputs, env, mockConfig);
215
+ expect(result.script).toContain('export APK_PACKAGE_NAME="$PACKAGE_NAME"');
216
+ expect(result.script).toContain('APK_PACKAGE_NAME=$APK_PACKAGE_NAME');
217
+ });
218
+ test('should export APK_VERSION_CODE', async () => {
219
+ const executor = new BitriseApkInfoStepExecutor();
220
+ const env = {};
221
+ const inputs = {};
222
+ const result = await executor.execute(inputs, env, mockConfig);
223
+ expect(result.script).toContain('export APK_VERSION_CODE="$VERSION_CODE"');
224
+ expect(result.script).toContain('APK_VERSION_CODE=$APK_VERSION_CODE');
225
+ });
226
+ test('should export APK_VERSION_NAME', async () => {
227
+ const executor = new BitriseApkInfoStepExecutor();
228
+ const env = {};
229
+ const inputs = {};
230
+ const result = await executor.execute(inputs, env, mockConfig);
231
+ expect(result.script).toContain('export APK_VERSION_NAME="$VERSION_NAME"');
232
+ expect(result.script).toContain('APK_VERSION_NAME=$APK_VERSION_NAME');
233
+ });
234
+ test('should export APK_MIN_SDK', async () => {
235
+ const executor = new BitriseApkInfoStepExecutor();
236
+ const env = {};
237
+ const inputs = {};
238
+ const result = await executor.execute(inputs, env, mockConfig);
239
+ expect(result.script).toContain('export APK_MIN_SDK="$MIN_SDK"');
240
+ expect(result.script).toContain('APK_MIN_SDK=$APK_MIN_SDK');
241
+ });
242
+ test('should export APK_TARGET_SDK', async () => {
243
+ const executor = new BitriseApkInfoStepExecutor();
244
+ const env = {};
245
+ const inputs = {};
246
+ const result = await executor.execute(inputs, env, mockConfig);
247
+ expect(result.script).toContain('export APK_TARGET_SDK="$TARGET_SDK"');
248
+ expect(result.script).toContain('APK_TARGET_SDK=$APK_TARGET_SDK');
249
+ });
250
+ test('should display exported variables', async () => {
251
+ const executor = new BitriseApkInfoStepExecutor();
252
+ const env = {};
253
+ const inputs = {};
254
+ const result = await executor.execute(inputs, env, mockConfig);
255
+ expect(result.script).toContain('Exported environment variables:');
256
+ expect(result.script).toContain('Exporting metadata as environment variables');
257
+ });
258
+ });
259
+ describe('Output formatting', () => {
260
+ test('should include formatted APK information header', async () => {
261
+ const executor = new BitriseApkInfoStepExecutor();
262
+ const env = {};
263
+ const inputs = {};
264
+ const result = await executor.execute(inputs, env, mockConfig);
265
+ expect(result.script).toContain('APK Information');
266
+ expect(result.script).toContain('╔═══════════════════════════════════════════════╗');
267
+ expect(result.script).toContain('╚═══════════════════════════════════════════════╝');
268
+ });
269
+ });
270
+ describe('Script structure', () => {
271
+ test('should include bash error handling directives', async () => {
272
+ const executor = new BitriseApkInfoStepExecutor();
273
+ const env = {};
274
+ const inputs = {};
275
+ const result = await executor.execute(inputs, env, mockConfig);
276
+ expect(result.script).toContain('#!/bin/bash');
277
+ expect(result.script).toContain('set -e');
278
+ expect(result.script).toContain('set -o pipefail');
279
+ });
280
+ test('should include informative messages', async () => {
281
+ const executor = new BitriseApkInfoStepExecutor();
282
+ const env = {};
283
+ const inputs = {};
284
+ const result = await executor.execute(inputs, env, mockConfig);
285
+ expect(result.script).toContain('Extracting APK metadata');
286
+ expect(result.script).toContain('APK metadata extracted successfully');
287
+ });
288
+ });
289
+ describe('Integration scenarios', () => {
290
+ test('should work with custom APK path', async () => {
291
+ const executor = new BitriseApkInfoStepExecutor();
292
+ const env = {};
293
+ const inputs = {
294
+ apk_path: './custom/path/my-app.apk',
295
+ };
296
+ const result = await executor.execute(inputs, env, mockConfig);
297
+ expect(result.kind).toBe('script');
298
+ expect(result.script).toContain('./custom/path/my-app.apk');
299
+ expect(result.script).toContain('aapt');
300
+ });
301
+ test('should work with minimal configuration (auto-detect)', async () => {
302
+ const executor = new BitriseApkInfoStepExecutor();
303
+ const env = {};
304
+ const inputs = {};
305
+ const result = await executor.execute(inputs, env, mockConfig);
306
+ expect(result.kind).toBe('script');
307
+ expect(result.script).toContain('Auto-detect APK file');
308
+ expect(result.script).toContain('build/outputs/apk');
309
+ });
310
+ });
311
+ describe('Bitrise compatibility', () => {
312
+ test('should map to CI Build APK metadata extraction pattern', async () => {
313
+ const executor = new BitriseApkInfoStepExecutor();
314
+ const env = {};
315
+ const inputs = {};
316
+ const result = await executor.execute(inputs, env, mockConfig);
317
+ expect(result.script).toContain('CI Build APK metadata extraction');
318
+ });
319
+ test('should support Bitrise input naming conventions', async () => {
320
+ const executor = new BitriseApkInfoStepExecutor();
321
+ const env = {};
322
+ const inputs = {
323
+ apk_path: './app.apk',
324
+ };
325
+ const result = await executor.execute(inputs, env, mockConfig);
326
+ expect(result.script).toBeDefined();
327
+ expect(result.kind).toBe('script');
328
+ });
329
+ });
330
+ });
331
+ //# sourceMappingURL=bitrise-apk-info.test.js.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Bitrise slack step implementation
3
+ * Maps Bitrise slack@* to CI Build Slack notification
4
+ */
5
+ import { BaseStepExecutor } from './base.js';
6
+ import type { StepDef, CIConfig } from '../../types.js';
7
+ import type { ValidationRequirement } from '../validation-types.js';
8
+ /**
9
+ * Inputs for slack step
10
+ */
11
+ export interface BitriseSlackInputs {
12
+ webhook_url?: string;
13
+ text?: string;
14
+ message?: string;
15
+ channel?: string;
16
+ from_username?: string;
17
+ icon_emoji?: string;
18
+ icon_url?: string;
19
+ color?: string;
20
+ pretext?: string;
21
+ author_name?: string;
22
+ title?: string;
23
+ title_link?: string;
24
+ message_on_error?: string;
25
+ fields?: string;
26
+ buttons?: string;
27
+ footer?: string;
28
+ footer_icon?: string;
29
+ timestamp?: string;
30
+ is_debug_mode?: string;
31
+ }
32
+ /**
33
+ * Bitrise slack step executor (FR-5)
34
+ * Sends Slack notifications via webhook
35
+ *
36
+ * Supports Bitrise step versions: slack@1, @2, @3, @4
37
+ */
38
+ export declare class BitriseSlackStepExecutor extends BaseStepExecutor {
39
+ isSkippedInLocalMode(): boolean;
40
+ getValidationRequirements(inputs: BitriseSlackInputs, env: Record<string, string>, config: CIConfig): ValidationRequirement[];
41
+ execute(inputs: BitriseSlackInputs, env: Record<string, string>, config: CIConfig): Promise<StepDef>;
42
+ /**
43
+ * Escapes a string for safe inclusion in JSON
44
+ * @param str String to escape
45
+ * @returns Escaped string safe for JSON
46
+ */
47
+ private escapeJson;
48
+ }
49
+ //# sourceMappingURL=bitrise-slack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitrise-slack.d.ts","sourceRoot":"","sources":["../../../../src/yaml/steps/bitrise-slack.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,qBAAa,wBAAyB,SAAQ,gBAAgB;IAC5D,oBAAoB,IAAI,OAAO;IAI/B,yBAAyB,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAG,qBAAqB,EAAE;IAsDvH,OAAO,CAAC,MAAM,EAAE,kBAAkB,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IA8O1G;;;;OAIG;IACH,OAAO,CAAC,UAAU;CAQnB"}
@@ -0,0 +1,280 @@
1
+ /**
2
+ * Bitrise slack step implementation
3
+ * Maps Bitrise slack@* to CI Build Slack notification
4
+ */
5
+ import { BaseStepExecutor } from './base.js';
6
+ import { MissingEnvironmentVariableError } from '../env-resolver.js';
7
+ /**
8
+ * Bitrise slack step executor (FR-5)
9
+ * Sends Slack notifications via webhook
10
+ *
11
+ * Supports Bitrise step versions: slack@1, @2, @3, @4
12
+ */
13
+ export class BitriseSlackStepExecutor extends BaseStepExecutor {
14
+ isSkippedInLocalMode() {
15
+ return true;
16
+ }
17
+ getValidationRequirements(inputs, env, config) {
18
+ if (config.local)
19
+ return [];
20
+ const requirements = [];
21
+ const webhookUrl = this.getInput(inputs, 'webhook_url', '') || env.SLACK_WEBHOOK_URL || '';
22
+ if (!webhookUrl) {
23
+ requirements.push({
24
+ category: 'environment',
25
+ name: 'SLACK_WEBHOOK_URL',
26
+ description: 'Slack webhook URL for sending build notifications',
27
+ timing: 'pre-execution',
28
+ severity: 'error',
29
+ hint: 'Slack webhook URL for sending build notifications to your Slack workspace.\n\n' +
30
+ 'Expected format:\n' +
31
+ ' ┌────────────────────────────────────────────────────────┐\n' +
32
+ ' │ https://hooks.slack.com/services/T00000000/B00000000/ │\n' +
33
+ ' │ XXXXXXXXXXXXXXXXXXXXXXXX │\n' +
34
+ ' └────────────────────────────────────────────────────────┘\n\n' +
35
+ 'How to get it:\n' +
36
+ ' • Visit: https://api.slack.com/messaging/webhooks\n' +
37
+ ' • Or: Slack App Settings → Incoming Webhooks\n' +
38
+ ' • Create a new webhook for your channel\n' +
39
+ ' • Copy the webhook URL',
40
+ check: async () => ({ passed: false, message: 'SLACK_WEBHOOK_URL is not set' }),
41
+ });
42
+ }
43
+ const channel = env.SLACK_CHANNEL || this.getInput(inputs, 'channel', '');
44
+ if (!channel) {
45
+ requirements.push({
46
+ category: 'environment',
47
+ name: 'SLACK_CHANNEL',
48
+ description: 'Slack channel to post notifications to (e.g. #builds)',
49
+ timing: 'pre-execution',
50
+ severity: 'error',
51
+ hint: 'Slack channel to post the build notification to (e.g. #builds or #ci-alerts)',
52
+ check: async () => ({ passed: false, message: 'SLACK_CHANNEL is not set (optional)' }),
53
+ });
54
+ }
55
+ // CIBUILD_PUBLIC_INSTALL_PAGE_URL is auto-generated at runtime by a distribution step.
56
+ // Declare it as runtime so auto-discovery doesn't prompt for it — slack handles it gracefully.
57
+ requirements.push({
58
+ category: 'environment',
59
+ name: 'CIBUILD_PUBLIC_INSTALL_PAGE_URL',
60
+ description: 'Public install page URL (auto-generated at runtime)',
61
+ timing: 'runtime',
62
+ severity: 'info',
63
+ });
64
+ return requirements;
65
+ }
66
+ async execute(inputs, env, config) {
67
+ const stepName = 'slack';
68
+ if (config.local) {
69
+ const script = this.createBashScriptFromCommands(['echo "⏭️ slack: skipped in local mode"'], stepName);
70
+ return this.createScriptStep(script, stepName);
71
+ }
72
+ // Get webhook URL - this is required (FR-5.2)
73
+ const webhookUrl = this.getInput(inputs, 'webhook_url', '') || env.SLACK_WEBHOOK_URL || '';
74
+ if (!webhookUrl) {
75
+ throw new MissingEnvironmentVariableError('SLACK_WEBHOOK_URL', stepName, 'Slack webhook URL for sending build notifications to your Slack workspace.\n\n' +
76
+ 'Expected format:\n' +
77
+ ' ┌────────────────────────────────────────────────────────┐\n' +
78
+ ' │ https://hooks.slack.com/services/T00000000/B00000000/ │\n' +
79
+ ' │ XXXXXXXXXXXXXXXXXXXXXXXX │\n' +
80
+ ' └────────────────────────────────────────────────────────┘\n\n' +
81
+ 'How to get it:\n' +
82
+ ' • Visit: https://api.slack.com/messaging/webhooks\n' +
83
+ ' • Or: Slack App Settings → Incoming Webhooks\n' +
84
+ ' • Create a new webhook for your channel\n' +
85
+ ' • Copy the webhook URL');
86
+ }
87
+ // Get message content - prefer 'text' over 'message' (FR-5.2)
88
+ let messageText = this.getInput(inputs, 'text', '') || this.getInput(inputs, 'message', '') || 'CI Build build notification';
89
+ // Get optional formatting fields - allow env var overrides (FR-5.2)
90
+ // Environment variables can override YAML inputs for runtime configuration
91
+ const channel = env.SLACK_CHANNEL || this.getInput(inputs, 'channel', '');
92
+ const username = env.SLACK_USERNAME || this.getInput(inputs, 'from_username', 'CI Build');
93
+ const iconEmoji = env.SLACK_ICON_EMOJI || this.getInput(inputs, 'icon_emoji', '');
94
+ const iconUrl = env.SLACK_ICON_URL || this.getInput(inputs, 'icon_url', '');
95
+ const color = env.SLACK_COLOR || this.getInput(inputs, 'color', 'good');
96
+ const pretext = env.SLACK_PRETEXT || this.getInput(inputs, 'pretext', '');
97
+ const authorName = env.SLACK_AUTHOR_NAME || this.getInput(inputs, 'author_name', '');
98
+ const title = env.SLACK_TITLE || this.getInput(inputs, 'title', '');
99
+ const titleLink = env.SLACK_TITLE_LINK || this.getInput(inputs, 'title_link', '');
100
+ const footer = env.SLACK_FOOTER || this.getInput(inputs, 'footer', '');
101
+ const footerIcon = env.SLACK_FOOTER_ICON || this.getInput(inputs, 'footer_icon', '');
102
+ const timestamp = this.getInput(inputs, 'timestamp', '');
103
+ const fields = this.getInput(inputs, 'fields', '');
104
+ const buttons = this.getInput(inputs, 'buttons', '');
105
+ // Debug mode
106
+ const isDebugMode = this.getInput(inputs, 'is_debug_mode', '');
107
+ const commands = [];
108
+ commands.push('# Bitrise slack step → CI Build Slack notification');
109
+ commands.push('echo "📋 Sending Slack notification..."');
110
+ commands.push('');
111
+ // Convert buttons to clickable links in bash (where envman variables are available)
112
+ // Buttons format: "Label|URL\nLabel|URL"
113
+ commands.push('# Parse buttons and interpolate URLs with current environment');
114
+ commands.push('BUTTON_LINKS=""');
115
+ if (buttons) {
116
+ // Pass buttons as base64 to avoid escaping issues
117
+ const buttonsB64 = Buffer.from(buttons).toString('base64');
118
+ commands.push(`BUTTONS_DATA=$(echo "${buttonsB64}" | base64 -d)`);
119
+ commands.push('');
120
+ commands.push('# Process each button line');
121
+ commands.push('while IFS="|" read -r label url; do');
122
+ commands.push(' [ -z "$label" ] && continue');
123
+ commands.push(' ');
124
+ commands.push(' # Handle different URL formats:');
125
+ commands.push(' # 1. If empty (variable was interpolated to empty at YAML parse time), try common variables');
126
+ commands.push(' # 2. If starts with http/https, use directly (may contain ${} to interpolate)');
127
+ commands.push(' # 3. Otherwise, try to expand it as a variable reference');
128
+ commands.push(' url_interpolated=""');
129
+ commands.push(' ');
130
+ commands.push(' if [ -z "$url" ]; then');
131
+ commands.push(' # Empty URL - check if this is the Install button which needs CIBUILD_PUBLIC_INSTALL_PAGE_URL');
132
+ commands.push(' if [ "$label" = "Install" ] && [ -n "$CIBUILD_PUBLIC_INSTALL_PAGE_URL" ]; then');
133
+ commands.push(' url_interpolated="$CIBUILD_PUBLIC_INSTALL_PAGE_URL"');
134
+ commands.push(' fi');
135
+ commands.push(' elif [[ "$url" =~ ^https?:// ]]; then');
136
+ commands.push(' # It\'s a URL - interpolate any ${VAR} in it');
137
+ commands.push(' url_interpolated=$(eval echo "$url")');
138
+ commands.push(' else');
139
+ commands.push(' # Not a URL - might be a variable name, try to expand it');
140
+ commands.push(' url_interpolated=$(eval echo "$url")');
141
+ commands.push(' fi');
142
+ commands.push(' ');
143
+ commands.push(' # Only add button if URL is not empty');
144
+ commands.push(' if [ -n "$url_interpolated" ]; then');
145
+ commands.push(' # Slack markdown format: <url|label>');
146
+ commands.push(' if [ -z "$BUTTON_LINKS" ]; then');
147
+ commands.push(' BUTTON_LINKS="<$url_interpolated|$label>"');
148
+ commands.push(' else');
149
+ commands.push(' BUTTON_LINKS="$BUTTON_LINKS • <$url_interpolated|$label>"');
150
+ commands.push(' fi');
151
+ commands.push(' fi');
152
+ commands.push('done <<< "$BUTTONS_DATA"');
153
+ commands.push('');
154
+ }
155
+ // Append button links to message text
156
+ commands.push('# Append button links to message text if any');
157
+ commands.push(`SLACK_MESSAGE_TEXT="${this.escapeJson(messageText)}"`);
158
+ commands.push('if [ -n "$BUTTON_LINKS" ]; then');
159
+ commands.push(' # Escape button links for JSON (backslashes and quotes)');
160
+ commands.push(' BUTTON_LINKS_ESCAPED=$(echo "$BUTTON_LINKS" | sed \'s/\\\\/\\\\\\\\/g\' | sed \'s/"/\\\\"/g\')');
161
+ commands.push(' SLACK_MESSAGE_TEXT="$SLACK_MESSAGE_TEXT\\\\n\\\\n$BUTTON_LINKS_ESCAPED"');
162
+ commands.push('fi');
163
+ commands.push('');
164
+ // Build JSON payload (FR-5.3, FR-5.4)
165
+ commands.push('# Build Slack message JSON payload');
166
+ commands.push('cat > /tmp/slack-payload.json << SLACK_EOF');
167
+ // Start JSON object
168
+ const jsonLines = ['{'];
169
+ // Add basic fields
170
+ if (channel) {
171
+ jsonLines.push(` "channel": "${this.escapeJson(channel)}",`);
172
+ }
173
+ jsonLines.push(` "username": "${this.escapeJson(username)}",`);
174
+ if (iconEmoji) {
175
+ jsonLines.push(` "icon_emoji": "${this.escapeJson(iconEmoji)}",`);
176
+ }
177
+ if (iconUrl) {
178
+ jsonLines.push(` "icon_url": "${this.escapeJson(iconUrl)}",`);
179
+ }
180
+ // Add attachment with message content
181
+ jsonLines.push(' "attachments": [');
182
+ jsonLines.push(' {');
183
+ jsonLines.push(` "color": "${this.escapeJson(color)}",`);
184
+ if (pretext) {
185
+ jsonLines.push(` "pretext": "${this.escapeJson(pretext)}",`);
186
+ }
187
+ if (authorName) {
188
+ jsonLines.push(` "author_name": "${this.escapeJson(authorName)}",`);
189
+ }
190
+ if (title) {
191
+ jsonLines.push(` "title": "${this.escapeJson(title)}",`);
192
+ }
193
+ if (titleLink) {
194
+ jsonLines.push(` "title_link": "${this.escapeJson(titleLink)}",`);
195
+ }
196
+ // Use SLACK_MESSAGE_TEXT variable which includes button links
197
+ jsonLines.push(` "text": "$SLACK_MESSAGE_TEXT",`);
198
+ if (footer) {
199
+ jsonLines.push(` "footer": "${this.escapeJson(footer)}",`);
200
+ }
201
+ if (footerIcon) {
202
+ jsonLines.push(` "footer_icon": "${this.escapeJson(footerIcon)}",`);
203
+ }
204
+ if (timestamp) {
205
+ jsonLines.push(` "ts": ${timestamp},`);
206
+ }
207
+ // Add fields if provided (FR-5.2)
208
+ if (fields) {
209
+ jsonLines.push(` "fields": ${fields},`);
210
+ }
211
+ // Note: Buttons/actions are not supported in Slack incoming webhooks
212
+ // They require the interactive messages API which is different from webhooks
213
+ // Commenting out to avoid 400 errors
214
+ // if (buttons) {
215
+ // jsonLines.push(` "actions": ${buttons},`);
216
+ // }
217
+ // Remove trailing comma from last line
218
+ const lastLine = jsonLines[jsonLines.length - 1];
219
+ if (lastLine.endsWith(',')) {
220
+ jsonLines[jsonLines.length - 1] = lastLine.slice(0, -1);
221
+ }
222
+ jsonLines.push(' }');
223
+ jsonLines.push(' ]');
224
+ jsonLines.push('}');
225
+ commands.push(jsonLines.join('\n'));
226
+ commands.push('SLACK_EOF');
227
+ commands.push('');
228
+ // Show payload in debug mode
229
+ if (isDebugMode === 'true' || isDebugMode === 'yes') {
230
+ commands.push('# Debug: Display payload');
231
+ commands.push('echo "Slack payload:"');
232
+ commands.push('cat /tmp/slack-payload.json');
233
+ commands.push('echo ""');
234
+ commands.push('');
235
+ }
236
+ // Send to Slack webhook (FR-5.3)
237
+ commands.push('# Send POST request to Slack webhook');
238
+ commands.push(`SLACK_RESPONSE=$(curl -X POST "${this.escapeBash(webhookUrl)}" \\`);
239
+ commands.push(' -H "Content-Type: application/json" \\');
240
+ commands.push(' -d @/tmp/slack-payload.json \\');
241
+ commands.push(' -w "\\n%{http_code}" \\');
242
+ commands.push(' --silent)');
243
+ commands.push('');
244
+ commands.push('# Extract HTTP status code and response body');
245
+ commands.push('HTTP_CODE=$(echo "$SLACK_RESPONSE" | tail -n1)');
246
+ commands.push('RESPONSE_BODY=$(echo "$SLACK_RESPONSE" | sed \'$d\')');
247
+ commands.push('');
248
+ // Check result
249
+ commands.push('if [ "$HTTP_CODE" = "200" ] || [ "$RESPONSE_BODY" = "ok" ]; then');
250
+ commands.push(' echo "✅ Slack notification sent successfully"');
251
+ commands.push('else');
252
+ commands.push(' echo "❌ Failed to send Slack notification (HTTP $HTTP_CODE)"');
253
+ commands.push(' echo "Response: $RESPONSE_BODY"');
254
+ commands.push(' echo ""');
255
+ commands.push(' echo "Payload that was sent:"');
256
+ commands.push(' cat /tmp/slack-payload.json');
257
+ commands.push(' exit 1');
258
+ commands.push('fi');
259
+ commands.push('');
260
+ // Cleanup
261
+ commands.push('# Cleanup temporary file');
262
+ commands.push('rm -f /tmp/slack-payload.json');
263
+ const script = this.createBashScriptFromCommands(commands, stepName);
264
+ return this.createScriptStep(script, stepName);
265
+ }
266
+ /**
267
+ * Escapes a string for safe inclusion in JSON
268
+ * @param str String to escape
269
+ * @returns Escaped string safe for JSON
270
+ */
271
+ escapeJson(str) {
272
+ return str
273
+ .replace(/\\/g, '\\\\') // Backslash
274
+ .replace(/"/g, '\\"') // Quote
275
+ .replace(/\n/g, '\\n') // Newline
276
+ .replace(/\r/g, '\\r') // Carriage return
277
+ .replace(/\t/g, '\\t'); // Tab
278
+ }
279
+ }
280
+ //# sourceMappingURL=bitrise-slack.js.map