@codfish/actions 2.0.1 → 3.3.1

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 (37) hide show
  1. package/README.md +135 -64
  2. package/bin/generate-docs.js +10 -10
  3. package/comment/README.md +9 -9
  4. package/comment/action.yml +3 -3
  5. package/npm-publish-pr/README.md +319 -40
  6. package/npm-publish-pr/action.yml +271 -87
  7. package/package.json +19 -14
  8. package/setup-node-and-install/README.md +77 -34
  9. package/setup-node-and-install/action.yml +36 -3
  10. package/.github/codeql-config.yml +0 -21
  11. package/.github/dependabot.yml +0 -35
  12. package/.github/workflows/claude-code-review.yml +0 -43
  13. package/.github/workflows/claude.yml +0 -38
  14. package/.github/workflows/release.yml +0 -48
  15. package/.github/workflows/security.yml +0 -103
  16. package/.github/workflows/update-docs.yml +0 -38
  17. package/.github/workflows/validate.yml +0 -210
  18. package/.husky/pre-commit +0 -1
  19. package/.nvmrc +0 -1
  20. package/AGENT.md +0 -149
  21. package/CLAUDE.md +0 -3
  22. package/CONTRIBUTING.md +0 -316
  23. package/SECURITY.md +0 -208
  24. package/eslint.config.js +0 -8
  25. package/tests/fixtures/.node-version +0 -1
  26. package/tests/fixtures/.nvmrc +0 -1
  27. package/tests/fixtures/lockfiles/package-lock.json +0 -12
  28. package/tests/fixtures/lockfiles/pnpm-lock.yaml +0 -9
  29. package/tests/fixtures/lockfiles/yarn.lock +0 -7
  30. package/tests/fixtures/package-json/minimal.json +0 -4
  31. package/tests/fixtures/package-json/scoped.json +0 -6
  32. package/tests/fixtures/package-json/valid.json +0 -13
  33. package/tests/integration/comment/basic.bats +0 -95
  34. package/tests/integration/npm-pr-version/basic.bats +0 -438
  35. package/tests/integration/setup-node-and-install/basic.bats +0 -638
  36. package/tests/scripts/test-helpers.sh +0 -113
  37. package/tests/scripts/test-runner.sh +0 -115
