@ronaldphilipsen/local-action 0.0.0-stage → 7.0.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 (223) hide show
  1. package/.checkov.yml +3 -0
  2. package/.env.example +379 -0
  3. package/.github/codeql/codeql-config.yml +7 -0
  4. package/.github/copilot-instructions.md +79 -0
  5. package/.github/dependabot.yml +32 -0
  6. package/.github/workflows/codeql-analysis.yml +53 -0
  7. package/.github/workflows/continuous-delivery.yml +93 -0
  8. package/.github/workflows/continuous-integration.yml +382 -0
  9. package/.github/workflows/linter.yml +47 -0
  10. package/.github/workflows/release.yaml +100 -0
  11. package/.github/workflows/version-check.yml +44 -0
  12. package/.grype.yml +151 -0
  13. package/.markdown-lint.yml +7 -0
  14. package/.mega-linter.yml +188 -0
  15. package/.node-version +1 -0
  16. package/.prettierignore +4 -0
  17. package/.prettierrc.yml +14 -0
  18. package/.vscode/launch.json +15 -0
  19. package/.vscode/mcp.json +9 -0
  20. package/.vscode/settings.json +15 -0
  21. package/.vscode/tasks.json +51 -0
  22. package/.yaml-lint.yml +10 -0
  23. package/CHANGELOG.md +75 -0
  24. package/CODEOWNERS +3 -0
  25. package/CODE_OF_CONDUCT.md +74 -0
  26. package/CONTRIBUTING.md +140 -0
  27. package/LICENSE +21 -0
  28. package/README.md +277 -2
  29. package/SECURITY.md +42 -0
  30. package/SUPPORT.md +19 -0
  31. package/__fixtures__/@actions/core.ts +14 -0
  32. package/__fixtures__/@actions/exec.ts +9 -0
  33. package/__fixtures__/@actions/github.ts +3 -0
  34. package/__fixtures__/@actions/http-client.ts +9 -0
  35. package/__fixtures__/@actions/io.ts +9 -0
  36. package/__fixtures__/@octokit/rest.ts +18 -0
  37. package/__fixtures__/crypto.ts +7 -0
  38. package/__fixtures__/fs.ts +27 -0
  39. package/__fixtures__/javascript/no-export/.env.fixture +2 -0
  40. package/__fixtures__/javascript/no-export/action.yml +16 -0
  41. package/__fixtures__/javascript/no-export/node_modules/.gitkeep +0 -0
  42. package/__fixtures__/javascript/no-export/package.json +12 -0
  43. package/__fixtures__/javascript/no-export/src/index.js +0 -0
  44. package/__fixtures__/javascript/no-export/src/main.js +0 -0
  45. package/__fixtures__/javascript/no-import/.env.fixture +2 -0
  46. package/__fixtures__/javascript/no-import/action.yml +16 -0
  47. package/__fixtures__/javascript/no-import/node_modules/.gitkeep +0 -0
  48. package/__fixtures__/javascript/no-import/package.json +12 -0
  49. package/__fixtures__/javascript/no-import/src/index.js +3 -0
  50. package/__fixtures__/javascript/no-import/src/main.js +7 -0
  51. package/__fixtures__/javascript/success/.env.fixture +2 -0
  52. package/__fixtures__/javascript/success/action.yml +16 -0
  53. package/__fixtures__/javascript/success/node_modules/.gitkeep +0 -0
  54. package/__fixtures__/javascript/success/package.json +12 -0
  55. package/__fixtures__/javascript/success/post/index.js +3 -0
  56. package/__fixtures__/javascript/success/post/main.js +13 -0
  57. package/__fixtures__/javascript/success/pre/index.js +3 -0
  58. package/__fixtures__/javascript/success/pre/main.js +13 -0
  59. package/__fixtures__/javascript/success/src/index.js +3 -0
  60. package/__fixtures__/javascript/success/src/main.js +13 -0
  61. package/__fixtures__/javascript-esm/no-import/.env.fixture +2 -0
  62. package/__fixtures__/javascript-esm/no-import/action.yml +16 -0
  63. package/__fixtures__/javascript-esm/no-import/node_modules/.gitkeep +0 -0
  64. package/__fixtures__/javascript-esm/no-import/package.json +13 -0
  65. package/__fixtures__/javascript-esm/no-import/src/index.js +3 -0
  66. package/__fixtures__/javascript-esm/no-import/src/main.js +7 -0
  67. package/__fixtures__/javascript-esm/success/.env.fixture +2 -0
  68. package/__fixtures__/javascript-esm/success/action.yml +16 -0
  69. package/__fixtures__/javascript-esm/success/node_modules/.gitkeep +0 -0
  70. package/__fixtures__/javascript-esm/success/package.json +13 -0
  71. package/__fixtures__/javascript-esm/success/post/index.js +3 -0
  72. package/__fixtures__/javascript-esm/success/post/main.js +13 -0
  73. package/__fixtures__/javascript-esm/success/pre/index.js +3 -0
  74. package/__fixtures__/javascript-esm/success/pre/main.js +13 -0
  75. package/__fixtures__/javascript-esm/success/src/index.js +3 -0
  76. package/__fixtures__/javascript-esm/success/src/main.js +13 -0
  77. package/__fixtures__/path.ts +7 -0
  78. package/__fixtures__/payloads/issue_opened.json +33 -0
  79. package/__fixtures__/stream/promises.ts +3 -0
  80. package/__fixtures__/tsconfig-paths.ts +4 -0
  81. package/__fixtures__/typescript/no-import/.env.fixture +2 -0
  82. package/__fixtures__/typescript/no-import/action.yml +16 -0
  83. package/__fixtures__/typescript/no-import/node_modules/.gitkeep +0 -0
  84. package/__fixtures__/typescript/no-import/package.json +15 -0
  85. package/__fixtures__/typescript/no-import/src/index.ts +3 -0
  86. package/__fixtures__/typescript/no-import/src/main.ts +3 -0
  87. package/__fixtures__/typescript/no-import/tsconfig.json +20 -0
  88. package/__fixtures__/typescript/success/.env.fixture +2 -0
  89. package/__fixtures__/typescript/success/action.yml +16 -0
  90. package/__fixtures__/typescript/success/node_modules/.gitkeep +0 -0
  91. package/__fixtures__/typescript/success/package.json +15 -0
  92. package/__fixtures__/typescript/success/post/index.ts +3 -0
  93. package/__fixtures__/typescript/success/post/main.ts +9 -0
  94. package/__fixtures__/typescript/success/pre/index.ts +3 -0
  95. package/__fixtures__/typescript/success/pre/main.ts +9 -0
  96. package/__fixtures__/typescript/success/src/index.ts +3 -0
  97. package/__fixtures__/typescript/success/src/main.ts +9 -0
  98. package/__fixtures__/typescript/success/tsconfig.json +20 -0
  99. package/__fixtures__/typescript/success-yaml/.env.fixture +2 -0
  100. package/__fixtures__/typescript/success-yaml/action.yaml +16 -0
  101. package/__fixtures__/typescript/success-yaml/node_modules/.gitkeep +0 -0
  102. package/__fixtures__/typescript/success-yaml/package.json +15 -0
  103. package/__fixtures__/typescript/success-yaml/post/index.ts +3 -0
  104. package/__fixtures__/typescript/success-yaml/post/main.ts +9 -0
  105. package/__fixtures__/typescript/success-yaml/pre/index.ts +3 -0
  106. package/__fixtures__/typescript/success-yaml/pre/main.ts +9 -0
  107. package/__fixtures__/typescript/success-yaml/src/index.ts +3 -0
  108. package/__fixtures__/typescript/success-yaml/src/main.ts +9 -0
  109. package/__fixtures__/typescript/success-yaml/tsconfig.json +20 -0
  110. package/__fixtures__/typescript-esm/no-export/.env.fixture +2 -0
  111. package/__fixtures__/typescript-esm/no-export/action.yml +17 -0
  112. package/__fixtures__/typescript-esm/no-export/node_modules/.gitkeep +0 -0
  113. package/__fixtures__/typescript-esm/no-export/package.json +17 -0
  114. package/__fixtures__/typescript-esm/no-export/src/index.ts +0 -0
  115. package/__fixtures__/typescript-esm/no-export/src/main.ts +0 -0
  116. package/__fixtures__/typescript-esm/no-export/tsconfig.json +25 -0
  117. package/__fixtures__/typescript-esm/no-import/.env.fixture +2 -0
  118. package/__fixtures__/typescript-esm/no-import/action.yml +17 -0
  119. package/__fixtures__/typescript-esm/no-import/node_modules/.gitkeep +0 -0
  120. package/__fixtures__/typescript-esm/no-import/package.json +17 -0
  121. package/__fixtures__/typescript-esm/no-import/src/index.ts +3 -0
  122. package/__fixtures__/typescript-esm/no-import/src/main.ts +3 -0
  123. package/__fixtures__/typescript-esm/no-import/tsconfig.json +25 -0
  124. package/__fixtures__/typescript-esm/success/.env.fixture +2 -0
  125. package/__fixtures__/typescript-esm/success/action.yml +17 -0
  126. package/__fixtures__/typescript-esm/success/node_modules/.gitkeep +0 -0
  127. package/__fixtures__/typescript-esm/success/package.json +17 -0
  128. package/__fixtures__/typescript-esm/success/post/index.ts +3 -0
  129. package/__fixtures__/typescript-esm/success/post/main.ts +9 -0
  130. package/__fixtures__/typescript-esm/success/pre/index.ts +3 -0
  131. package/__fixtures__/typescript-esm/success/pre/main.ts +9 -0
  132. package/__fixtures__/typescript-esm/success/src/index.ts +3 -0
  133. package/__fixtures__/typescript-esm/success/src/main.ts +9 -0
  134. package/__fixtures__/typescript-esm/success/tsconfig.json +25 -0
  135. package/__fixtures__/typescript-esm/tsconfig-comments/.env.fixture +2 -0
  136. package/__fixtures__/typescript-esm/tsconfig-comments/action.yml +17 -0
  137. package/__fixtures__/typescript-esm/tsconfig-comments/node_modules/.gitkeep +0 -0
  138. package/__fixtures__/typescript-esm/tsconfig-comments/package.json +17 -0
  139. package/__fixtures__/typescript-esm/tsconfig-comments/src/index.ts +3 -0
  140. package/__fixtures__/typescript-esm/tsconfig-comments/src/main.ts +9 -0
  141. package/__fixtures__/typescript-esm/tsconfig-comments/tsconfig.json +21 -0
  142. package/__tests__/command.test.ts +224 -0
  143. package/__tests__/stubs/artifact/internal/client.test.ts +340 -0
  144. package/__tests__/stubs/artifact/internal/delete/delete-artifact.test.ts +152 -0
  145. package/__tests__/stubs/artifact/internal/download/download-artifact.test.ts +119 -0
  146. package/__tests__/stubs/artifact/internal/find/get-artifact.test.ts +237 -0
  147. package/__tests__/stubs/artifact/internal/find/list-artifacts.test.ts +218 -0
  148. package/__tests__/stubs/artifact/internal/find/retry-options.test.ts +54 -0
  149. package/__tests__/stubs/artifact/internal/shared/config.test.ts +91 -0
  150. package/__tests__/stubs/artifact/internal/shared/errors.test.ts +38 -0
  151. package/__tests__/stubs/artifact/internal/shared/user-agent.test.ts +22 -0
  152. package/__tests__/stubs/artifact/internal/upload/path-and-artifact-name-validation.test.ts +53 -0
  153. package/__tests__/stubs/artifact/internal/upload/upload-artifact.test.ts +126 -0
  154. package/__tests__/stubs/artifact/internal/upload/upload-zip-specification.test.ts +49 -0
  155. package/__tests__/stubs/cache/cache.test.ts +357 -0
  156. package/__tests__/stubs/cache/errors.test.ts +55 -0
  157. package/__tests__/stubs/cache/internal/cacheUtils.test.ts +109 -0
  158. package/__tests__/stubs/cache/internal/constants.test.ts +81 -0
  159. package/__tests__/stubs/cache/internal/tar.test.ts +129 -0
  160. package/__tests__/stubs/core/core.test.ts +760 -0
  161. package/__tests__/stubs/core/path-utils.test.ts +45 -0
  162. package/__tests__/stubs/core/platform.test.ts +89 -0
  163. package/__tests__/stubs/core/summary.test.ts +455 -0
  164. package/__tests__/stubs/env.test.ts +72 -0
  165. package/__tests__/stubs/github/context.test.ts +73 -0
  166. package/__tests__/stubs/github/github.test.ts +15 -0
  167. package/__tests__/stubs/github/internal/utils.test.ts +98 -0
  168. package/__tests__/stubs/github/utils.test.ts +16 -0
  169. package/__tests__/utils/config.test.ts +78 -0
  170. package/__tests__/utils/output.test.ts +32 -0
  171. package/__tests__/utils/package.test.ts +33 -0
  172. package/badges/coverage.svg +1 -0
  173. package/bin/local-action.js +121 -0
  174. package/docs/create-a-job-summary.md +32 -0
  175. package/docs/debugging-in-vscode.md +27 -0
  176. package/docs/img/job-summary.png +0 -0
  177. package/docs/supported-functionality.md +126 -0
  178. package/eslint.config.mjs +74 -0
  179. package/jest.config.ts +41 -0
  180. package/package.json +93 -4
  181. package/src/command.ts +171 -0
  182. package/src/commands/run.ts +616 -0
  183. package/src/index.ts +21 -0
  184. package/src/stubs/artifact/artifact.ts +17 -0
  185. package/src/stubs/artifact/internal/client.ts +400 -0
  186. package/src/stubs/artifact/internal/delete/delete-artifact.ts +126 -0
  187. package/src/stubs/artifact/internal/download/download-artifact.ts +309 -0
  188. package/src/stubs/artifact/internal/find/get-artifact.ts +135 -0
  189. package/src/stubs/artifact/internal/find/list-artifacts.ts +188 -0
  190. package/src/stubs/artifact/internal/find/retry-options.ts +57 -0
  191. package/src/stubs/artifact/internal/shared/config.ts +64 -0
  192. package/src/stubs/artifact/internal/shared/errors.ts +53 -0
  193. package/src/stubs/artifact/internal/shared/interfaces.ts +195 -0
  194. package/src/stubs/artifact/internal/shared/user-agent.ts +13 -0
  195. package/src/stubs/artifact/internal/upload/path-and-artifact-name-validation.ts +92 -0
  196. package/src/stubs/artifact/internal/upload/upload-artifact.ts +127 -0
  197. package/src/stubs/artifact/internal/upload/upload-zip-specification.ts +108 -0
  198. package/src/stubs/artifact/internal/upload/zip.ts +122 -0
  199. package/src/stubs/cache/cache.ts +334 -0
  200. package/src/stubs/cache/errors.ts +31 -0
  201. package/src/stubs/cache/interfaces.ts +4 -0
  202. package/src/stubs/cache/internal/cacheUtils.ts +207 -0
  203. package/src/stubs/cache/internal/constants.ts +45 -0
  204. package/src/stubs/cache/internal/tar.ts +374 -0
  205. package/src/stubs/cache/options.ts +91 -0
  206. package/src/stubs/core/core.ts +743 -0
  207. package/src/stubs/core/path-utils.ts +39 -0
  208. package/src/stubs/core/platform.ts +132 -0
  209. package/src/stubs/core/summary.ts +399 -0
  210. package/src/stubs/env.ts +40 -0
  211. package/src/stubs/github/context.ts +94 -0
  212. package/src/stubs/github/github.ts +29 -0
  213. package/src/stubs/github/interfaces.ts +52 -0
  214. package/src/stubs/github/internal/utils.ts +83 -0
  215. package/src/stubs/github/utils.ts +52 -0
  216. package/src/types/quibble.d.ts +5 -0
  217. package/src/types.ts +116 -0
  218. package/src/utils/config.ts +47 -0
  219. package/src/utils/output.ts +20 -0
  220. package/src/utils/package.ts +38 -0
  221. package/tsconfig.base.json +29 -0
  222. package/tsconfig.eslint.json +22 -0
  223. package/tsconfig.json +18 -0
