|
1 | 1 | # Terraform Module Releaser |
2 | 2 |
|
3 | 3 | A GitHub Action written in TypeScript that automates versioning, releases, and documentation for Terraform modules in |
4 | | -GitHub monorepos. The action creates module-specific Git tags, GitHub releases, pull request comments, and generates |
5 | | -comprehensive wiki documentation. |
| 4 | +monorepos. Creates module-specific Git tags, GitHub releases, PR comments, and comprehensive wiki documentation. |
6 | 5 |
|
7 | | -**Always reference these instructions first and fallback to search or Bash commands only when you encounter unexpected |
8 | | -information that does not match the info here.** |
| 6 | +## Tech Stack |
9 | 7 |
|
10 | | -## Working Effectively |
| 8 | +- **TypeScript 5.9+** with strict mode |
| 9 | +- **Node.js 22+** for local development (`.node-version`); compiles to Node.js 20+ compatible output |
| 10 | +- **Vitest** for testing with V8 coverage |
| 11 | +- **Biome** for linting/formatting (not ESLint/Prettier) |
| 12 | +- **@actions/core** and **@octokit** for GitHub integration |
11 | 13 |
|
12 | | -### Bootstrap and Build the Repository |
| 14 | +## Essential Commands |
13 | 15 |
|
14 | | -- Install Node.js dependencies: `npm ci --no-fund` |
15 | | -- Run TypeScript type checking: `npm run typecheck` |
16 | | -- Lint and format code: `npm run check` |
| 16 | +```bash |
| 17 | +# Format and lint (run before every commit) |
| 18 | +npm run check:fix |
| 19 | +npm run textlint:fix |
17 | 20 |
|
18 | | -### Testing |
| 21 | +# Type checking |
| 22 | +npm run typecheck |
19 | 23 |
|
20 | | -- Run full test suite: `npm run test` (requires GITHUB_TOKEN for some tests) |
21 | | -- Run tests in watch mode during development: `npm run test:watch` |
22 | | - |
23 | | -## Validation |
24 | | - |
25 | | -### Required Environment Variables for Full Testing |
| 24 | +# Testing |
| 25 | +npm run test # Full test suite (requires GITHUB_TOKEN) |
| 26 | +npm run test:watch # Watch mode for development |
| 27 | +``` |
26 | 28 |
|
27 | | -- `GITHUB_TOKEN` - Required for tests that interact with GitHub API. Without this, some tests will be skipped with clear |
28 | | - error messages. |
| 29 | +## GITHUB_TOKEN Setup |
29 | 30 |
|
30 | | -### External Dependencies |
| 31 | +Integration tests require a valid GitHub token. Set it in your environment: |
31 | 32 |
|
32 | | -External dependencies like terraform-docs are automatically installed and handled during `npm run test` - no manual |
33 | | -prerequisite downloads needed. Note that firewall restrictions may block some operations in certain environments. |
| 33 | +```bash |
| 34 | +# For current session |
| 35 | +export GITHUB_TOKEN="ghp_your_token_here" |
34 | 36 |
|
35 | | -### Manual Validation Scenarios |
| 37 | +# Or create .env file (add to .gitignore) |
| 38 | +echo "GITHUB_TOKEN=ghp_your_token_here" > .env |
| 39 | +``` |
36 | 40 |
|
37 | | -- **Always validate TypeScript compilation**: Run `npm run typecheck` to catch type errors. |
38 | | -- **Always test functionality**: Run `npm run test` to verify operation and functionality. |
39 | | -- **Validate linting compliance**: Run `npm run check` to ensure code meets style requirements. |
| 41 | +## Project Structure |
40 | 42 |
|
41 | | -## Common Tasks |
| 43 | +```bash |
| 44 | +src/ # TypeScript source |
| 45 | +├── index.ts # Entry point |
| 46 | +├── ... # Core logic and utilities |
| 47 | +└── types/ # Type definitions |
| 48 | +__tests__/ # Tests (mirror src/) |
| 49 | +tf-modules/ # Example Terraform modules for testing |
| 50 | +dist/ # Compiled output (auto-generated) |
| 51 | +``` |
42 | 52 |
|
43 | | -### Build and Test Workflow |
| 53 | +## Code Standards |
44 | 54 |
|
45 | | -- `npm ci --no-fund` -- Install dependencies |
46 | | -- `npm run typecheck` -- Type checking |
47 | | -- `npm run check` -- Lint/formatting code |
48 | | -- `npm run test` -- Run full test suite |
| 55 | +**Naming:** |
49 | 56 |
|
50 | | -### Development |
| 57 | +- Functions/variables: `camelCase` (`parseModules`, `tagName`) |
| 58 | +- Types/interfaces: `PascalCase` (`TerraformModule`, `WikiConfig`) |
| 59 | +- Constants: `UPPER_SNAKE_CASE` (`WIKI_HOME_FILENAME`) |
51 | 60 |
|
52 | | -- Use `npm run test:watch` for continuous testing during development |
53 | | -- Use `npm run check` to check linting without fixing |
54 | | -- Always run `npm run check:fix` before committing or the CI (.github/workflows/lint.yml) will fail |
| 61 | +**Style:** Biome enforces all formatting automatically via `npm run check:fix` |
55 | 62 |
|
56 | | -### Working with the Action Locally |
| 63 | +## Development Workflow |
57 | 64 |
|
58 | | -- The action can be tested locally using the CI workflow configuration in `.github/workflows/ci.yml` |
59 | | -- Test terraform modules are located in `tf-modules/` directory |
60 | | -- Use GitHub Codespaces or Dev Containers for a consistent development environment (configuration in `.devcontainer/`) |
| 65 | +1. Make changes in `src/` |
| 66 | +2. Run `npm run check:fix && npm run textlint:fix` (autofix formatting) |
| 67 | +3. Run `npm run typecheck` (verify compilation) |
| 68 | +4. Run `npm run test` (ensure tests pass) |
| 69 | +5. Commit using [Conventional Commits](https://www.conventionalcommits.org/) format (e.g., `feat:`, `fix:`, `chore:`) |
61 | 70 |
|
62 | | -## Key Repository Structure |
| 71 | +**Commit Format:** We follow Conventional Commits with semantic versioning. Examples: `feat: add new feature`, |
| 72 | +`fix: resolve bug`, `chore: update dependencies` |
63 | 73 |
|
64 | | -```shell |
65 | | -/home/runner/work/terraform-module-releaser/terraform-module-releaser/ |
66 | | -├── .devcontainer/ # Dev container configuration |
67 | | -├── .github/workflows/ # CI/CD workflows (ci.yml, test.yml, lint.yml) |
68 | | -├── __mocks__/ # Test mocks |
69 | | -├── __tests__/ # Test files (mirror src/ structure) |
70 | | -├── action.yml # GitHub Action metadata and inputs |
71 | | -├── dist/ # Compiled action bundle (generated) |
72 | | -├── package.json # Dependencies and scripts |
73 | | -├── scripts/ # Utility scripts (changelog.js, parse-modules-test.ts) |
74 | | -├── src/ # TypeScript source code |
75 | | -│ ├── index.ts # Action entry point |
76 | | -│ ├── main.ts # Main action logic |
77 | | -│ ├── config.ts # Configuration handling |
78 | | -│ ├── context.ts # GitHub Actions context |
79 | | -│ ├── parser.ts # Terraform module discovery |
80 | | -│ ├── terraform-module.ts # Module representation |
81 | | -│ ├── wiki.ts # Wiki generation |
82 | | -│ ├── terraform-docs.ts # Terraform documentation |
83 | | -│ ├── releases.ts # GitHub releases |
84 | | -│ ├── tags.ts # Git tags |
85 | | -│ ├── pull-request.ts # PR comments |
86 | | -│ └── types/ # TypeScript type definitions |
87 | | -├── tf-modules/ # Example Terraform modules for testing |
88 | | -├── biome.json # Biome linter/formatter configuration |
89 | | -├── tsconfig.json # TypeScript configuration |
90 | | -└── vitest.config.ts # Test configuration |
91 | | -``` |
| 74 | +## Testing Notes |
92 | 75 |
|
93 | | -## Linting and Formatting |
| 76 | +- Path aliases: `@/` → `src/`, `@/tests/` → `__tests__/` |
| 77 | +- Some tests download terraform-docs binary (requires internet) |
| 78 | +- Tests without GITHUB_TOKEN are automatically skipped |
| 79 | +- Test modules in `tf-modules/` directory |
94 | 80 |
|
95 | | -- Uses **Biome** (not Prettier or ESLint) for TypeScript linting and formatting |
96 | | -- Configuration in `biome.json` |
97 | | -- Super Linter runs in CI but defers TypeScript formatting to Biome |
| 81 | +## Boundaries |
98 | 82 |
|
99 | | -## Testing Framework |
| 83 | +✅ **Always do:** |
100 | 84 |
|
101 | | -- Uses **Vitest** for testing with TypeScript support |
102 | | -- Configuration in `vitest.config.ts` |
103 | | -- Tests include both unit tests and integration tests with real GitHub API calls |
104 | | -- Coverage reporting with V8 provider |
105 | | -- Path aliases configured: `@/` points to `src/`, `@/tests/` to `__tests__/` |
| 85 | +- Run `npm run check:fix` before committing |
| 86 | +- Add/update tests for code changes |
| 87 | +- Follow TypeScript strict mode |
| 88 | +- Use existing patterns in codebase |
106 | 89 |
|
107 | | -## Known Limitations |
| 90 | +⚠️ **Ask first:** |
108 | 91 |
|
109 | | -- Some tests require `GITHUB_TOKEN` environment variable - they will be skipped with clear messages if not provided |
110 | | -- Some tests require internet access to download terraform-docs binary |
111 | | -- The action is designed to run in GitHub Actions environment with appropriate permissions |
| 92 | +- Adding new dependencies |
| 93 | +- Changing build configuration |
| 94 | +- Modifying GitHub Actions workflows |
112 | 95 |
|
113 | | -### Troubleshooting |
| 96 | +🚫 **Never do:** |
114 | 97 |
|
115 | | -- If API tests fail with "GITHUB_TOKEN environment variable must be set": Provide a valid GitHub token or skip |
116 | | - integration tests |
117 | | -- If build fails: Ensure Node.js 22 is installed (specified in `.node-version`) |
118 | | -- If linting fails: Run `npm run check:fix` to autofix formatting issues |
| 98 | +- Commit without running lint/tests |
| 99 | +- Modify `dist/` manually (auto-generated) |
| 100 | +- Bypass TypeScript strict checks |
0 commit comments