-
Notifications
You must be signed in to change notification settings - Fork 5
318 lines (276 loc) · 11.4 KB
/
Copy pathpython-publish.yml
File metadata and controls
318 lines (276 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
name: Pull Shark Automation
off:
workflow_dispatch:
inputs:
mode:
description: "Execution mode"
required: true
default: "sequential"
type: choice
options:
- sequential
- parallel
pr_count:
description: "Number of PRs to create"
required: true
default: "20"
type: string
concurrent_workers:
description: "Parallel workers (parallel mode only)"
required: false
default: "10"
type: string
delay_seconds:
description: "Delay between PRs in seconds (sequential mode only)"
required: false
default: "15"
type: string
dry_run:
description: "Enable dry run (no actual commits)"
required: false
default: false
type: boolean
auto_merge:
description: "Auto-merge created PRs"
required: false
default: true
type: boolean
schedule:
# Optional: run on a schedule (uncomment to enable)
# - cron: "0 9 * * 1" # Every Monday at 9 AM UTC
- cron: "0 0 31 2 *" # Never (placeholder — remove to use schedule above)
permissions:
contents: write
pull-requests: write
jobs:
# ──────────────────────────────────────────────
# JOB 1: Setup & validate environment
# ──────────────────────────────────────────────
setup:
name: 🔧 Setup Environment
runs-on: ubuntu-latest
outputs:
mode: ${{ steps.params.outputs.mode }}
pr_count: ${{ steps.params.outputs.pr_count }}
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🐍 Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: 📦 Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: 🔐 Authenticate GitHub CLI
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
gh auth status
- name: ✅ Validate parameters
id: params
run: |
MODE="${{ github.event.inputs.mode || 'sequential' }}"
COUNT="${{ github.event.inputs.pr_count || '20' }}"
echo "mode=$MODE" >> $GITHUB_OUTPUT
echo "pr_count=$COUNT" >> $GITHUB_OUTPUT
echo "▶ Mode: $MODE"
echo "▶ PR Count: $COUNT"
echo "▶ Dry Run: ${{ github.event.inputs.dry_run }}"
- name: ⚙️ Write config.json
run: |
cat > config.json <<EOF
{
"repo_path": ".",
"base_branch": "main",
"readme_file": "README.md",
"pr_count": ${{ github.event.inputs.pr_count || 20 }},
"delay_seconds": ${{ github.event.inputs.delay_seconds || 15 }},
"auto_merge": ${{ github.event.inputs.auto_merge || true }},
"dry_run": ${{ github.event.inputs.dry_run || false }},
"max_retries": 3,
"use_free_proxies": false,
"max_concurrent": ${{ github.event.inputs.concurrent_workers || 10 }},
"discord_webhook": "${{ secrets.DISCORD_WEBHOOK }}",
"slack_webhook": "${{ secrets.SLACK_WEBHOOK }}"
}
EOF
echo "✅ config.json written"
cat config.json
- name: 🔑 Write github_tokens.json
run: |
cat > github_tokens.json <<EOF
{
"tokens": [
{
"name": "Primary",
"token": "${{ secrets.GH_TOKEN_PRIMARY || secrets.GITHUB_TOKEN }}"
}
]
}
EOF
echo "✅ github_tokens.json written"
# ──────────────────────────────────────────────
# JOB 2: Sequential Mode
# ──────────────────────────────────────────────
run-sequential:
name: 📝 Sequential Automation
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.mode == 'sequential' }}
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN_PRIMARY || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: 🐍 Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: 📦 Install dependencies
run: |
pip install -r requirements.txt
- name: 🔐 Authenticate GitHub CLI
run: echo "${{ secrets.GH_TOKEN_PRIMARY || secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: ⚙️ Restore config files
run: |
cat > config.json <<EOF
{
"repo_path": ".",
"base_branch": "main",
"readme_file": "README.md",
"pr_count": ${{ github.event.inputs.pr_count || 20 }},
"delay_seconds": ${{ github.event.inputs.delay_seconds || 15 }},
"auto_merge": ${{ github.event.inputs.auto_merge || true }},
"dry_run": ${{ github.event.inputs.dry_run || false }},
"max_retries": 3,
"use_free_proxies": false,
"max_concurrent": 10,
"discord_webhook": "${{ secrets.DISCORD_WEBHOOK }}",
"slack_webhook": "${{ secrets.SLACK_WEBHOOK }}"
}
EOF
cat > github_tokens.json <<EOF
{
"tokens": [
{ "name": "Primary", "token": "${{ secrets.GH_TOKEN_PRIMARY || secrets.GITHUB_TOKEN }}" }
]
}
EOF
- name: 🚀 Run sequential automation
run: |
git config --global user.email "automation@github-actions.com"
git config --global user.name "Pull Shark Bot"
ARGS="--count ${{ github.event.inputs.pr_count || 20 }}"
ARGS="$ARGS --delay ${{ github.event.inputs.delay_seconds || 15 }}"
if [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then
ARGS="$ARGS --dry-run"
fi
if [[ "${{ github.event.inputs.auto_merge }}" == "false" ]]; then
ARGS="$ARGS --no-merge"
fi
echo "▶ Running: python main.py $ARGS"
python main.py $ARGS
- name: 📊 Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: sequential-logs
path: "*.log"
retention-days: 7
# ──────────────────────────────────────────────
# JOB 3: Parallel Mode
# ──────────────────────────────────────────────
run-parallel:
name: ⚡ Parallel Automation
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.mode == 'parallel' }}
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN_PRIMARY || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: 🐍 Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
cache: "pip"
- name: 📦 Install dependencies
run: pip install -r requirements.txt
- name: 🔐 Authenticate GitHub CLI
run: echo "${{ secrets.GH_TOKEN_PRIMARY || secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: ⚙️ Restore config files
run: |
cat > config.json <<EOF
{
"repo_path": ".",
"base_branch": "main",
"readme_file": "README.md",
"pr_count": ${{ github.event.inputs.pr_count || 20 }},
"delay_seconds": 5,
"auto_merge": ${{ github.event.inputs.auto_merge || true }},
"dry_run": ${{ github.event.inputs.dry_run || false }},
"max_retries": 3,
"use_free_proxies": false,
"max_concurrent": ${{ github.event.inputs.concurrent_workers || 10 }},
"discord_webhook": "${{ secrets.DISCORD_WEBHOOK }}",
"slack_webhook": "${{ secrets.SLACK_WEBHOOK }}"
}
EOF
# Build token list — add GH_TOKEN_2 / GH_TOKEN_3 as repo secrets for rotation
TOKENS="[ { \"name\": \"Primary\", \"token\": \"${{ secrets.GH_TOKEN_PRIMARY || secrets.GITHUB_TOKEN }}\" }"
if [[ -n "${{ secrets.GH_TOKEN_2 }}" ]]; then
TOKENS="$TOKENS, { \"name\": \"Secondary\", \"token\": \"${{ secrets.GH_TOKEN_2 }}\" }"
fi
if [[ -n "${{ secrets.GH_TOKEN_3 }}" ]]; then
TOKENS="$TOKENS, { \"name\": \"Tertiary\", \"token\": \"${{ secrets.GH_TOKEN_3 }}\" }"
fi
TOKENS="$TOKENS ]"
echo "{ \"tokens\": $TOKENS }" > github_tokens.json
echo "✅ Token file written"
- name: ⚡ Run parallel automation
run: |
git config --global user.email "automation@github-actions.com"
git config --global user.name "Pull Shark Bot"
ARGS="--count ${{ github.event.inputs.pr_count || 20 }}"
ARGS="$ARGS --concurrent ${{ github.event.inputs.concurrent_workers || 10 }}"
if [[ "${{ github.event.inputs.dry_run }}" == "true" ]]; then
ARGS="$ARGS --dry-run"
fi
echo "▶ Running: python parallel_automation.py $ARGS"
python parallel_automation.py $ARGS
- name: 📊 Upload logs
if: always()
uses: actions/upload-artifact@v4
with:
name: parallel-logs
path: "*.log"
retention-days: 7
# ──────────────────────────────────────────────
# JOB 4: Post-run summary
# ──────────────────────────────────────────────
summary:
name: 📋 Job Summary
runs-on: ubuntu-latest
needs: [run-sequential, run-parallel]
if: always()
steps:
- name: 🗒️ Write job summary
run: |
echo "## 🦈 Pull Shark Automation — Run Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Parameter | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Mode | \`${{ github.event.inputs.mode || 'sequential' }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| PR Count | \`${{ github.event.inputs.pr_count || '20' }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Auto Merge | \`${{ github.event.inputs.auto_merge || 'true' }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Dry Run | \`${{ github.event.inputs.dry_run || 'false' }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Triggered by | \`${{ github.actor }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| Workflow Run | [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "> Logs are available as artifacts in this workflow run." >> $GITHUB_STEP_SUMMARY