1
+ name : Template Sync Dispatch
2
+
3
+ on :
4
+ push :
5
+ branches : [main]
6
+ paths :
7
+ - ' tsconfig.json'
8
+ - ' biome.json'
9
+ - ' vitest.config.ts'
10
+ - ' .editorconfig'
11
+ - ' .gitignore'
12
+ - ' .yarnrc.yml'
13
+ - ' package.json'
14
+ - ' .github/workflows/**'
15
+ - ' .husky/**'
16
+ - ' commitlint.config.js'
17
+ - ' src/tools/example*'
18
+ - ' src/utils/validation*'
19
+ - ' .github/template-sync-config.yml'
20
+ workflow_dispatch :
21
+ inputs :
22
+ target_repos :
23
+ description : ' Specific repos to sync (comma-separated, or "all" for discovery)'
24
+ required : false
25
+ default : ' all'
26
+ dry_run :
27
+ description : ' Dry run mode (only check what would be updated)'
28
+ required : false
29
+ default : ' false'
30
+ type : boolean
31
+
32
+ jobs :
33
+ discover-repos :
34
+ runs-on : ubuntu-latest
35
+ outputs :
36
+ repos : ${{ steps.discover.outputs.repos }}
37
+ steps :
38
+ - name : Checkout template
39
+ uses : actions/checkout@v4
40
+
41
+ - name : Setup Node.js
42
+ uses : actions/setup-node@v4
43
+ with :
44
+ node-version : ' 18'
45
+
46
+ - name : Discover target repositories
47
+ id : discover
48
+ env :
49
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
50
+ TARGET_REPOS : ${{ github.event.inputs.target_repos || 'all' }}
51
+ run : |
52
+ cat > discover-repos.js << 'EOF'
53
+ const { Octokit } = require('@octokit/rest');
54
+
55
+ const octokit = new Octokit({
56
+ auth: process.env.GITHUB_TOKEN
57
+ });
58
+
59
+ async function discoverRepos() {
60
+ const targetRepos = process.env.TARGET_REPOS;
61
+
62
+ if (targetRepos !== 'all') {
63
+ // Specific repos provided
64
+ const repos = targetRepos.split(',').map(r => r.trim());
65
+ console.log(JSON.stringify(repos));
66
+ return;
67
+ }
68
+
69
+ // Discover repos created from this template
70
+ const { data: repos } = await octokit.rest.repos.listForOrg({
71
+ org: 'Mearman',
72
+ type: 'public'
73
+ });
74
+
75
+ const mcpRepos = [];
76
+
77
+ for (const repo of repos) {
78
+ // Check if repo has template marker
79
+ try {
80
+ await octokit.rest.repos.getContent({
81
+ owner: 'Mearman',
82
+ repo: repo.name,
83
+ path: '.template-marker'
84
+ });
85
+
86
+ // Check if it's an MCP server repo
87
+ if (repo.name.startsWith('mcp-') && repo.name !== 'mcp-template') {
88
+ mcpRepos.push(repo.name);
89
+ }
90
+ } catch (error) {
91
+ // No template marker found, skip
92
+ }
93
+ }
94
+
95
+ console.log(JSON.stringify(mcpRepos));
96
+ }
97
+
98
+ discoverRepos().catch(console.error);
99
+ EOF
100
+
101
+ npm install @octokit/rest
102
+ repos=$(node discover-repos.js)
103
+ echo "repos=$repos" >> $GITHUB_OUTPUT
104
+
105
+ trigger-sync :
106
+ needs : discover-repos
107
+ if : needs.discover-repos.outputs.repos != '[]'
108
+ runs-on : ubuntu-latest
109
+ strategy :
110
+ matrix :
111
+ repo : ${{ fromJson(needs.discover-repos.outputs.repos) }}
112
+ max-parallel : 3
113
+ steps :
114
+ - name : Trigger template sync in ${{ matrix.repo }}
115
+ env :
116
+ GITHUB_TOKEN : ${{ secrets.TEMPLATE_SYNC_TOKEN || secrets.GITHUB_TOKEN }}
117
+ run : |
118
+ curl -X POST \
119
+ -H "Authorization: token $GITHUB_TOKEN" \
120
+ -H "Accept: application/vnd.github.v3+json" \
121
+ "https://api.github.com/repos/Mearman/${{ matrix.repo }}/dispatches" \
122
+ -d '{
123
+ "event_type": "template-sync",
124
+ "client_payload": {
125
+ "template_repo": "mcp-template",
126
+ "template_version": "${{ github.sha }}",
127
+ "dry_run": "${{ github.event.inputs.dry_run || false }}"
128
+ }
129
+ }'
130
+
131
+ - name : Create sync tracking issue (if not dry run)
132
+ if : github.event.inputs.dry_run != 'true'
133
+ env :
134
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
135
+ run : |
136
+ curl -X POST \
137
+ -H "Authorization: token $GITHUB_TOKEN" \
138
+ -H "Accept: application/vnd.github.v3+json" \
139
+ "https://api.github.com/repos/Mearman/${{ matrix.repo }}/issues" \
140
+ -d '{
141
+ "title": "Template sync triggered",
142
+ "body": "Template sync has been triggered from mcp-template commit ${{ github.sha }}.\n\nCheck the Actions tab for sync progress.",
143
+ "labels": ["template-sync", "automated"]
144
+ }'
0 commit comments