Skip to content
Cover image for article: 5 GitHub Actions Every Maintainer Needs to Know
GitHubgithub-actionscodingDevops

5 GitHub Actions Every Maintainer Needs to Know

3 min

Maintaining an open-source project can be rewarding, but it also comes with its fair share of challenges. From managing pull requests to keeping dependencies up to date, the list of repetitive tasks can quickly become overwhelming. Luckily, GitHub Actions can automate many of these tasks, allowing you to focus on writing code and improving your project.

In this article, we'll explore five essential GitHub Actions that every project maintainer should use to enhance productivity and keep repositories well-organized.

Article image

1. Auto-merge for Dependabot Updates

Keeping dependencies up to date is crucial for security and performance. Dependabot helps by creating pull requests when new versions of dependencies are available, but manually reviewing and merging these updates can be time-consuming.

Use this GitHub Action to automatically merge safe updates:

name: Auto-merge Dependabot Updates
on:
  pull_request:
    types:
      - opened
    branches:
      - main
jobs:
  auto-merge:
    runs-on: ubuntu-latest
    steps:
      - name: Auto-approve Dependabot PRs
        uses: hmarr/auto-approve-action@v3
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
      - name: Auto-merge Dependabot PRs
        uses: pascalgn/automerge-action@v0.15.4
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}

Why You Need It: Saves time by merging non-breaking dependency updates automatically, keeping your project up to date with minimal effort.

2. Label PRs and Issues Automatically

Properly labeled issues and pull requests improve organization and help contributors find what they need faster. The actions/labeler GitHub Action automatically assigns labels based on file changes.

name: Label Issues and PRs
on:
  pull_request:
    types: [opened, synchronize]
  issues:
    types: [opened]

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/labeler@v4
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"

Why You Need It: Reduces manual labeling effort and ensures consistency across issues and pull requests.

3. Stale Issue and PR Management

Many open-source projects suffer from inactive issues and pull requests cluttering the repository. The stale action helps by automatically closing inactive items.

name: Close Stale Issues and PRs
on:
  schedule:
    - cron: "0 0 * * *"  # Runs daily

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/stale@v7
        with:
          stale-issue-message: "This issue has been marked as stale due to inactivity."
          close-issue-message: "Closing this issue due to inactivity."
          days-before-stale: 30
          days-before-close: 7

Why You Need It: Keeps your project clean by automatically closing outdated and inactive issues and PRs.

4. Run Tests on Every Pull Request

A well-maintained project should have automated tests running on every pull request to prevent broken code from being merged. This workflow uses actions/setup-node to test JavaScript projects.

name: Run Tests on PRs
on:
  pull_request:
    branches:
      - main
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '16'
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test

Why You Need It: Ensures only passing code is merged, maintaining project stability.

5. Automatically Publish Releases

Manually creating releases can be tedious. The release-please action automates this by generating changelogs and publishing new versions based on commits.

name: Automated Releases
on:
  push:
    branches:
      - main
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: google-github-actions/release-please-action@v3
        with:
          release-type: node

Why You Need It: Automates releases, ensuring timely updates and reducing manual work.

Final Thoughts

These five GitHub Actions can significantly enhance your open-source project maintenance by automating repetitive tasks, keeping things organized, and ensuring code quality.

By integrating these workflows, you can focus on what truly matters: writing great code and building a thriving community.

Are you using GitHub Actions to streamline your workflow? Let us know in the comments below!

Share this article