macOS GitHub CLI Complete Automation Series - Part 5: Advanced Workflows and Real-World Application
⏱️ Estimated reading time: 25 min
Introduction to the Final Part
This is the final installment of the macOS GitHub CLI Complete Automation Series. We will integrate all the systems built so far and create a complete workflow ready for immediate production use. This part covers CI/CD integration, team onboarding automation, and performance optimization.
Integrated System Architecture
1. Master Control System
# Master control script
cat > ~/scripts/github-cli/core/master-controller.sh << 'EOF'
#!/bin/bash
# GitHub CLI Master Control System
export GITHUB_CLI_VERSION="2.0"
export MASTER_CONFIG_DIR="$HOME/scripts/github-cli/config"
export MASTER_LOG_DIR="$HOME/Documents/github-automation/logs"
# System status check
function gh_system_status() {
echo "GitHub CLI Automation System Status"
echo "=================================="
echo
# Basic environment check
echo "Environment Info:"
echo " GitHub CLI: $(gh --version | head -1)"
echo " Current account: $(gh api user -q .login 2>/dev/null || echo 'not authenticated')"
echo " Context: $(cat ~/.config/gh/current_context 2>/dev/null || echo 'not set')"
echo " Workspace: $(current_workspace)"
echo
# Script system status
echo "Script System:"
local script_dirs=("core" "wiki" "utils")
for dir in "${script_dirs[@]}"; do
if [[ -d "$HOME/scripts/github-cli/$dir" ]]; then
local file_count=$(find "$HOME/scripts/github-cli/$dir" -name "*.sh" | wc -l)
echo " $dir: OK ($file_count scripts)"
else
echo " $dir: MISSING"
fi
done
echo
# Active projects
echo "Active Projects:"
gh project list --owner @me --limit 3 --format json | \
jq -r '.[] | " \(.title): \(.url)"' 2>/dev/null || echo " None"
echo
# Recent activity
echo "Recent Activity (7 days):"
local recent_issues=$(gh issue list --author @me --search "created:>=$(date -d '-7 days' '+%Y-%m-%d')" --json number | jq length)
local recent_prs=$(gh pr list --author @me --search "created:>=$(date -d '-7 days' '+%Y-%m-%d')" --json number | jq length)
echo " Issues created: $recent_issues"
echo " PRs created: $recent_prs"
}
# System self-diagnosis
function gh_system_doctor() {
echo "GitHub CLI System Diagnosis"
echo "========================"
echo
local issues=0
# Check required tools
local required_tools=("gh" "git" "jq" "curl")
for tool in "${required_tools[@]}"; do
if command -v "$tool" >/dev/null 2>&1; then
echo "OK: $tool installed"
else
echo "MISSING: $tool not installed"
issues=$((issues + 1))
fi
done
echo
# Check authentication
if gh auth status >/dev/null 2>&1; then
echo "OK: GitHub CLI authenticated"
else
echo "FAIL: GitHub CLI authentication required"
issues=$((issues + 1))
fi
# Check script permissions
if [[ -x "$HOME/scripts/github-cli/core/master-controller.sh" ]]; then
echo "OK: Script execute permission confirmed"
else
echo "FAIL: Script execute permission missing"
issues=$((issues + 1))
fi
# Check config file
if [[ -f "$HOME/.config/gh/current_context" ]]; then
echo "OK: Context config confirmed"
else
echo "WARNING: Context not set (recommended)"
fi
echo
if [[ $issues -eq 0 ]]; then
echo "System is operating normally!"
else
echo "WARNING: $issues issue(s) found."
echo "Run 'gh_system_repair' to attempt automatic repair."
fi
}
# Automatic system repair
function gh_system_repair() {
echo "Starting automatic system repair..."
# Restore script permissions
find "$HOME/scripts/github-cli" -name "*.sh" -exec chmod +x {} \;
echo "OK: Script execute permissions restored"
# Restore directory structure
mkdir -p "$HOME/scripts/github-cli"/{core,wiki,utils,config}
mkdir -p "$HOME/Documents/github-automation/logs"
echo "OK: Directory structure restored"
# Clean up logs
find "$MASTER_LOG_DIR" -name "*.log" -mtime +30 -delete 2>/dev/null
echo "OK: Old logs cleaned up"
echo "System repair complete!"
}
EOF
chmod +x ~/scripts/github-cli/core/master-controller.sh
2. CI/CD Pipeline Integration
# GitHub Actions integration system
cat > ~/scripts/github-cli/core/cicd-integration.sh << 'EOF'
#!/bin/bash
# Automatic CI/CD pipeline creation
function create_cicd_workflow() {
local project_type="${1:-general}"
local workflow_dir=".github/workflows"
mkdir -p "$workflow_dir"
case "$project_type" in
"node"|"javascript"|"typescript")
create_node_workflow "$workflow_dir"
;;
"python")
create_python_workflow "$workflow_dir"
;;
"go")
create_go_workflow "$workflow_dir"
;;
*)
create_general_workflow "$workflow_dir"
;;
esac
# GitHub CLI automation integration
create_automation_workflow "$workflow_dir"
echo "OK: CI/CD workflow created."
}
# Node.js workflow
function create_node_workflow() {
local workflow_dir="$1"
cat > "$workflow_dir/ci.yml" << 'NODEEOF'
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: $
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Run linting
run: npm run lint
- name: Update Wiki
if: github.ref == 'refs/heads/main'
run: |
# Automatic wiki update (using GitHub CLI)
npm run docs:generate || true
gh extension install github/gh-wiki || true
gh wiki sync || true
env:
GITHUB_TOKEN: $
NODEEOF
}
# Automation integration workflow
function create_automation_workflow() {
local workflow_dir="$1"
cat > "$workflow_dir/automation.yml" << 'AUTOEOF'
name: GitHub CLI Automation
on:
issues:
types: [opened, closed, labeled]
pull_request:
types: [opened, closed, merged]
schedule:
- cron: '0 9 * * *' # daily at 9 AM
jobs:
automation:
runs-on: ubuntu-latest
steps:
- name: Auto-assign issues
if: github.event_name == 'issues' && github.event.action == 'opened'
run: |
# Automatic issue assignment and project addition
gh issue edit $ --add-assignee "@team"
gh project item-add $ --url $
env:
GITHUB_TOKEN: $
- name: Update project status
if: github.event_name == 'pull_request' && github.event.action == 'opened'
run: |
# Update related issue status when PR is created
gh pr view $ --json body | \
jq -r '.body' | grep -o '#[0-9]\+' | \
xargs -I {} gh issue edit {} --add-label "in-review"
env:
GITHUB_TOKEN: $
- name: Daily report
if: github.event_name == 'schedule'
run: |
# Generate and notify daily report
gh issue create --title "Daily Report $(date +%Y-%m-%d)" \
--body "Automatically generated daily activity report" \
--label "report,automated"
env:
GITHUB_TOKEN: $
AUTOEOF
}
# Deployment monitoring
function monitor_deployment() {
local workflow_name="$1"
local max_wait="${2:-300}" # 5 minutes
echo "Starting deployment monitoring: $workflow_name"
local start_time=$(date +%s)
while true; do
local status=$(gh run list --workflow="$workflow_name" --limit=1 --json status -q '.[0].status')
local current_time=$(date +%s)
local elapsed=$((current_time - start_time))
case "$status" in
"completed")
local conclusion=$(gh run list --workflow="$workflow_name" --limit=1 --json conclusion -q '.[0].conclusion')
if [[ "$conclusion" == "success" ]]; then
echo "Deployment successful! (${elapsed}s elapsed)"
else
echo "Deployment failed: $conclusion"
gh run view --log-failed
fi
break
;;
"in_progress")
echo "Deployment in progress... (${elapsed}s elapsed)"
;;
"queued")
echo "Deployment queued... (${elapsed}s elapsed)"
;;
esac
if [[ $elapsed -gt $max_wait ]]; then
echo "Monitoring timeout (${max_wait}s)"
break
fi
sleep 10
done
}
EOF
chmod +x ~/scripts/github-cli/core/cicd-integration.sh
3. Team Onboarding Automation
# Team onboarding system
cat > ~/scripts/github-cli/core/team-onboarding.sh << 'EOF'
#!/bin/bash
# New team member onboarding
function onboard_team_member() {
local username="$1"
local role="${2:-developer}"
local team="${3:-dev-team}"
if [[ -z "$username" ]]; then
echo "Usage: onboard_team_member <GitHub username> [role] [team]"
return 1
fi
echo "Onboarding new team member: @$username"
echo "================================="
# 1. Grant repository access
echo "Setting up repository permissions..."
local repos=$(gh repo list --limit 100 --json name -q '.[].name')
while IFS= read -r repo; do
gh api "repos/:owner/$repo/collaborators/$username" \
-X PUT -f permission="push" 2>/dev/null && \
echo " OK: $repo access granted"
done <<< "$repos"
# 2. Add to team
echo "Adding to team..."
gh api "orgs/:owner/teams/$team/memberships/$username" \
-X PUT -f role="member" 2>/dev/null && \
echo " OK: Added to $team team"
# 3. Create onboarding issue
echo "Creating onboarding checklist..."
local onboarding_issue=$(gh issue create \
--title "Welcome @$username - Onboarding Checklist" \
--body "# New Team Member Onboarding Checklist
Welcome to the team, @$username!
## Account Setup
- [ ] Enable GitHub 2FA
- [ ] Update profile picture and information
- [ ] Register SSH key
## Development Environment Setup
- [ ] Install and configure GitHub CLI
- [ ] Set up automation scripts
- [ ] Configure IDE/editor
## Project Understanding
- [ ] Read wiki documentation
- [ ] Review codebase
- [ ] Understand architecture documentation
## First Contribution
- [ ] Complete a Good First Issue
- [ ] Create first PR
- [ ] Participate in code review
## Team Introduction
- [ ] Attend team meeting
- [ ] 1:1 meeting with mentor
- [ ] Join team channels
## Need Help?
- Technical issues: @tech-leads
- Process questions: @team-leads
- General inquiries: @$team
---
Assignee: @$username
Team: $team" \
--assignee "$username" \
--label "onboarding,$team" \
--format json | jq -r '.number')
echo "OK: Onboarding issue #$onboarding_issue created"
# 4. Welcome message
gh issue comment "$onboarding_issue" --body "Welcome @$username to the $team team as $role!
Please work through the checklist above as you get settled in.
Feel free to mention us anytime you have questions!"
echo "Onboarding process complete!"
}
# Create project setup guide
function create_project_setup_guide() {
local project_name="$1"
if [[ -z "$project_name" ]]; then
echo "Usage: create_project_setup_guide <project name>"
return 1
fi
echo "Generating project setup guide..."
# Create setup guide issue
gh issue create \
--title "Project Setup Guide: $project_name" \
--body "# $project_name Project Setup Guide
## Quick Start
### 1. Clone the repository
\`\`\`bash
git clone $(gh repo view --json cloneUrl -q .cloneUrl)
cd $project_name
\`\`\`
### 2. Install dependencies
\`\`\`bash
# Auto-detect project type
~/scripts/github-cli/utils/auto-setup.sh
\`\`\`
### 3. Configure development environment
\`\`\`bash
# GitHub CLI automation setup
gh extension install github/gh-cli-automation
\`\`\`
## Development Workflow
### Issue-based development
1. \`gh issue create\` - Create new issue
2. \`issue_start <number>\` - Start work
3. \`issue_finish <number>\` - Complete work
### Code review
1. \`gh pr create\` - Create PR
2. \`auto_assign_reviewers <PR number>\` - Auto-assign reviewers
3. \`gh pr merge\` - Merge
## Additional Resources
- [API Documentation](../../wiki/API-Documentation)
- [Coding Conventions](../../wiki/Coding-Conventions)
- [Deployment Guide](../../wiki/Deployment-Guide)
---
*This guide was automatically generated.*" \
--label "documentation,guide" \
--pin
echo "OK: Project setup guide created."
}
# Team performance report
function generate_team_report() {
local team_name="${1:-dev-team}"
local period="${2:-30}"
echo "Team Report: $team_name (last ${period} days)"
echo "============================================="
echo
# Team member activity
echo "Team Member Contributions:"
gh api "search/issues?q=author:@$team_name+type:pr+closed:>$(date -d "-$period days" +%Y-%m-%d)" | \
jq -r '.items[] | .user.login' | sort | uniq -c | sort -nr | \
while read count member; do
echo " $member: $count PRs"
done
echo
# Issue handling status
echo "Issue Status:"
local created=$(gh issue list --search "team:$team_name created:>$(date -d "-$period days" +%Y-%m-%d)" --json number | jq length)
local closed=$(gh issue list --search "team:$team_name closed:>$(date -d "-$period days" +%Y-%m-%d)" --json number | jq length)
echo " Created: $created"
echo " Closed: $closed"
echo " Resolution rate: $(( closed * 100 / created ))%"
echo
# Code review stats
echo "Code Review Stats:"
local reviewed=$(gh api "search/issues?q=reviewed-by:@$team_name+type:pr+updated:>$(date -d "-$period days" +%Y-%m-%d)" | jq '.total_count')
echo " PRs reviewed: $reviewed"
echo
echo "Improvement Suggestions:"
if [[ $closed -lt $created ]]; then
echo " - Issue resolution speed needs improvement"
fi
if [[ $reviewed -lt 10 ]]; then
echo " - Code review participation needs to increase"
fi
}
EOF
chmod +x ~/scripts/github-cli/core/team-onboarding.sh
4. Final zshrc Integration
# Final integrated zshrc configuration
cat >> ~/.zshrc << 'EOF'
# ===============================================
# GitHub CLI Complete Automation System - Final Integration
# ===============================================
# Load all script modules
if [[ -d "$HOME/scripts/github-cli" ]]; then
# Load config
source "$HOME/scripts/github-cli/config/wiki-config.sh" 2>/dev/null
# Core systems
source "$HOME/scripts/github-cli/core/master-controller.sh"
source "$HOME/scripts/github-cli/core/cicd-integration.sh"
source "$HOME/scripts/github-cli/core/team-onboarding.sh"
# Wiki system (built in Part 4)
for script in "$HOME/scripts/github-cli/wiki"/*.sh; do
[[ -f "$script" ]] && source "$script"
done
echo "GitHub CLI Complete Automation System (v2.0) loaded!"
fi
# Integrated command system
function gh() {
local command="$1"
shift
case "$command" in
# System management
"status") gh_system_status "$@" ;;
"doctor") gh_system_doctor "$@" ;;
"repair") gh_system_repair "$@" ;;
# Team management
"onboard") onboard_team_member "$@" ;;
"team-report") generate_team_report "$@" ;;
# CI/CD
"create-workflow") create_cicd_workflow "$@" ;;
"monitor") monitor_deployment "$@" ;;
# Wiki (Part 4 features)
"wiki") wiki "$@" ;;
# Default GitHub CLI
*) command gh "$command" "$@" ;;
esac
}
# Master dashboard
function github_dashboard() {
clear
echo "
+======================================================+
| GitHub CLI Automation Dashboard |
+======================================================+
"
# System status
gh_system_status
echo
# Today's tasks
echo "Today's Tasks:"
gh issue list --assignee @me --state open --limit 3 --json number,title | \
jq -r '.[] | " * #\(.number): \(.title)"' 2>/dev/null || echo " No tasks!"
echo
# Quick commands
echo "Quick Commands:"
echo " gh status - Check system status"
echo " gh doctor - Diagnose system"
echo " gh wiki update - Update wiki"
echo " issue_start <num> - Start working on an issue"
echo " github_dashboard - This dashboard"
}
# Welcome message on startup
function github_welcome() {
local current_hour=$(date +%H)
local greeting
if [[ $current_hour -lt 12 ]]; then
greeting="Good morning"
elif [[ $current_hour -lt 18 ]]; then
greeting="Good afternoon"
else
greeting="Good evening"
fi
echo "$greeting! GitHub CLI automation system is ready."
echo "Run 'github_dashboard' to view the dashboard."
}
# Run on startup
github_welcome
# Shortcut aliases
alias ghs="gh status"
alias ghd="gh doctor"
alias ghdash="github_dashboard"
EOF
source ~/.zshrc
5. Production Deployment Guide
# Production deployment checklist
cat > ~/scripts/github-cli/utils/deployment-checklist.sh << 'EOF'
#!/bin/bash
# Production deployment checklist
function create_deployment_checklist() {
echo "GitHub CLI Automation System Deployment Checklist"
echo "============================================="
echo
local checks=(
"GitHub CLI installed and authenticated"
"Script directory structure created"
"Permissions configured"
"Work/personal account separation configured"
"Team member onboarding process established"
"CI/CD pipeline integrated"
"Wiki automation configured"
"Monitoring and alerts configured"
)
for i in "${!checks[@]}"; do
echo "$((i+1)). [ ] ${checks[$i]}"
done
echo
echo "Post-deployment verification:"
echo "- Run 'gh doctor' to check system status"
echo "- Train team members on usage"
echo "- Create a plan for regular updates"
}
# Performance optimization tool
function optimize_performance() {
echo "Running GitHub CLI performance optimization..."
# Clear cache
rm -rf "$HOME/.cache/github-cli" 2>/dev/null
mkdir -p "$HOME/.cache/github-cli"
# Clean up logs
find "$HOME/Documents/github-automation/logs" -name "*.log" -mtime +7 -delete 2>/dev/null
# Git configuration optimization
git config --global core.preloadindex true
git config --global core.fscache true
git config --global gc.auto 256
echo "OK: Performance optimization complete!"
}
# Backup system
function backup_configuration() {
local backup_dir="$HOME/Documents/github-automation/backups/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$backup_dir"
echo "Backing up configuration..."
# Back up scripts
cp -r "$HOME/scripts/github-cli" "$backup_dir/"
# Back up config files
cp -r "$HOME/.config/gh" "$backup_dir/" 2>/dev/null || true
# Back up zshrc GitHub section
grep -A 1000 "GitHub CLI Complete Automation" ~/.zshrc > "$backup_dir/zshrc_github_section.txt"
echo "OK: Backup complete: $backup_dir"
echo "Backup contents:"
ls -la "$backup_dir"
}
create_deployment_checklist
EOF
chmod +x ~/scripts/github-cli/utils/deployment-checklist.sh
Series Complete
Congratulations! The GitHub CLI Complete Automation Series is now finished.
Systems Built - Summary
- Fully automated environment (Part 1)
- Multi-account management
- Intelligent zshrc configuration
- Context-based workspaces
- Issue management automation (Part 2)
- AI-based issue classification
- Sprint planning automation
- Workflow state management
- Project management separation (Part 3)
- GitHub Projects v2 automation
- Team collaboration system
- Complete work/personal project separation
- Wiki management automation (Part 4)
- Code-based documentation generation
- Multilingual support
- API documentation auto-sync
- Integrated system (Part 5)
- CI/CD pipeline integration
- Team onboarding automation
- Performance optimization and monitoring
Practical Tips
github_dashboard: Check status every morninggh doctor: Periodic system checkupsgh onboard <username>: Onboard new team memberswiki update: Auto-sync documentationgh team-report: Team performance analysis
You have now fully built an expert-level GitHub automation system!
Other Posts in This Series
- Part 1: Installation and Environment Setup
- Part 2: Complete Issue Management Automation
- Part 3: Project Management + Work/Personal Project Separation
- Part 4: Complete Wiki Management Automation
- Part 5: Advanced Workflows and Real-World Application (this post - final part!)