|
| 1 | +# Migration to Centralized Reusable Workflows |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +This setup establishes the `.github` repository as a centralized meta repository for all devops-infra workflows, eliminating duplication across ~14 repositories. |
| 6 | + |
| 7 | +## What Was Created |
| 8 | + |
| 9 | +### 1. Reusable Workflows (`.github/workflows/`) |
| 10 | + |
| 11 | +Five centralized workflows: |
| 12 | + |
| 13 | +| Workflow | Purpose | Replaces | |
| 14 | +|--------------------------------|-----------------------------------------|--------------------------------| |
| 15 | +| `auto-create-pull-request.yml` | Auto-create PRs for feature branches | `auto-create-pull-request.yml` | |
| 16 | +| `auto-create-release.yml` | Create releases from merged PRs | `auto-create-release.yml` | |
| 17 | +| `cron-check-dependencies.yml` | Scheduled dependency testing | `cron-check-dependencies.yml` | |
| 18 | +| `manual-update-version.yml` | Manual version bumps | `manual-update-version.yml` | |
| 19 | +| `manual-sync-common-files.yml` | Sync common files from template sources | `manual-sync-common-files.yml` | |
| 20 | + |
| 21 | +### 2. Example Caller Workflows (`.github/workflows/examples/`) |
| 22 | + |
| 23 | +Ready-to-use examples showing how repositories call the centralized workflows: |
| 24 | +- `auto-create-pull-request.yml` |
| 25 | +- `auto-create-release.yml` |
| 26 | +- `cron-check-dependencies.yml` |
| 27 | +- `manual-update-version.yml` |
| 28 | +- `manual-sync-common-files.yml` |
| 29 | + |
| 30 | +### 3. Reusable Taskfiles (`.github/taskfiles/`) |
| 31 | + |
| 32 | +Shared Taskfile templates used by the sync-files workflow: |
| 33 | +- `Taskfile.yml` |
| 34 | +- `Taskfile.cicd.yml` |
| 35 | +- `Taskfile.docker.yml` |
| 36 | +- `Taskfile.variables.yml` |
| 37 | + |
| 38 | +### 4. Reusable Configs (`.github/configs/`) |
| 39 | + |
| 40 | +Shared config files synced by `sync:configs` and `sync:ignores`: |
| 41 | +- `.editorconfig` |
| 42 | +- `.hadolint.yaml` |
| 43 | +- `.pre-commit-config.yaml` |
| 44 | +- `.shellcheckrc` |
| 45 | +- `.yamllint.yml` |
| 46 | +- `.gitignore` |
| 47 | +- `.dockerignore` |
| 48 | + |
| 49 | +### 5. Documentation |
| 50 | + |
| 51 | +- `README.md` - Complete guide to centralized workflows, migration process, and troubleshooting |
| 52 | +- Updated `copilot-instructions.md` - Added centralized workflow section and Task runner info |
| 53 | + |
| 54 | +### 6. Migration Script |
| 55 | + |
| 56 | +`migrate-to-reusable.sh` - Automated script to migrate repositories with: |
| 57 | +- Dry-run mode for testing |
| 58 | +- Automatic backup creation |
| 59 | +- Selective workflow migration |
| 60 | +- Clear next-steps guidance |
| 61 | + |
| 62 | +## Migration Process |
| 63 | + |
| 64 | +### Step 1: Commit and Push to .github Repository |
| 65 | + |
| 66 | +```bash |
| 67 | +cd /Users/christoph/IdeaProjects/devops-infra/.github |
| 68 | +git add .github/workflows/*.yml |
| 69 | +git add .github/workflows/examples/ |
| 70 | +git add .github/workflows/README.md |
| 71 | +git add .github/workflows/migrate-to-reusable.sh |
| 72 | +git add .github/configs/ |
| 73 | +git add .github/taskfiles/ |
| 74 | +git add copilot-instructions.md |
| 75 | +git commit -m "feat: Add centralized workflows for organization" |
| 76 | +git push origin master |
| 77 | +``` |
| 78 | + |
| 79 | +### Step 2: Migrate Individual Repositories |
| 80 | + |
| 81 | +Choose one of these approaches: |
| 82 | + |
| 83 | +#### Option A: Manual Migration (Recommended for first repo) |
| 84 | + |
| 85 | +1. **Pick a test repository** (suggest `action-format-hcl` as it's simpler) |
| 86 | + |
| 87 | +2. **Copy example workflows:** |
| 88 | + ```bash |
| 89 | + cd /Users/christoph/IdeaProjects/devops-infra/action-format-hcl |
| 90 | + |
| 91 | + # Backup existing workflows |
| 92 | + cp -r .github/workflows .github/workflows.backup |
| 93 | + |
| 94 | + # Copy examples |
| 95 | + cp ../. github/.github/workflows/examples/*.yml .github/workflows/ |
| 96 | + ``` |
| 97 | + |
| 98 | +3. **Remove old workflows:** |
| 99 | + ```bash |
| 100 | + # Keep only the new caller workflows |
| 101 | + ls .github/workflows/ |
| 102 | + ``` |
| 103 | + |
| 104 | +4. **Test:** |
| 105 | + ```bash |
| 106 | + git checkout -b test/central-workflows |
| 107 | + git add .github/workflows/ |
| 108 | + git commit -m "test: Migrate to centralized workflows" |
| 109 | + git push origin test/central-workflows |
| 110 | + ``` |
| 111 | + |
| 112 | +5. **Verify in GitHub Actions UI** that the workflow runs correctly |
| 113 | + |
| 114 | +#### Option B: Automated Migration |
| 115 | + |
| 116 | +```bash |
| 117 | +cd /Users/christoph/IdeaProjects/devops-infra/.github/.github/workflows |
| 118 | + |
| 119 | +# Dry-run first |
| 120 | +./migrate-to-reusable.sh ../../action-format-hcl --dry-run |
| 121 | + |
| 122 | +# If looks good, run for real |
| 123 | +./migrate-to-reusable.sh ../../action-format-hcl |
| 124 | + |
| 125 | +# Migrate specific workflows only |
| 126 | +./migrate-to-reusable.sh ../../docker-terragrunt --workflows pr,release |
| 127 | +``` |
| 128 | + |
| 129 | +### Step 3: Rollout to All Repositories |
| 130 | + |
| 131 | +Once verified with one repository, migrate the rest: |
| 132 | + |
| 133 | +**Repositories to migrate:** |
| 134 | +- action-commit-push |
| 135 | +- action-format-hcl ✓ (use as test) |
| 136 | +- action-pull-request |
| 137 | +- action-terraform-copy-vars |
| 138 | +- action-terraform-validate |
| 139 | +- action-tflint |
| 140 | +- docker-simple-runner |
| 141 | +- docker-terragrunt |
| 142 | +- template-action |
| 143 | + |
| 144 | +**Repositories that may need customization:** |
| 145 | +- `velez` - Uses Python/pytest, not Docker (may need different workflow) |
| 146 | + |
| 147 | +**Archived repositories (excluded from automation):** |
| 148 | +- `docker-okta-aws-sso` |
| 149 | + |
| 150 | +### Step 4: Cleanup |
| 151 | + |
| 152 | +After successful migration and testing: |
| 153 | + |
| 154 | +```bash |
| 155 | +# In each repository |
| 156 | +rm -rf .github/workflows.backup* |
| 157 | +``` |
| 158 | + |
| 159 | +## Benefits After Migration |
| 160 | + |
| 161 | +### Before |
| 162 | +- ~70 duplicate workflow files across 14 repositories |
| 163 | +- Bug fixes require updating 14 repos individually |
| 164 | +- Inconsistent workflow versions between repos |
| 165 | +- High maintenance burden |
| 166 | + |
| 167 | +### After |
| 168 | +- 5 centralized workflows + ~14 small caller workflows |
| 169 | +- Update logic once in `.github`, applies everywhere |
| 170 | +- Guaranteed consistency across all repos |
| 171 | +- Minimal maintenance |
| 172 | + |
| 173 | +## Customization Examples |
| 174 | + |
| 175 | +### Disable Docker for non-Docker repos |
| 176 | +```yaml |
| 177 | +jobs: |
| 178 | + call-workflow: |
| 179 | + uses: devops-infra/.github/.github/workflows/auto-create-pull-request.yml@master |
| 180 | + with: |
| 181 | + enable-docker: false |
| 182 | + enable-lint: true |
| 183 | +``` |
| 184 | +
|
| 185 | +### Use different runner |
| 186 | +```yaml |
| 187 | +jobs: |
| 188 | + call-workflow: |
| 189 | + uses: devops-infra/.github/.github/workflows/auto-create-pull-request.yml@master |
| 190 | + with: |
| 191 | + runs-on: ubuntu-latest |
| 192 | +``` |
| 193 | +
|
| 194 | +### Single-arch builds |
| 195 | +```yaml |
| 196 | +jobs: |
| 197 | + call-workflow: |
| 198 | + uses: devops-infra/.github/.github/workflows/auto-create-pull-request.yml@master |
| 199 | + with: |
| 200 | + docker-platforms: amd64 |
| 201 | +``` |
| 202 | +
|
| 203 | +## Rollback Plan |
| 204 | +
|
| 205 | +If issues occur: |
| 206 | +
|
| 207 | +1. **Individual repository:** Restore from `.github/workflows.backup` |
| 208 | +2. **Organization-wide:** Temporarily pin to old workflow files until fixed |
| 209 | +3. **Revert .github changes:** `git revert <commit>` in `.github` repository |
| 210 | + |
| 211 | +## Future Enhancements |
| 212 | + |
| 213 | +1. **Version tagging:** Pin workflows to tags instead of `@master` for stability |
| 214 | + ```yaml |
| 215 | + uses: devops-infra/.github/.github/workflows/auto-create-pull-request.yml@v1.0.0 |
| 216 | + ``` |
| 217 | + |
| 218 | +2. **Python-specific workflow:** Create centralized workflow for `velez` and similar Python projects |
| 219 | + |
| 220 | +3. **Makefile-specific workflow:** Create centralized workflow for repos still using Make |
| 221 | + |
| 222 | +4. **Auto-sync workflow:** Create workflow that automatically updates caller workflows in all repos when examples change |
| 223 | + |
| 224 | +5. **Workflow testing:** Add tests to validate centralized workflows before deployment |
| 225 | + |
| 226 | +## Support |
| 227 | + |
| 228 | +For issues or questions: |
| 229 | +- Check `README.md` in `.github/.github/workflows/` |
| 230 | +- Review examples in `examples/` directory |
| 231 | +- Test with `--dry-run` flag first |
| 232 | +- Start with one simple repository before migrating all |
| 233 | + |
| 234 | +## Checklist |
| 235 | + |
| 236 | +- [ ] Commit and push centralized workflows to `.github` repository |
| 237 | +- [ ] Test migration with `action-format-hcl` (or similar simple repo) |
| 238 | +- [ ] Verify GitHub Actions run successfully |
| 239 | +- [ ] Migrate remaining action-* repositories |
| 240 | +- [ ] Migrate docker-* repositories (may need customization) |
| 241 | +- [ ] Handle special cases (velez) |
| 242 | +- [ ] Skip archived repositories (docker-okta-aws-sso) |
| 243 | +- [ ] Clean up backup directories |
| 244 | +- [ ] Update any documentation referencing old workflows |
| 245 | +- [ ] Consider implementing version tagging for workflows |
0 commit comments