@@ -1,438 +0,0 @@
1
- #!/usr/bin/env bats
2
-
3
- load "../../scripts/test-helpers.sh"
4
-
5
- setup() {
6
- setup_github_env
7
- TEST_DIR=$(mktemp -d)
8
- cd "$TEST_DIR"
9
- }
10
-
11
- teardown() {
12
- cd /
13
- cleanup_test_env "$TEST_DIR"
14
- }
15
-
16
- @test "npm-pr-version: generates correct PR version format" {
17
- # Setup test repo
18
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
19
-
20
- # Mock npm command
21
- mock_npm_publish
22
-
23
- # Set PR and SHA environment variables
24
- export PR=123
25
- export SHA="abcdef1234567890"
26
-
27
- # Test version generation logic
28
- bash -c '
29
- version="0.0.0-PR-${PR}--$(echo ${SHA} | cut -c -7)"
30
- echo "Generated version: $version"
31
- echo "version=$version"
32
- ' > output.txt
33
-
34
- assert_output_contains "version=0.0.0-PR-123--abcdef1" "$(cat output.txt)"
35
- }
36
-
37
- @test "npm-pr-version: updates package.json version" {
38
- # Setup test repo
39
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
40
-
41
- # Set environment variables
42
- export PR=456
43
- export SHA="fedcba0987654321"
44
-
45
- # Test version update in package.json
46
- bash -c '
47
- version="0.0.0-PR-${PR}--$(echo ${SHA} | cut -c -7)"
48
- npm version $version --no-git-tag-version
49
- echo "Updated package.json:"
50
- cat package.json | grep "\"version\""
51
- ' > output.txt 2>/dev/null || echo "npm version failed" > output.txt
52
-
53
- # Check if version was updated (npm version command may not be available in test env)
54
- if grep -q "npm version failed" output.txt; then
55
- # Fallback: test with manual JSON update
56
- bash -c '
57
- version="0.0.0-PR-456--fedcba0"
58
- # Simulate version update
59
- sed -i.bak "s/\"version\": \"[^\"]*\"/\"version\": \"$version\"/" package.json
60
- cat package.json | grep "\"version\""
61
- ' > output.txt
62
- fi
63
-
64
- assert_output_contains "0.0.0-PR-456--fedcba0" "$(cat output.txt)"
65
- }
66
-
67
- @test "npm-pr-version: handles scoped packages" {
68
- # Setup test repo with scoped package
69
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/scoped.json" package.json
70
-
71
- export PR=789
72
- export SHA="1234567890abcdef"
73
-
74
- # Test with scoped package
75
- bash -c '
76
- version="0.0.0-PR-${PR}--$(echo ${SHA} | cut -c -7)"
77
- echo "version=$version"
78
- echo "Testing scoped package:"
79
- cat package.json | grep "\"name\""
80
- ' > output.txt
81
-
82
- assert_output_contains "version=0.0.0-PR-789--1234567" "$(cat output.txt)"
83
- assert_output_contains "@test-org/scoped-package" "$(cat output.txt)"
84
- }
85
-
86
- @test "npm-pr-version: detects yarn package manager" {
87
- # Setup test repo with yarn lockfile
88
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
89
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/yarn.lock" .
90
-
91
- export PR=456
92
- export SHA="fedcba0987654321"
93
-
94
- # Test package manager detection
95
- bash -c '
96
- if [ -f "./yarn.lock" ]; then
97
- package_manager="yarn"
98
- echo "Detected package manager: yarn"
99
- elif [ -f "./pnpm-lock.yaml" ]; then
100
- package_manager="pnpm"
101
- echo "Detected package manager: pnpm"
102
- else
103
- package_manager="npm"
104
- echo "Detected package manager: npm"
105
- fi
106
- echo "package-manager=$package_manager"
107
- ' > output.txt
108
-
109
- assert_output_contains "package-manager=yarn" "$(cat output.txt)"
110
- assert_output_contains "Detected package manager: yarn" "$(cat output.txt)"
111
- }
112
-
113
- @test "npm-pr-version: detects pnpm package manager" {
114
- # Setup test repo with pnpm lockfile
115
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
116
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/lockfiles/pnpm-lock.yaml" .
117
-
118
- export PR=789
119
- export SHA="1234567890abcdef"
120
-
121
- # Test package manager detection
122
- bash -c '
123
- if [ -f "./yarn.lock" ]; then
124
- package_manager="yarn"
125
- echo "Detected package manager: yarn"
126
- elif [ -f "./pnpm-lock.yaml" ]; then
127
- package_manager="pnpm"
128
- echo "Detected package manager: pnpm"
129
- else
130
- package_manager="npm"
131
- echo "Detected package manager: npm"
132
- fi
133
- echo "package-manager=$package_manager"
134
- ' > output.txt
135
-
136
- assert_output_contains "package-manager=pnpm" "$(cat output.txt)"
137
- assert_output_contains "Detected package manager: pnpm" "$(cat output.txt)"
138
- }
139
-
140
- @test "npm-pr-version: requires package.json" {
141
- # Test without package.json
142
- export PR=999
143
- export SHA="testsha123456789"
144
-
145
- # This should fail
146
- bash -c '
147
- if [ ! -f "package.json" ]; then
148
- echo "ERROR: package.json not found"
149
- exit 1
150
- fi
151
- ' > output.txt 2>&1 || echo "exit-code=$?" >> output.txt
152
-
153
- assert_output_contains "ERROR: package.json not found" "$(cat output.txt)"
154
- }
155
-
156
- @test "npm-pr-version: comment input defaults to true" {
157
- # Test that comment input defaults to 'true' when not specified
158
- bash -c '
159
- comment_input=""
160
- if [ -z "$comment_input" ]; then
161
- comment_input="true"
162
- fi
163
- echo "comment=$comment_input"
164
- ' > output.txt
165
-
166
- assert_output_contains "comment=true" "$(cat output.txt)"
167
- }
168
-
169
- @test "npm-pr-version: comment input can be set to false" {
170
- # Test that comment input can be explicitly set to false
171
- bash -c '
172
- comment_input="false"
173
- echo "comment=$comment_input"
174
-
175
- # Simulate conditional comment step
176
- if [ "$comment_input" = "true" ]; then
177
- echo "Would create comment"
178
- else
179
- echo "Skipping comment creation"
180
- fi
181
- ' > output.txt
182
-
183
- assert_output_contains "comment=false" "$(cat output.txt)"
184
- assert_output_contains "Skipping comment creation" "$(cat output.txt)"
185
- }
186
-
187
- @test "npm-pr-version: comment-tag input defaults to npm-publish-pr" {
188
- # Test that comment-tag input defaults to 'npm-publish-pr' when not specified
189
- bash -c '
190
- comment_tag_input=""
191
- if [ -z "$comment_tag_input" ]; then
192
- comment_tag_input="npm-publish-pr"
193
- fi
194
- echo "comment-tag=$comment_tag_input"
195
- ' > output.txt
196
-
197
- assert_output_contains "comment-tag=npm-publish-pr" "$(cat output.txt)"
198
- }
199
-
200
- @test "npm-pr-version: comment-tag input can be customized" {
201
- # Test that comment-tag input can be set to custom value
202
- bash -c '
203
- comment_tag_input="my-custom-tag"
204
- echo "comment-tag=$comment_tag_input"
205
-
206
- # Simulate using custom tag in comment action
207
- echo "Using tag: $comment_tag_input for PR comment"
208
- ' > output.txt
209
-
210
- assert_output_contains "comment-tag=my-custom-tag" "$(cat output.txt)"
211
- assert_output_contains "Using tag: my-custom-tag for PR comment" "$(cat output.txt)"
212
- }
213
-
214
- @test "npm-pr-version: comment workflow with custom tag" {
215
- # Test complete workflow with comment disabled and custom tag
216
- bash -c '
217
- comment_input="false"
218
- comment_tag_input="custom-npm-publish"
219
-
220
- echo "comment=$comment_input"
221
- echo "comment-tag=$comment_tag_input"
222
-
223
- # Simulate the conditional logic from action.yml
224
- if [ "$comment_input" = "true" ]; then
225
- echo "Would use codfish/actions/comment@main with tag: $comment_tag_input"
226
- else
227
- echo "Comment step skipped due to comment=false"
228
- fi
229
- ' > output.txt
230
-
231
- assert_output_contains "comment=false" "$(cat output.txt)"
232
- assert_output_contains "comment-tag=custom-npm-publish" "$(cat output.txt)"
233
- assert_output_contains "Comment step skipped due to comment=false" "$(cat output.txt)"
234
- }
235
-
236
- @test "npm-pr-version: before/after commenting workflow" {
237
- # Test that before/after commenting logic works correctly
238
- bash -c '
239
- comment_input="true"
240
- comment_tag_input="npm-publish-pr"
241
- publish_success="true"
242
-
243
- echo "comment=$comment_input"
244
- echo "comment-tag=$comment_tag_input"
245
-
246
- # Simulate before comment
247
- if [ "$comment_input" = "true" ]; then
248
- echo "Before: Publishing PR version..."
249
- fi
250
-
251
- # Simulate publish step
252
- if [ "$publish_success" = "true" ]; then
253
- echo "Publish: SUCCESS"
254
- package_name="test-package"
255
- version="0.0.0-PR-123--abc1234"
256
-
257
- # Simulate success comment
258
- if [ "$comment_input" = "true" ]; then
259
- echo "After: PR package published successfully! Install with: npm install $package_name@$version"
260
- fi
261
- else
262
- echo "Publish: FAILED"
263
- error_message="Failed to publish"
264
-
265
- # Simulate error comment
266
- if [ "$comment_input" = "true" ]; then
267
- echo "After: PR package publish failed! Error: $error_message"
268
- fi
269
- fi
270
- ' > output.txt
271
-
272
- assert_output_contains "Before: Publishing PR version..." "$(cat output.txt)"
273
- assert_output_contains "Publish: SUCCESS" "$(cat output.txt)"
274
- assert_output_contains "After: PR package published successfully!" "$(cat output.txt)"
275
- assert_output_contains "npm install test-package@0.0.0-PR-123--abc1234" "$(cat output.txt)"
276
- }
277
-
278
- @test "npm-pr-version: error handling and comment update" {
279
- # Test error handling workflow
280
- bash -c '
281
- comment_input="true"
282
- comment_tag_input="npm-publish-pr"
283
- publish_success="false"
284
-
285
- echo "comment=$comment_input"
286
- echo "comment-tag=$comment_tag_input"
287
-
288
- # Simulate before comment
289
- if [ "$comment_input" = "true" ]; then
290
- echo "Before: Publishing PR version..."
291
- fi
292
-
293
- # Simulate publish step failure
294
- if [ "$publish_success" = "true" ]; then
295
- echo "Publish: SUCCESS"
296
- else
297
- echo "Publish: FAILED"
298
- error_message="Failed to publish package with npm. Error: E403 Forbidden"
299
-
300
- # Simulate error comment
301
- if [ "$comment_input" = "true" ]; then
302
- echo "After: PR package publish failed! Error: $error_message"
303
- fi
304
- fi
305
- ' > output.txt
306
-
307
- assert_output_contains "Before: Publishing PR version..." "$(cat output.txt)"
308
- assert_output_contains "Publish: FAILED" "$(cat output.txt)"
309
- assert_output_contains "After: PR package publish failed!" "$(cat output.txt)"
310
- assert_output_contains "Error: Failed to publish package with npm. Error: E403 Forbidden" "$(cat output.txt)"
311
- }
312
-
313
- @test "npm-pr-version: error handling with package name extraction" {
314
- # Setup test repo with package.json
315
- cp "$BATS_TEST_DIRNAME/../../../tests/fixtures/package-json/valid.json" package.json
316
-
317
- # Test error message generation with package name
318
- bash -c '
319
- # Simulate package name extraction
320
- if [ -f "package.json" ]; then
321
- package_name=$(jq -r ".name // empty" package.json)
322
- echo "package-name=$package_name"
323
-
324
- # Simulate error scenario
325
- error_message="❌ ERROR: Failed to publish package with npm. Error: E403 Forbidden - you must be logged in"
326
- echo "error-message=$error_message"
327
- fi
328
- ' > output.txt
329
-
330
- assert_output_contains "package-name=test-package" "$(cat output.txt)"
331
- assert_output_contains "error-message=❌ ERROR: Failed to publish package with npm" "$(cat output.txt)"
332
- assert_output_contains "E403 Forbidden" "$(cat output.txt)"
333
- }
334
-
335
- @test "npm-pr-version: npm version error capture" {
336
- # Test npm version error handling with output capture
337
- bash -c '
338
- version="invalid-version"
339
-
340
- # Simulate npm version command failure with output
341
- version_output="npm ERR! Invalid version: \"invalid-version\""
342
- version_exit_code=1
343
-
344
- if [ $version_exit_code -ne 0 ]; then
345
- error_message="❌ ERROR: Failed to update package version. Check if the version format is valid. Error: $version_output"
346
- echo "error-message=$error_message"
347
- fi
348
- ' > output.txt
349
-
350
- assert_output_contains "error-message=❌ ERROR: Failed to update package version" "$(cat output.txt)"
351
- assert_output_contains "Check if the version format is valid" "$(cat output.txt)"
352
- assert_output_contains "npm ERR! Invalid version" "$(cat output.txt)"
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
- }