This directory contains reusable Taskfile templates for GitHub operations, including managing submodules, handling releases, merging pull requests, working with GitHub Container Registry, and more.
- GitHub CLI installed
- Docker installed (for GHCR tasks)
- jq installed (for JSON processing)
- Task installed (
brew install go-task/tap/go-task)
Adds a GitHub repository as a submodule.
task add-git-submodules ORG=myorg REGEXP=my-repo TARGET_DIR=modulesRequired variables:
ORG: GitHub organization nameREGEXP: Repository name (exact match)TARGET_DIR: Directory where submodule will be added
Validates that GitHub CLI is installed on your system.
task check-gh-cliCreates a GitHub release using a changelog file or auto-generated notes.
# Using changelog file (default: changelogs/CHANGELOG.rst)
task create-release NEXT_VERSION=1.0.0
# Using custom changelog file
task create-release NEXT_VERSION=1.0.0 CHANGELOG_FILE=CHANGELOG.md
# Force auto-generated notes
task create-release NEXT_VERSION=1.0.0 AUTO_NOTES=trueRequired variables:
NEXT_VERSION: Version number for the release
Optional variables:
CHANGELOG_FILE: Path to changelog file (default:changelogs/CHANGELOG.rst)AUTO_NOTES: Force use of auto-generated notes
Shows git diff while excluding specified patterns.
task diff-changes BASE_BRANCH=main EXCLUDES="test,.github,.terraform*,*.md"Required variables:
BASE_BRANCH: Branch to compare against
Optional variables:
EXCLUDES: Comma-separated list of patterns to exclude
Sets up GitHub authentication for GitHub Container Registry access.
task ghcr-setupPulls and tags Docker images from GitHub Container Registry.
# Pull with default settings
task ghcr-pull-image IMAGE=my-app
# Pull with custom tag
task ghcr-pull-image IMAGE=my-app TAG=v1.2.3
# Pull from custom registry/namespace
task ghcr-pull-image IMAGE=my-app REGISTRY=ghcr.io NAMESPACE=myorgRequired variables:
IMAGE: Image name to pull
Optional variables:
TAG: Image tag (defaults to value in taskfile)REGISTRY: Container registry URLNAMESPACE: Registry namespaceLOCAL_IMAGE: Local image name (defaults to IMAGE)LOCAL_TAG: Local tag name (defaults to TAG)
Tags and pushes Docker images to GitHub Container Registry.
# Push with default settings
task ghcr-push-image IMAGE=my-app
# Push with custom tag
task ghcr-push-image IMAGE=my-app TAG=v1.2.3
# Push with additional tags
task ghcr-push-image IMAGE=my-app ADDITIONAL_TAGS="latest,stable"
# Push from custom local tag
task ghcr-push-image IMAGE=my-app LOCAL_TAG=devRequired variables:
IMAGE: Image name to push
Optional variables:
TAG: Remote image tag (defaults to value in taskfile)LOCAL_TAG: Local tag to push from (default:latest)ADDITIONAL_TAGS: Comma-separated list of additional tags to pushREGISTRY: Container registry URLNAMESPACE: Registry namespace
Interactively merge the current branch's pull request with squash and cleanup. Checks CI status, prompts for confirmation if checks haven't passed, then merges and returns you to the default branch with cleanup.
task pr-mergeThis task will:
- Find the PR for your current branch
- Check CI status and prompt if checks haven't passed
- Squash merge the PR and delete the remote branch
- Switch to the default branch (main/master) and pull latest changes
- Clean up local branches with
git fetch --prune
Pulls updates for all git repositories in the current directory.
task pull-git-reposShows branches you worked on most recently in a project.
# Show recent branches in current directory
task recent-branches
# Show recent branches in a specific project
task recent-branches PROJECT_PATH=/path/to/project
# Show more branches (default is 10)
task recent-branches LIMIT=20Optional variables:
PROJECT_PATH: Path to the git repository (default: current directory)LIMIT: Number of branches to show (default: 10)
Shows the most recently worked on git projects by scanning for git repositories.
# Show 5 most recent projects in home directory
task recent-projects
# Search in a specific path
task recent-projects SEARCH_PATH=/path/to/projects
# Show more projects
task recent-projects LIMIT=10
# Search deeper in directory tree
task recent-projects MAX_DEPTH=5Optional variables:
SEARCH_PATH: Directory to search for git repositories (default:$HOME)LIMIT: Number of projects to show (default: 5)MAX_DEPTH: Maximum depth to search for git repositories (default: 3)
Removes one or more git submodules and cleans up related files.
task remove-git-submodules TARGET_DIR=modules REGEXP="^prefix-.*"Required variables:
TARGET_DIR: Directory containing the submodulesREGEXP: Pattern to match submodule names to remove
Initializes and updates submodules idempotently (safe to run multiple times).
task sync-submodules-
Adding a submodule:
task add-git-submodules ORG=mycompany REGEXP=api-service TARGET_DIR=services
-
Synchronizing all submodules after cloning a repository:
task sync-submodules
-
Creating a release with auto-generated notes:
task create-release NEXT_VERSION=1.2.0 AUTO_NOTES=true
-
Removing submodules matching a pattern:
task remove-git-submodules TARGET_DIR=modules REGEXP="^api-.*" -
Viewing changes excluding certain patterns:
task diff-changes BASE_BRANCH=main EXCLUDES="test,docs/*,*.md" -
Working with GitHub Container Registry:
# First-time setup task ghcr-setup # Pull an image task ghcr-pull-image IMAGE=my-app TAG=v1.0.0 # Push an image with multiple tags task ghcr-push-image IMAGE=my-app TAG=v1.0.0 ADDITIONAL_TAGS="latest,stable"
-
Merging your current PR:
# When you're ready to merge your current branch's PR task pr-merge -
Finding recent work:
# See which projects you worked on recently task recent-projects # See recent branches in current project task recent-branches # See recent branches in a specific project task recent-branches PROJECT_PATH=/path/to/project LIMIT=15
You can extend these tasks in your own Taskfile by importing this template and overriding or adding new tasks:
version: "3"
includes:
gh:
taskfile: ./github.yml
optional: true
tasks:
# Override or extend existing tasks
create-release:
deps: [gh:create-release]
cmds:
- echo "Additional steps after release creation..."
# Add new tasks that use the base tasks
release-and-merge:
cmds:
- task: gh:create-release
vars:
NEXT_VERSION: 1.0.0
- task: gh:merge-pull-requests- The GitHub CLI must be authenticated (
gh auth login) before using these tasks - GHCR tasks require Docker to be installed and running
- The
ghcr-setuptask configures GitHub authentication with the necessary scopes for package access - All tasks have appropriate error handling and validation
- The
pr-mergetask is for interactive merging of your current branch's PR with CI check validation and cleanup - Release tasks will use a changelog file if it exists, otherwise will generate notes automatically
- The
sync-submodulestask is idempotent and can be run multiple times without issues - The
pull-git-repostask skips repositories with uncommitted changes - The
recent-branchestask shows branches sorted by last commit date - The
recent-projectstask scans for git repositories and sorts them by last commit timestamp