@codfish/actions 1.1.0 → 2.0.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.
@@ -17,13 +17,13 @@ teardown() {
17
17
  # Test tag generation logic from action
18
18
  TAG_INPUT="test-tag"
19
19
  MESSAGE_INPUT="Hello, World!"
20
-
20
+
21
21
  bash -c "
22
22
  tag=\"<!-- codfish/actions/comment $TAG_INPUT -->\"
23
23
  echo \"Generated tag: \$tag\"
24
24
  echo \"tag=\$tag\"
25
25
  " > output.txt
26
-
26
+
27
27
  assert_output_contains "tag=<!-- codfish/actions/comment test-tag -->" "$(cat output.txt)"
28
28
  }
29
29
 
@@ -32,13 +32,13 @@ teardown() {
32
32
  MESSAGE_INPUT="Line 1
33
33
  Line 2
34
34
  Line 3"
35
-
35
+
36
36
  bash -c '
37
37
  body=$(printf "$1")
38
38
  echo "Processed message:"
39
39
  echo "$body"
40
40
  ' -- "$MESSAGE_INPUT" > output.txt
41
-
41
+
42
42
  assert_output_contains "Line 1" "$(cat output.txt)"
43
43
  assert_output_contains "Line 2" "$(cat output.txt)"
44
44
  assert_output_contains "Line 3" "$(cat output.txt)"
@@ -52,13 +52,13 @@ Line 3"
52
52
  - Item 2
53
53
 
54
54
  **Bold text** and *italic text*"
55
-
55
+
56
56
  bash -c '
57
57
  body=$(printf "$1")
58
58
  echo "Markdown message:"
59
59
  echo "$body"
60
60
  ' -- "$MESSAGE_INPUT" > output.txt
61
-
61
+
62
62
  assert_output_contains "## Test Header" "$(cat output.txt)"
63
63
  assert_output_contains "- Item 1" "$(cat output.txt)"
64
64
  assert_output_contains "**Bold text**" "$(cat output.txt)"
@@ -68,7 +68,7 @@ Line 3"
68
68
  # Test complete body generation
69
69
  TAG_INPUT="build-status"
70
70
  MESSAGE_INPUT="✅ Build successful!"
71
-
71
+
72
72
  bash -c "
73
73
  tag=\"<!-- codfish/actions/comment $TAG_INPUT -->\"
74
74
  body=\$(printf '$MESSAGE_INPUT')
@@ -76,7 +76,7 @@ Line 3"
76
76
  echo \"\$body\"
77
77
  echo \"\$tag\"
78
78
  " > output.txt
79
-
79
+
80
80
  assert_output_contains "✅ Build successful!" "$(cat output.txt)"
81
81
  assert_output_contains "<!-- codfish/actions/comment build-status -->" "$(cat output.txt)"
82
82
  }
@@ -85,11 +85,11 @@ Line 3"
85
85
  # Test with empty tag
86
86
  TAG_INPUT=""
87
87
  MESSAGE_INPUT="Message without tag"
88
-
88
+
89
89
  bash -c "
90
90
  tag=\"<!-- codfish/actions/comment $TAG_INPUT -->\"
91
91
  echo \"Tag with empty input: \$tag\"
92
92
  " > output.txt
93
-
93
+
94
94
  assert_output_contains "<!-- codfish/actions/comment -->" "$(cat output.txt)"
