GitHub Actions Templates

GitHub Actions Templates

Production-ready GitHub Actions workflow patterns for testing, building, and deploying applications

Category: design Source: wshobson/agents

What Is This

The GitHub Actions Templates skill provides a curated collection of production-ready workflow patterns for use with GitHub Actions. These templates are designed to automate the essential phases of modern software development, including testing, building, and deploying applications. By leveraging these templates, developers and DevOps engineers can set up robust continuous integration and continuous deployment (CI/CD) pipelines with minimal effort, ensuring repeatable, reliable, and scalable automation on GitHub-hosted repositories.

The skill is delivered as a set of YAML-based workflow templates that adhere to best practices and security standards. These patterns support a range of use cases, from simple test automation to complex deployment workflows involving containerization, Kubernetes, and security scanning. The templates are easily adaptable and are intended to reduce the boilerplate and configuration overhead typical of custom workflow authoring.

Why Use It

Setting up CI/CD workflows can be a time-consuming and error-prone process, especially when dealing with multiple environments or integrating new tools. The GitHub Actions Templates skill addresses these challenges by providing:

  • Standardization: Ensures your team follows consistent, proven patterns across repositories.
  • Best Practices: Incorporates security, caching, matrix builds, and deployment conventions recognized by the industry.
  • Time Savings: Reduces the manual effort needed to write, test, and maintain workflow files.
  • Flexibility: Offers reusable patterns that can be customized for different languages, frameworks, and deployment targets.
  • Production-Readiness: Designed to work reliably in real-world, production deployments.

By adopting these templates, development teams can focus on delivering features and improvements rather than spending time on CI/CD pipeline setup and troubleshooting.

How to Use It

To use the GitHub Actions Templates skill, you typically select a relevant template and adapt it to your repository's requirements. The templates are provided as YAML files and can be added directly to the .github/workflows directory in your GitHub repository.

Example: Testing Workflow for Node.js Projects

Below is an example of a production-ready test workflow template that demonstrates common best practices, such as matrix builds for multiple Node.js versions, caching dependencies, linting, testing, and uploading test coverage.

name: Test

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x, 20.x]

    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"

      - name: Install dependencies
        run: npm ci

      - name: Run linter
        run: npm run lint

      - name: Run tests
        run: npm test

      - name: Upload coverage
        uses: codecov/codecov-action@v3
        with:
          files: ./coverage/*.xml

This workflow triggers on pushes to main and develop branches, as well as on pull requests to main. It runs tests using two Node.js versions in parallel, performs linting, and uploads code coverage reports.

Example: Docker Build and Deployment

You can use other templates from this skill to automate Docker image builds and push to container registries, or to deploy applications to Kubernetes clusters. These templates typically include steps for authentication, image tagging, and deployment orchestration.

Sample snippet for Docker build and push:

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Log in to registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker image
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: ghcr.io/${{ github.repository }}:latest

When to Use It

The GitHub Actions Templates skill is ideal for the following scenarios:

  • Automated Testing: Run unit, integration, and end-to-end tests on every code push or pull request.
  • Continuous Deployment: Automatically deploy applications to staging or production environments on successful builds.
  • Containerization Workflows: Build, tag, and push Docker images, or deploy them to Kubernetes clusters.
  • Security Automation: Integrate static analysis tools or vulnerability scanners as part of your CI/CD process.
  • Multi-Environment Builds: Execute matrix builds to test your application across different platforms, versions, or configurations.

It is particularly useful when you need repeatable, secure, and scalable automation for development and deployment processes on GitHub.

Important Notes

  • Customization: Templates are designed to be starting points. You should tailor them to fit your project's dependencies, environment variables, and deployment targets.
  • Security: Always store secrets (such as API tokens and registry credentials) in GitHub Secrets, and reference them securely in workflows.
  • Maintenance: Periodically review and update templates to incorporate new best practices, action versions, and security patches.
  • Documentation: Each template should be well-documented within your repository to ensure team members understand the workflow and responsibilities.
  • Compatibility: While templates cover common use cases, ensure that the selected pattern is compatible with your technology stack and deployment infrastructure.

By leveraging the GitHub Actions Templates skill, teams can accelerate their adoption of CI/CD, improve code quality, and increase deployment reliability with minimal setup and consistent results.