TypeScript Action Template

October 3, 2025 ยท View on GitHub

CI Check dist/ Coverage Node.js Version License

A highly optimized GitHub Action template repository for building robust, performant TypeScript-based GitHub Actions with minimal bundle size and comprehensive code quality tooling.

Features

  • ๐Ÿš€ High Performance: Optimized 1.3KB bundle size (99.7% reduction from typical builds)
  • ๐Ÿ“ฆ Modern TypeScript: Full TypeScript configuration with strict type checking
  • ๐Ÿ” Code Quality: ESLint with SonarJS static analysis, complexity limits, and import sorting
  • ๐ŸŽจ Code Formatting: Prettier integration with automatic formatting
  • ๐Ÿงช Comprehensive Testing: Jest testing framework with coverage reporting and badges
  • โšก Optimized Build: Rollup bundling with external dependencies and Terser minification
  • ๐Ÿ—๏ธ Smart Architecture: Modular logging system with dependency injection
  • ๐Ÿ“Š Quality Gates: Duplicate code detection (1% threshold), circular dependency checking
  • ๐Ÿ›ก๏ธ Security: SonarJS security patterns and vulnerability detection
  • ๐Ÿ”ง Developer Experience: Local development support with @github/local-action
  • ๐Ÿ“‹ CI/CD Ready: Pre-configured GitHub Actions workflows with quality gates

Project Structure

โ”œโ”€โ”€ .devcontainer/          # Dev container configuration
โ”œโ”€โ”€ .github/
โ”‚   โ”œโ”€โ”€ workflows/          # GitHub Actions CI/CD workflows
โ”‚   โ”‚   โ”œโ”€โ”€ ci.yml          # Main CI pipeline
โ”‚   โ”‚   โ””โ”€โ”€ check-dist.yml  # Distribution verification
โ”‚   โ”œโ”€โ”€ FUNDING.yml         # GitHub funding configuration
โ”‚   โ””โ”€โ”€ pull_request_template.md
โ”œโ”€โ”€ .vscode/                # VS Code workspace settings
โ”œโ”€โ”€ __mocks__/              # Test mocks
โ”‚   โ””โ”€โ”€ @actions/
โ”‚       โ””โ”€โ”€ core.ts
โ”œโ”€โ”€ badges/                 # Generated coverage badges
โ”œโ”€โ”€ coverage/               # Test coverage reports
โ”œโ”€โ”€ dist/                   # Build output
โ”œโ”€โ”€ script/                 # Utility scripts
โ”‚   โ”œโ”€โ”€ copyright.sh        # Copyright header management
โ”‚   โ”œโ”€โ”€ distchk.sh          # Distribution verification
โ”‚   โ””โ”€โ”€ release.sh          # Release automation
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts            # Main entry point
โ”‚   โ”œโ”€โ”€ core/               # Core action logic
โ”‚   โ”‚   โ”œโ”€โ”€ action.ts       # Action implementation
โ”‚   โ”‚   โ””โ”€โ”€ index.ts        # Core exports
โ”‚   โ”œโ”€โ”€ logging/            # Modular logging system
โ”‚   โ”‚   โ”œโ”€โ”€ loggers/        # Logger implementations
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ composite.ts # Multi-logger coordination
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ core.ts     # GitHub Actions logger
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ filtered.ts # Filtered logging
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ metrics.ts  # Metrics collection
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ mock.ts     # Test mock logger
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ noop.ts     # No-op logger
โ”‚   โ”‚   โ”œโ”€โ”€ pino/           # Pino logger integration
โ”‚   โ”‚   โ”œโ”€โ”€ filters/        # Log filtering system
โ”‚   โ”‚   โ”œโ”€โ”€ config.ts       # Logger configuration
โ”‚   โ”‚   โ”œโ”€โ”€ types.ts        # Type definitions
โ”‚   โ”‚   โ””โ”€โ”€ index.ts        # Logging exports
โ”‚   โ””โ”€โ”€ __tests__/          # Comprehensive test suite
โ”œโ”€โ”€ .editorconfig           # Editor style configuration
โ”œโ”€โ”€ .gitignore              # Optimized git ignore rules
โ”œโ”€โ”€ .gitattributes          # Git attributes
โ”œโ”€โ”€ .jscpd.json            # Code duplication detection config
โ”œโ”€โ”€ .markdown-lint.yml      # Markdown linting configuration
โ”œโ”€โ”€ .npmignore              # NPM publish control
โ”œโ”€โ”€ .nvmrc                  # Node.js version (20)
โ”œโ”€โ”€ .prettierignore         # Prettier ignore rules
โ”œโ”€โ”€ .prettierrc.yml         # Prettier configuration
โ”œโ”€โ”€ .yaml-lint.yml          # YAML linting configuration
โ”œโ”€โ”€ action.yml              # GitHub Action metadata
โ”œโ”€โ”€ CODEOWNERS              # Code ownership rules
โ”œโ”€โ”€ eslint.config.mjs       # Modern ESLint flat configuration
โ”œโ”€โ”€ jest.config.cjs         # Jest testing configuration
โ”œโ”€โ”€ package.json            # Optimized dependencies and scripts
โ”œโ”€โ”€ rollup.config.js        # Optimized build configuration
โ”œโ”€โ”€ tsconfig.json           # Production TypeScript config
โ”œโ”€โ”€ tsconfig.test.json      # Test environment TypeScript config
โ””โ”€โ”€ README.md               # This file