@@ -0,0 +1,74 @@
1
+ import { FlatCompat } from '@eslint/eslintrc'
2
+ import js from '@eslint/js'
3
+ import typescriptEslint from '@typescript-eslint/eslint-plugin'
4
+ import tsParser from '@typescript-eslint/parser'
5
+ import prettier from 'eslint-plugin-prettier'
6
+ import globals from 'globals'
7
+ import path from 'node:path'
8
+ import { fileURLToPath } from 'node:url'
9
+
10
+ const __filename = fileURLToPath(import.meta.url)
11
+ const __dirname = path.dirname(__filename)
12
+ const compat = new FlatCompat({
13
+ baseDirectory: __dirname,
14
+ recommendedConfig: js.configs.recommended,
15
+ allConfig: js.configs.all
16
+ })
17
+
18
+ export default [
19
+ {
20
+ ignores: [
21
+ '__fixtures__/javascript',
22
+ '__fixtures__/javascript-esm',
23
+ '__fixtures__/typescript',
24
+ '__fixtures__/typescript-esm',
25
+ '.github',
26
+ '.vscode',
27
+ 'badges',
28
+ 'bin',
29
+ 'coverage',
30
+ 'megalinter-reports',
31
+ 'node_modules',
32
+ 'reports'
33
+ ]
34
+ },
35
+ ...compat.extends(
36
+ 'eslint:recommended',
37
+ 'plugin:@typescript-eslint/eslint-recommended',
38
+ 'plugin:@typescript-eslint/recommended'
39
+ ),
40
+ {
41
+ plugins: {
42
+ prettier,
43
+ '@typescript-eslint': typescriptEslint
44
+ },
45
+
46
+ languageOptions: {
47
+ globals: {
48
+ ...globals.node,
49
+ Atomics: 'readonly',
50
+ SharedArrayBuffer: 'readonly'
51
+ },
52
+
53
+ parser: tsParser,
54
+ ecmaVersion: 2023,
55
+ sourceType: 'module',
56
+
57
+ parserOptions: {
58
+ project: ['tsconfig.eslint.json']
59
+ }
60
+ },
61
+
62
+ rules: {
63
+ '@typescript-eslint/no-explicit-any': 'off',
64
+ camelcase: 'off',
65
+ 'eslint-comments/no-use': 'off',
66
+ 'eslint-comments/no-unused-disable': 'off',
67
+ 'i18n-text/no-en': 'off',
68
+ 'no-console': 'off',
69
+ 'no-shadow': 'off',
70
+ 'no-unused-vars': 'off',
71
+ 'prettier/prettier': 'error'
72
+ }
73
+ }
74
+ ]
package/jest.config.ts ADDED
@@ -0,0 +1,41 @@
1
+ import type { JestConfigWithTsJest } from 'ts-jest'
2
+
3
+ const config: JestConfigWithTsJest = {
4
+ clearMocks: true,
5
+ collectCoverage: true,
6
+ collectCoverageFrom: ['src/**'],
7
+ coverageDirectory: 'coverage',
8
+ coveragePathIgnorePatterns: [
9
+ 'node_modules',
10
+ 'src/types/quibble.d.ts',
11
+ 'src/commands/run.ts',
12
+ 'src/stubs/artifact/artifact.ts',
13
+ 'src/index.ts'
14
+ ],
15
+ coverageReporters: ['json-summary', 'lcov', 'text'],
16
+ coverageThreshold: {
17
+ global: {
18
+ branches: 100,
19
+ functions: 100,
20
+ lines: 100,
21
+ statements: 100
22
+ }
23
+ },
24
+ extensionsToTreatAsEsm: ['.ts'],
25
+ moduleFileExtensions: ['js', 'ts'],
26
+ preset: 'ts-jest',
27
+ reporters: ['default', 'jest-junit'],
28
+ resolver: 'ts-jest-resolver',
29
+ roots: ['<rootDir>/src/', '<rootDir>/__fixtures__/', '<rootDir>/__tests__/'],
30
+ testMatch: ['**/*.test.ts'],
31
+ testPathIgnorePatterns: ['/dist/', '/megalinter-reports/', '/node_modules/'],
32
+ transform: {
33
+ '\\.[jt]sx?$': [
34
+ 'ts-jest',
35
+ { useESM: true, tsconfig: 'tsconfig.eslint.json' }
36
+ ]
37
+ },
38
+ verbose: true
39
+ }
40
+
41
+ export default config
package/package.json CHANGED
@@ -1,6 +1,95 @@
1
1
  {
2
2
  "name": "@ronaldphilipsen/local-action",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "description": "Local Debugging for GitHub Actions",
4
+ "version": "7.0.1",
5
+ "type": "module",
6
+ "author": "Nick Alteen <ncalteen@github.com>",
7
+ "private": false,
8
+ "homepage": "https://github.com/RonaldPhilipsen/local-action",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/RonaldPhilipsen/local-action.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/RonaldPhilipsen/local-action/issues"
15
+ },
16
+ "keywords": [
17
+ "actions",
18
+ "node",
19
+ "typescript"
20
+ ],
21
+ "engines": {
22
+ "node": "^20 || ^22 || ^24 || ^26"
23
+ },
24
+ "exports": {
25
+ ".": "./src/index.ts"
26
+ },
27
+ "bin": {
28
+ "local-action": "bin/local-action.js"
29
+ },
30
+ "scripts": {
31
+ "ci-test": "NODE_OPTIONS=\"$NODE_OPTIONS --no-warnings --experimental-vm-modules\" jest --ci --reporters=default --reporters=jest-junit --no-cache",
32
+ "coverage": "make-coverage-badge --output-path ./badges/coverage.svg",
33
+ "format:write": "prettier --write .",
34
+ "format:check": "prettier --check .",
35
+ "lint": "eslint .",
36
+ "test": "NODE_OPTIONS=\"$NODE_OPTIONS --no-warnings --experimental-vm-modules\" jest --no-cache",
37
+ "all": "npm run format:write && npm run lint && npm run test && npm run coverage"
38
+ },
39
+ "license": "MIT",
40
+ "jest-junit": {
41
+ "outputDirectory": "reports",
42
+ "outputName": "jest-junit.xml"
43
+ },
44
+ "dependencies": {
45
+ "@actions/artifact": "^5.0.2",
46
+ "@actions/cache": "^5.0.3",
47
+ "@actions/core": "^2.0.2",
48
+ "@actions/exec": "^2.0.0",
49
+ "@actions/github": "^7.0.0",
50
+ "@actions/http-client": "^3.0.1",
51
+ "@octokit/core": "^7.0.6",
52
+ "@octokit/plugin-paginate-rest": "^13.2.1",
53
+ "@octokit/plugin-request-log": "^6.0.0",
54
+ "@octokit/plugin-rest-endpoint-methods": "^17.0.0",
55
+ "@octokit/plugin-retry": "^8.0.3",
56
+ "@octokit/rest": "^22.0.1",
57
+ "archiver": "^7.0.1",
58
+ "chalk": "^5.6.2",
59
+ "commander": "^14.0.3",
60
+ "comment-json": "^4.5.1",
61
+ "dotenv": "^17.3.1",
62
+ "figlet": "^1.10.0",
63
+ "quibble": "^0.9.2",
64
+ "semver": "^7.7.4",
65
+ "tsconfig-paths": "^4.2.0",
66
+ "tsx": "^4.21.0",
67
+ "typescript": "^5.9.3",
68
+ "yaml": "^2.8.2"
69
+ },
70
+ "devDependencies": {
71
+ "@eslint/compat": "^2.0.2",
72
+ "@eslint/eslintrc": "^3.3.3",
73
+ "@eslint/js": "^10.0.1",
74
+ "@jest/globals": "^30.2.0",
75
+ "@types/archiver": "^7.0.0",
76
+ "@types/jest": "^30.0.0",
77
+ "@types/node": "^25.2.3",
78
+ "@types/semver": "^7.7.1",
79
+ "@types/unzip-stream": "^0.3.4",
80
+ "@typescript-eslint/eslint-plugin": "^8.56.0",
81
+ "@typescript-eslint/parser": "^8.56.0",
82
+ "eslint": "^10.0.0",
83
+ "eslint-plugin-prettier": "^5.5.5",
84
+ "jest": "^30.2.0",
85
+ "jest-junit": "^16.0.0",
86
+ "make-coverage-badge": "^1.2.0",
87
+ "prettier": "^3.8.1",
88
+ "ts-jest": "^29.4.6",
89
+ "ts-jest-resolver": "^2.0.1",
90
+ "ts-node": "^10.9.2"
91
+ },
92
+ "overrides": {
93
+ "undici": ">=6.23.0"
94
+ }
95
+ }
package/src/command.ts ADDED
@@ -0,0 +1,171 @@
1
+ import { Command, InvalidArgumentError } from 'commander'
2
+ import { dirname } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { action } from './commands/run.js'
5
+ import { EnvMeta } from './stubs/env.js'
6
+
7
+ /**
8
+ * Creates the CLI Program
9
+ *
10
+ * @returns Command Program Object
11
+ */
12
+ export async function makeProgram(): Promise<Command> {
13
+ const program: Command = new Command()
14
+ const fs = await import('fs')
15
+ const path = await import('path')
16
+ const __dirname = dirname(fileURLToPath(import.meta.url))
17
+
18
+ /**
19
+ * Checks if Action Path is Valid
20
+ *
21
+ * @param value Action Path
22
+ * @returns Resolved Action Path
23
+ * @throws InvalidArgumentError
24
+ */
25
+ function checkActionPath(value: string): string {
26
+ const actionPath: string = path.resolve(value)
27
+
28
+ try {
29
+ // Confirm the value is a directory
30
+ if (!fs.statSync(actionPath).isDirectory())
31
+ throw new InvalidArgumentError('Action path must be a directory')
32
+ } catch (err: any) {
33
+ if ('code' in err && err.code === 'ENOENT')
34
+ throw new InvalidArgumentError('Action path does not exist')
35
+ else throw new InvalidArgumentError(err.message as string)
36
+ }
37
+
38
+ // Save the action path to environment metadata
39
+ EnvMeta.actionPath = actionPath
40
+
41
+ // Confirm there is an `action.yml` or `action.yaml` in the directory and
42
+ // save the path to environment metadata
43
+ if (fs.existsSync(path.resolve(actionPath, 'action.yml')))
44
+ EnvMeta.actionFile = path.resolve(EnvMeta.actionPath, 'action.yml')
45
+ else if (fs.existsSync(path.resolve(actionPath, 'action.yaml')))
46
+ EnvMeta.actionFile = path.resolve(EnvMeta.actionPath, 'action.yaml')
47
+ else
48
+ throw new InvalidArgumentError(
49
+ 'Path must contain an action.yml / action.yaml file'
50
+ )
51
+
52
+ return path.resolve(value)
53
+ }
54
+
55
+ /**
56
+ * Checks if `main` Entrypoint is Valid
57
+ *
58
+ * @param value Entrypoint
59
+ * @returns Resolved Entrypoint Path
60
+ * @throws InvalidArgumentError
61
+ */
62
+ function checkEntrypoint(value: string): string {
63
+ const entrypoint: string = path.resolve(EnvMeta.actionPath, value)
64
+
65
+ // Confirm the entrypoint exists
66
+ if (!fs.existsSync(entrypoint))
67
+ throw new InvalidArgumentError(`Entrypoint does not exist: ${value}`)
68
+
69
+ // Save the action entrypoint to environment metadata
70
+ EnvMeta.entrypoint = entrypoint
71
+
72
+ return entrypoint
73
+ }
74
+
75
+ /**
76
+ * Checks if `pre` Entrypoint is Valid
77
+ *
78
+ * @param value Entrypoint
79
+ * @returns Resolved Entrypoint Path
80
+ * @throws InvalidArgumentError
81
+ */
82
+ function checkPreEntrypoint(value: string): string {
83
+ const entrypoint: string = path.resolve(EnvMeta.actionPath, value)
84
+
85
+ // Confirm the entrypoint exists
86
+ if (!fs.existsSync(entrypoint))
87
+ throw new InvalidArgumentError(
88
+ `PRE entrypoint does not exist: ${entrypoint}`
89
+ )
90
+
91
+ // Save the action entrypoint to environment metadata
92
+ EnvMeta.preEntrypoint = entrypoint
93
+
94
+ return entrypoint
95
+ }
96
+
97
+ /**
98
+ * Checks if `post` Entrypoint is Valid
99
+ *
100
+ * @param value Entrypoint
101
+ * @returns Resolved Entrypoint Path
102
+ * @throws InvalidArgumentError
103
+ */
104
+ function checkPostEntrypoint(value: string): string {
105
+ const entrypoint: string = path.resolve(EnvMeta.actionPath, value)
106
+
107
+ // Confirm the entrypoint exists
108
+ if (!fs.existsSync(entrypoint))
109
+ throw new InvalidArgumentError(`POST entrypoint does not exist: ${value}`)
110
+
111
+ // Save the action entrypoint to environment metadata
112
+ EnvMeta.postEntrypoint = entrypoint
113
+
114
+ return entrypoint
115
+ }
116
+
117
+ /**
118
+ * Checks if `dotenv` File is Valid
119
+ *
120
+ * @param value Dotenv File Path
121
+ * @returns Resolved Dotenv File Path
122
+ * @throws InvalidArgumentError
123
+ */
124
+ function checkDotenvFile(value: string): string {
125
+ const dotenvFile: string = path.resolve(value)
126
+
127
+ // Confirm the dotenv file exists
128
+ if (!fs.existsSync(dotenvFile))
129
+ throw new InvalidArgumentError('Environment file does not exist')
130
+
131
+ // Save the .env file path to environment metadata
132
+ EnvMeta.dotenvFile = dotenvFile
133
+
134
+ return dotenvFile
135
+ }
136
+
137
+ program
138
+ .name('local-action')
139
+ .description('Test a GitHub Action locally')
140
+ .version(
141
+ `Version: ${JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', 'package.json'), 'utf-8')).version as string}`
142
+ )
143
+
144
+ program
145
+ .command('run', { isDefault: true })
146
+ .description('Run a GitHub Action locally')
147
+ .argument('<action path>', 'Path to the action directory', checkActionPath)
148
+ .argument(
149
+ '<entrypoint>',
150
+ 'Action entrypoint (relative to the action directory)',
151
+ checkEntrypoint
152
+ )
153
+ .argument('<dotenv file>', 'Path to the local .env file', checkDotenvFile)
154
+ .option(
155
+ '--pre <pre>',
156
+ 'Action pre entrypoint (relative to the action directory)',
157
+ checkPreEntrypoint,
158
+ undefined
159
+ )
160
+ .option(
161
+ '--post <post>',
162
+ 'Action post entrypoint (relative to the action directory)',
163
+ checkPostEntrypoint,
164
+ undefined
165
+ )
166
+ .action(async (actionPath, entrypoint, dotenvFile, options) => {
167
+ await action(actionPath, entrypoint, dotenvFile, options)
168
+ })
169
+
170
+ return program
171
+ }