|
| 1 | +# CI/CD Automation Scripts |
| 2 | + |
| 3 | +This directory contains automation scripts for managing GitHub issues and project boards. |
| 4 | + |
| 5 | +## Scripts Overview |
| 6 | + |
| 7 | +### 1. `issue.py` - Issue Management |
| 8 | + |
| 9 | +Automatically processes GitHub issues, particularly game requests: |
| 10 | + |
| 11 | +- Detects issues with `[Gmae Request]` prefix |
| 12 | +- Searches for relevant links on GitHub Pages |
| 13 | +- Posts automated comments with search results |
| 14 | + |
| 15 | +### 2. `move_to_production.py` - Project Board Automation |
| 16 | + |
| 17 | +Moves project items from "Done" status to "In Production" status: |
| 18 | + |
| 19 | +- Queries GitHub Projects v2 API using GraphQL |
| 20 | +- Finds all items with status "Done" |
| 21 | +- Updates them to "In Production" status |
| 22 | +- Used for production deployment automation |
| 23 | + |
| 24 | +### 3. `test_production_move.py` - Testing Script |
| 25 | + |
| 26 | +Manual testing script for the production move operation: |
| 27 | + |
| 28 | +- Allows testing the move operation without triggering workflows |
| 29 | +- Supports dry-run mode (future enhancement) |
| 30 | +- Useful for debugging and validation |
| 31 | + |
| 32 | +## GitHub Workflows |
| 33 | + |
| 34 | +### Issue Management (`.github/workflows/issue.yml`) |
| 35 | + |
| 36 | +Triggers on: |
| 37 | + |
| 38 | +- Issue opened |
| 39 | +- Issue edited |
| 40 | + |
| 41 | +Actions: |
| 42 | + |
| 43 | +- Runs `issue.py` script |
| 44 | +- Posts automated comments for game requests |
| 45 | + |
| 46 | +### Production Deployment (`.github/workflows/production_deploy.yml`) |
| 47 | + |
| 48 | +Triggers on: |
| 49 | + |
| 50 | +- Push to `prod` branch |
| 51 | + |
| 52 | +Actions: |
| 53 | + |
| 54 | +- Runs `move_to_production.py` script |
| 55 | +- Moves all "Done" items to "In Production" in project #4 |
| 56 | + |
| 57 | +## Setup Requirements |
| 58 | + |
| 59 | +### GitHub App Configuration |
| 60 | + |
| 61 | +Both workflows use a GitHub App for authentication: |
| 62 | + |
| 63 | +1. **Secrets Required:** |
| 64 | + |
| 65 | + - `GH_APP_ID` - Your GitHub App ID |
| 66 | + - `GH_PRIVATE_KEY` - Your GitHub App private key |
| 67 | + |
| 68 | +2. **App Permissions:** |
| 69 | + - Issues: Read & Write (for issue comments) |
| 70 | + - Projects: Read & Write (for project board updates) |
| 71 | + - Repository: Read (for workflow access) |
| 72 | + |
| 73 | +### Project Configuration |
| 74 | + |
| 75 | +The production deployment script assumes: |
| 76 | + |
| 77 | +- Organization: `EducationalTools` |
| 78 | +- Project number: `4` |
| 79 | +- Status field with options: "Done" and "In Production" |
| 80 | + |
| 81 | +These can be customized by modifying the workflow or script parameters. |
| 82 | + |
| 83 | +## Usage |
| 84 | + |
| 85 | +### Automatic Usage |
| 86 | + |
| 87 | +The workflows run automatically based on their triggers: |
| 88 | + |
| 89 | +- Issue workflow: When issues are opened/edited |
| 90 | +- Production workflow: When code is pushed to `prod` branch |
| 91 | + |
| 92 | +### Manual Testing |
| 93 | + |
| 94 | +To test the production move operation manually: |
| 95 | + |
| 96 | +```bash |
| 97 | +# Install dependencies |
| 98 | +pip install requests |
| 99 | + |
| 100 | +# Test with your GitHub token |
| 101 | +python ci/scripts/test_production_move.py --token YOUR_GITHUB_TOKEN |
| 102 | + |
| 103 | +# Test with different organization/project |
| 104 | +python ci/scripts/test_production_move.py \ |
| 105 | + --token YOUR_TOKEN \ |
| 106 | + --org YourOrganization \ |
| 107 | + --project 5 |
| 108 | +``` |
| 109 | + |
| 110 | +### Direct Script Usage |
| 111 | + |
| 112 | +You can also run the scripts directly: |
| 113 | + |
| 114 | +```bash |
| 115 | +# Process a specific issue |
| 116 | +python ci/scripts/issue.py -n 123 -t YOUR_TOKEN |
| 117 | + |
| 118 | +# Move project items to production |
| 119 | +python ci/scripts/move_to_production.py -t YOUR_TOKEN -o EducationalTools -p 4 |
| 120 | +``` |
| 121 | + |
| 122 | +## Dependencies |
| 123 | + |
| 124 | +- `requests` - HTTP client for GitHub API calls |
| 125 | +- `googlesearch-python` - For searching game links (issue.py only) |
| 126 | + |
| 127 | +## Error Handling |
| 128 | + |
| 129 | +The scripts include error handling for common scenarios: |
| 130 | + |
| 131 | +- Invalid tokens or permissions |
| 132 | +- Missing projects or fields |
| 133 | +- Network issues |
| 134 | +- GraphQL API errors |
| 135 | + |
| 136 | +## GraphQL Queries |
| 137 | + |
| 138 | +The project automation uses GitHub's GraphQL API v4 for efficient data retrieval and mutations. Key operations: |
| 139 | + |
| 140 | +1. **Project Data Query** - Gets project ID and field information |
| 141 | +2. **Items Query** - Retrieves all project items with their status values |
| 142 | +3. **Update Mutation** - Changes item status from "Done" to "In Production" |
| 143 | + |
| 144 | +## Future Enhancements |
| 145 | + |
| 146 | +Potential improvements: |
| 147 | + |
| 148 | +- Dry-run mode for testing changes |
| 149 | +- Support for custom field names |
| 150 | +- Better error reporting and logging |
| 151 | +- Slack/Discord notifications |
| 152 | +- Rollback capabilities |
0 commit comments