95
- }
95
+ }
@@ -16,32 +16,32 @@ teardown() {
16
16
  @test "npm-pr-version: generates correct PR version format" {
17
17
  # Setup test repo
18
18
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
19
-
19
+
20
20
  # Mock npm command
21
21
  mock_npm_publish
22
-
22
+
23
23
  # Set PR and SHA environment variables
24
24
  export PR=123
25
25
  export SHA="abcdef1234567890"
26
-
26
+
27
27
  # Test version generation logic
28
28
  bash -c '
29
29
  version="0.0.0-PR-${PR}--$(echo ${SHA} | cut -c -7)"
30
30
  echo "Generated version: $version"
31
31
  echo "version=$version"
32
32
  ' > output.txt
33
-
33
+
34
34
  assert_output_contains "version=0.0.0-PR-123--abcdef1" "$(cat output.txt)"
35
35
  }
36
36
 
37
37
  @test "npm-pr-version: updates package.json version" {
38
38
  # Setup test repo
39
39
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
40
-
40
+
41
41
  # Set environment variables
42
42
  export PR=456
43
43
  export SHA="fedcba0987654321"
44
-
44
+
45
45
  # Test version update in package.json
46
46
  bash -c '
47
47
  version="0.0.0-PR-${PR}--$(echo ${SHA} | cut -c -7)"
@@ -49,7 +49,7 @@ teardown() {
49
49
  echo "Updated package.json:"
50
50
  cat package.json | grep "\"version\""
51
51
  ' > output.txt 2>/dev/null || echo "npm version failed" > output.txt
52
-
52
+
53
53
  # Check if version was updated (npm version command may not be available in test env)
54
54
  if grep -q "npm version failed" output.txt; then
55
55
  # Fallback: test with manual JSON update
@@ -60,17 +60,17 @@ teardown() {
60
60
  cat package.json | grep "\"version\""
61
61
  ' > output.txt
62
62
  fi
63
-
63
+
64
64
  assert_output_contains "0.0.0-PR-456--fedcba0" "$(cat output.txt)"
65
65
  }
66
66
 
67
67
  @test "npm-pr-version: handles scoped packages" {
68
68
  # Setup test repo with scoped package
69
69
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/scoped.json" package.json
70
-
70
+
71
71
  export PR=789
72
72
  export SHA="1234567890abcdef"
73
-
73
+
74
74
  # Test with scoped package
75
75
  bash -c '
76
76
  version="0.0.0-PR-${PR}--$(echo ${SHA} | cut -c -7)"
@@ -78,7 +78,7 @@ teardown() {
78
78
  echo "Testing scoped package:"
79
79
  cat package.json | grep "\"name\""
80
80
  ' > output.txt
81
-
81
+
82
82
  assert_output_contains "version=0.0.0-PR-789--1234567" "$(cat output.txt)"
83
83
  assert_output_contains "@test-org/scoped-package" "$(cat output.txt)"
84
84
  }
@@ -87,10 +87,10 @@ teardown() {
87
87
  # Setup test repo with yarn lockfile
88
88
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
89
89
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/yarn.lock" .
90
-
90
+
91
91
  export PR=456
92
92
  export SHA="fedcba0987654321"
93
-
93
+
94
94
  # Test package manager detection
95
95
  bash -c '
96
96
  if [ -f "./yarn.lock" ]; then
@@ -105,7 +105,7 @@ teardown() {
105
105
  fi
106
106
  echo "package-manager=$package_manager"
107
107
  ' > output.txt
108
-
108
+
109
109
  assert_output_contains "package-manager=yarn" "$(cat output.txt)"
110
110
  assert_output_contains "Detected package manager: yarn" "$(cat output.txt)"
111
111
  }
@@ -114,10 +114,10 @@ teardown() {
114
114
  # Setup test repo with pnpm lockfile
115
115
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
116
116
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/pnpm-lock.yaml" .
117
-
117
+
118
118
  export PR=789
119
119
  export SHA="1234567890abcdef"
120
-
120
+
121
121
  # Test package manager detection
122
122
  bash -c '
123
123
  if [ -f "./yarn.lock" ]; then
@@ -132,7 +132,7 @@ teardown() {
132
132
  fi
133
133
  echo "package-manager=$package_manager"
134
134
  ' > output.txt
135
-
135
+
136
136
  assert_output_contains "package-manager=pnpm" "$(cat output.txt)"
137
137
  assert_output_contains "Detected package manager: pnpm" "$(cat output.txt)"
138
138
  }
@@ -141,7 +141,7 @@ teardown() {
141
141
  # Test without package.json
142
142
  export PR=999
143
143
  export SHA="testsha123456789"
144
-
144
+
145
145
  # This should fail
146
146
  bash -c '
147
147
  if [ ! -f "package.json" ]; then
@@ -149,7 +149,7 @@ teardown() {
149
149
  exit 1
150
150
  fi
151
151
  ' > output.txt 2>&1 || echo "exit-code=$?" >> output.txt
152
-
152
+
153
153
  assert_output_contains "ERROR: package.json not found" "$(cat output.txt)"
154
154
  }
155
155
 
@@ -162,7 +162,7 @@ teardown() {
162
162
  fi
163
163
  echo "comment=$comment_input"
164
164
  ' > output.txt
165
-
165
+
166
166
  assert_output_contains "comment=true" "$(cat output.txt)"
167
167
  }
168
168
 
@@ -171,7 +171,7 @@ teardown() {
171
171
  bash -c '
172
172
  comment_input="false"
173
173
  echo "comment=$comment_input"
174
-
174
+
175
175
  # Simulate conditional comment step
176
176
  if [ "$comment_input" = "true" ]; then
177
177
  echo "Would create comment"
@@ -179,7 +179,7 @@ teardown() {
179
179
  echo "Skipping comment creation"
180
180
  fi
181
181
  ' > output.txt
182
-
182
+
183
183
  assert_output_contains "comment=false" "$(cat output.txt)"
184
184
  assert_output_contains "Skipping comment creation" "$(cat output.txt)"
185
185
  }
@@ -193,7 +193,7 @@ teardown() {
193
193
  fi
194
194
  echo "comment-tag=$comment_tag_input"
195
195
  ' > output.txt
196
-
196
+
197
197
  assert_output_contains "comment-tag=npm-publish-pr" "$(cat output.txt)"
198
198
  }
199
199
 
@@ -202,11 +202,11 @@ teardown() {
202
202
  bash -c '
203
203
  comment_tag_input="my-custom-tag"
204
204
  echo "comment-tag=$comment_tag_input"
205
-
205
+
206
206
  # Simulate using custom tag in comment action
207
207
  echo "Using tag: $comment_tag_input for PR comment"
208
208
  ' > output.txt
209
-
209
+
210
210
  assert_output_contains "comment-tag=my-custom-tag" "$(cat output.txt)"
211
211
  assert_output_contains "Using tag: my-custom-tag for PR comment" "$(cat output.txt)"
212
212
  }
@@ -216,10 +216,10 @@ teardown() {
216
216
  bash -c '
217
217
  comment_input="false"
218
218
  comment_tag_input="custom-npm-publish"
219
-
219
+
220
220
  echo "comment=$comment_input"
221
221
  echo "comment-tag=$comment_tag_input"
222
-
222
+
223
223
  # Simulate the conditional logic from action.yml
224
224
  if [ "$comment_input" = "true" ]; then
225
225
  echo "Would use codfish/actions/comment@main with tag: $comment_tag_input"
@@ -227,7 +227,7 @@ teardown() {
227
227
  echo "Comment step skipped due to comment=false"
228
228
  fi
229
229
  ' > output.txt
230
-
230
+
231
231
  assert_output_contains "comment=false" "$(cat output.txt)"
232
232
  assert_output_contains "comment-tag=custom-npm-publish" "$(cat output.txt)"
233
233
  assert_output_contains "Comment step skipped due to comment=false" "$(cat output.txt)"
@@ -239,21 +239,21 @@ teardown() {
239
239
  comment_input="true"
240
240
  comment_tag_input="npm-publish-pr"
241
241
  publish_success="true"
242
-
242
+
243
243
  echo "comment=$comment_input"
244
244
  echo "comment-tag=$comment_tag_input"
245
-
245
+
246
246
  # Simulate before comment
247
247
  if [ "$comment_input" = "true" ]; then
248
248
  echo "Before: Publishing PR version..."
249
249
  fi
250
-
250
+
251
251
  # Simulate publish step
252
252
  if [ "$publish_success" = "true" ]; then
253
253
  echo "Publish: SUCCESS"
254
254
  package_name="test-package"
255
255
  version="0.0.0-PR-123--abc1234"
256
-
256
+
257
257
  # Simulate success comment
258
258
  if [ "$comment_input" = "true" ]; then
259
259
  echo "After: PR package published successfully! Install with: npm install $package_name@$version"
@@ -261,14 +261,14 @@ teardown() {
261
261
  else
262
262
  echo "Publish: FAILED"
263
263
  error_message="Failed to publish"
264
-
264
+
265
265
  # Simulate error comment
266
266
  if [ "$comment_input" = "true" ]; then
267
267
  echo "After: PR package publish failed! Error: $error_message"
268
268
  fi
269
269
  fi
270
270
  ' > output.txt
271
-
271
+
272
272
  assert_output_contains "Before: Publishing PR version..." "$(cat output.txt)"
273
273
  assert_output_contains "Publish: SUCCESS" "$(cat output.txt)"
274
274
  assert_output_contains "After: PR package published successfully!" "$(cat output.txt)"
@@ -281,29 +281,29 @@ teardown() {
281
281
  comment_input="true"
282
282
  comment_tag_input="npm-publish-pr"
283
283
  publish_success="false"
284
-
284
+
285
285
  echo "comment=$comment_input"
286
286
  echo "comment-tag=$comment_tag_input"
287
-
287
+
288
288
  # Simulate before comment
289
289
  if [ "$comment_input" = "true" ]; then
290
290
  echo "Before: Publishing PR version..."
291
291
  fi
292
-
292
+
293
293
  # Simulate publish step failure
294
294
  if [ "$publish_success" = "true" ]; then
295
295
  echo "Publish: SUCCESS"
296
296
  else
297
297
  echo "Publish: FAILED"
298
298
  error_message="Failed to publish package with npm. Error: E403 Forbidden"
299
-
299
+
300
300
  # Simulate error comment
301
301
  if [ "$comment_input" = "true" ]; then
302
302
  echo "After: PR package publish failed! Error: $error_message"
303
303
  fi
304
304
  fi
305
305
  ' > output.txt
306
-
306
+
307
307
  assert_output_contains "Before: Publishing PR version..." "$(cat output.txt)"
308
308
  assert_output_contains "Publish: FAILED" "$(cat output.txt)"
309
309
  assert_output_contains "After: PR package publish failed!" "$(cat output.txt)"
@@ -313,20 +313,20 @@ teardown() {
313
313
  @test "npm-pr-version: error handling with package name extraction" {
314
314
  # Setup test repo with package.json
315
315
  cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
316
-
316
+
317
317
  # Test error message generation with package name
318
318
  bash -c '
319
319
  # Simulate package name extraction
320
320
  if [ -f "package.json" ]; then
321
321
  package_name=$(jq -r ".name // empty" package.json)
322
322
  echo "package-name=$package_name"
323
-
323
+
324
324
  # Simulate error scenario
325
325
  error_message="❌ ERROR: Failed to publish package with npm. Error: E403 Forbidden - you must be logged in"
326
326
  echo "error-message=$error_message"
327
327
  fi
328
328
  ' > output.txt
329
-
329
+
330
330
  assert_output_contains "package-name=test-package" "$(cat output.txt)"
331
331
  assert_output_contains "error-message=❌ ERROR: Failed to publish package with npm" "$(cat output.txt)"
332
332
  assert_output_contains "E403 Forbidden" "$(cat output.txt)"
@@ -336,18 +336,103 @@ teardown() {
336
336
  # Test npm version error handling with output capture
337
337
  bash -c '
338
338
  version="invalid-version"
339
-
339
+
340
340
  # Simulate npm version command failure with output
341
341
  version_output="npm ERR! Invalid version: \"invalid-version\""
342
342
  version_exit_code=1
343
-
343
+
344
344
  if [ $version_exit_code -ne 0 ]; then
345
345
  error_message="❌ ERROR: Failed to update package version. Check if the version format is valid. Error: $version_output"
346
346
  echo "error-message=$error_message"
347
347
  fi
348
348
  ' > output.txt
349
-
349
+
350
350
  assert_output_contains "error-message=❌ ERROR: Failed to update package version" "$(cat output.txt)"
351
351
  assert_output_contains "Check if the version format is valid" "$(cat output.txt)"
352
352
  assert_output_contains "npm ERR! Invalid version" "$(cat output.txt)"
353
- }
353
+ }
354
+
355
+ @test "npm-pr-version: error message sanitization" {
356
+ # Test that multi-line error messages are properly sanitized
357
+ bash -c '
358
+ # Define sanitize_error function
359
+ sanitize_error() {
360
+ local message="$1"
361
+ echo "$message" | tr '"'"'\n'"'"' '"'"' '"'"' | tr -s '"'"' '"'"' | cut -c1-500
362
+ }
363
+
364
+ # Simulate multi-line pnpm error
365
+ publish_output="ERR_PNPM_GIT_UNCLEAN Unclean working tree. Commit or stash changes first.
366
+ If you want to disable Git checks on publish, set the \"git-checks\" setting to \"false\", or run again with \"--no-git-checks\"."
367
+
368
+ error_message="❌ ERROR: Failed to publish package with pnpm. Error: $publish_output"
369
+ sanitized=$(sanitize_error "$error_message")
370
+
371
+ echo "raw-error=$error_message"
372
+ echo "sanitized-error=$sanitized"
373
+ ' > output.txt
374
+
375
+ # Check that sanitized version has no newlines and is truncated
376
+ sanitized_line=$(grep "^sanitized-error=" output.txt)
377
+
378
+ # Should not contain literal newlines in the sanitized output
379
+ assert_output_contains "sanitized-error=❌ ERROR: Failed to publish package with pnpm" "$(cat output.txt)"
380
+ assert_output_contains "ERR_PNPM_GIT_UNCLEAN" "$(cat output.txt)"
381
+
382
+ # Verify no newlines in sanitized version (count lines should be 1)
383
+ newline_count=$(echo "$sanitized_line" | wc -l)
384
+ [ "$newline_count" -eq 1 ]
385
+ }
386
+
387
+ @test "npm-pr-version: workflow link in error comment" {
388
+ # Test that error comment includes workflow link
389
+ bash -c '
390
+ # Simulate GitHub environment variables
391
+ GITHUB_SERVER_URL="https://github.com"
392
+ GITHUB_REPOSITORY="owner/repo"
393
+ GITHUB_RUN_ID="12345678"
394
+
395
+ # Simulate error comment with workflow link
396
+ error_message="Failed to publish"
397
+
398
+ # Generate comment like the action would
399
+ comment_message="❌ **PR package publish failed!**
400
+
401
+ Error: $error_message
402
+
403
+ 📋 [View workflow logs]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID) for more details."
404
+
405
+ echo "comment-message=$comment_message"
406
+ ' > output.txt
407
+
408
+ assert_output_contains "📋 [View workflow logs]" "$(cat output.txt)"
409
+ assert_output_contains "https://github.com/owner/repo/actions/runs/12345678" "$(cat output.txt)"
410
+ assert_output_contains "for more details." "$(cat output.txt)"
411
+ }
412
+
413
+ @test "npm-pr-version: commits package.json after version update" {
414
+ # Test that package.json is committed after npm version to keep git clean
415
+ bash -c '
416
+ # Simulate the version update and git commit workflow
417
+ echo "Simulating npm version update..."
418
+ echo "package.json modified"
419
+
420
+ # Simulate git configuration and commit (as per action.yml)
421
+ echo "Configuring git user..."
422
+ echo "git config user.name github-actions[bot]"
423
+ echo "git config user.email github-actions[bot]@users.noreply.github.com"
424
+ echo "Committing package.json changes..."
425
+ echo "git add package.json"
426
+ echo "git commit -m ci: update package version"
427
+ echo "working-tree=clean"
428
+
429
+ # This prevents pnpm/yarn git checks from failing
430
+ echo "pnpm-ready=true"
431
+ ' > output.txt
432
+
433
+ assert_output_contains "git config user.name github-actions[bot]" "$(cat output.txt)"
434
+ assert_output_contains "git add package.json" "$(cat output.txt)"
435
+ assert_output_contains "git commit -m ci: update package version" "$(cat output.txt)"
436
+ assert_output_contains "working-tree=clean" "$(cat output.txt)"
437
+ assert_output_contains "pnpm-ready=true" "$(cat output.txt)"
438
+ }