Skip to content

Coderrob/typescript-action-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TypeScript Action Template

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

File Purpose Key Features
action.yml GitHub Action metadata Defines inputs, outputs, and Node.js runtime
package.json Project configuration Optimized scripts, 24 dependencies (down from 32)
tsconfig.json TypeScript production config Strict rules, ECMAScript 2022 target, Node.js resolution
tsconfig.test.json TypeScript test config Extends base with Jest globals and test types
eslint.config.mjs ESLint flat configuration SonarJS rules, import organization, complexity limits
jest.config.cjs Jest testing framework Coverage reports, TypeScript transformation
rollup.config.js Build tool configuration 99.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.

About

GitHub Action TypeScript template repository

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •