Control GitHub Actions workflow execution to avoid infinite loops and unnecessary builds. Implement these practices:

  1. Add paths-ignore filters for generated files that might trigger the workflow again:
on:
  push:
    branches: ["main"]
    paths-ignore:
      - version.txt  # Skip when only version files change
  1. Explicitly specify branch references when checking out code to ensure the correct version is processed:
- name: Checkout code
  uses: actions/checkout@v4
  with:
    ref: main  # Explicitly reference the target branch
    fetch-depth: 0
  1. Target the correct branch when pushing changes to avoid misdirected commits:
- name: Push changes
  uses: ad-m/github-push-action@master
  with:
    github_token: $
    branch: trails  # Explicitly specify the target branch
  1. Restrict event triggers to only required events to prevent premature actions:
on:
  push:
    branches: [ "main" ]
  # pull_request:  # Remove if not needed for publishing operations
  #   branches: [ "main" ]

These practices ensure your workflows run only when needed and operate on the correct code, preventing wasteful CI resources and confusing version history.