Setup

  1. Clone this repository
  2. Install dependencies:
npm install
  1. Use the correct Node.js version:
nvm use

Development

Available Scripts

  • npm run all - ๐Ÿš€ Complete pipeline: lint:fix โ†’ quality โ†’ test โ†’ package
  • npm run dev - ๐Ÿ”ง Local development with @github/local-action
  • npm run typecheck - ๐Ÿ“‹ TypeScript type checking without emit
  • npm run lint - ๐Ÿ” Prettier and ESLint validation
  • npm run lint:fix - ๐ŸŽจ Autoformat and fix code issues
  • npm run quality - ๐Ÿ“Š Quality gates: lint + duplication + circular deps
  • npm test - ๐Ÿงช Jest tests with coverage reporting
  • npm run coverage - ๐Ÿ“ˆ Generate coverage badge
  • npm run duplication - ๐Ÿ“Š Code duplication analysis (1% threshold)
  • npm run madge - ๐Ÿ”„ Circular dependency detection
  • npm run package - ๐Ÿ“ฆ Production build (optimized 1.3KB bundle)
  • npm run package:watch - ๐Ÿ‘€ Watch mode for development
  • npm run copyright - ยฉ๏ธ Update copyright headers
  • npm run release - ๐Ÿš€ Prepare distribution for release

Local Development

Test the action locally using the dev script:

npm run dev

This uses @github/local-action to run the action with your local source code.

Testing

Run tests with coverage:

npm test

Coverage reports are generated in the coverage/ directory, and a badge is created in badges/coverage.svg.

Code Quality

Check for code duplication:

npm run duplication

Check for circular dependencies:

npm run madge

Building

Build the action for distribution:

npm run package

This creates the bundled dist/index.mjs file.

CI/CD

The repository includes comprehensive CI/CD workflows:

  • CI Pipeline (ci.yml): Runs linting, unit tests, and integration tests
  • Distribution Check (check-dist.yml): Ensures the dist/ directory matches the built output

Usage in Workflows

- name: Run TypeScript Action
  uses: your-org/your-action@v1
  with:
    # Add your inputs here

Configuration

Node.js Version

The project uses Node.js 20 (specified in .nvmrc).

TypeScript

  • Production config: tsconfig.json - Main configuration for builds and type checking
  • Test config: tsconfig.test.json - Extends main config with test environment support

Code Quality & Linting

ESLint with modern flat configuration includes:

  • TypeScript Integration: Full type-aware linting with strict rules
  • SonarJS Static Analysis: Security patterns, complexity limits, code smells
  • Import Organization: Automatic import sorting and organization
  • Complexity Monitoring: Cyclomatic complexity limits (fails build at >10)
  • Jest Support: Test-specific rules and globals
  • Prettier Integration: Seamless code formatting

Formatting

Prettier is configured with:

  • 2-space indentation
  • Single quotes
  • Semicolons
  • 80 character line width

Build

Rollup produces an optimized bundle with:

  • 99.7% Size Reduction: From 451KB to 1.3KB (external dependencies)
  • ES Module Output: Modern JavaScript for GitHub Actions
  • Terser Minification: Optimized production build
  • External Dependencies: Core Node.js and GitHub Action modules
  • Source Maps: Full debugging support

Configuration Files Summary

FilePurposeKey Features
action.ymlGitHub Action metadataDefines inputs, outputs, and Node.js runtime
package.jsonProject configurationOptimized scripts, 24 dependencies (down from 32)
tsconfig.jsonTypeScript production configStrict rules, ECMAScript 2022 target, Node.js resolution
tsconfig.test.jsonTypeScript test configExtends base with Jest globals and test types
eslint.config.mjsESLint flat configurationSonarJS rules, import organization, complexity limits
jest.config.cjsJest testing frameworkCoverage reports, TypeScript transformation
rollup.config.jsBuild tool configuration99.7% bundle reduction, external dependencies

Usage in Your Action

  1. Clone this template or use it as a GitHub template
  2. Customize action.yml with your action's metadata
  3. Implement your logic in src/core/action.ts
  4. Add tests in src/__tests__/
  5. Run the full pipeline with npm run all
  6. Build and release with npm run package

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes following the existing patterns
  4. Add comprehensive tests for new functionality
  5. Run the complete pipeline: npm run all
  6. Ensure all quality gates pass (linting, tests, coverage)
  7. Submit a pull request with a clear description

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.