|
| 1 | +name: Pull Shark Automation |
| 2 | + |
| 3 | +# Trigger workflow manually or on schedule |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + pr_count: |
| 8 | + description: 'Number of PRs to create' |
| 9 | + required: true |
| 10 | + default: '5' |
| 11 | + type: string |
| 12 | + schedule: |
| 13 | + # Run once a day at 10 AM UTC |
| 14 | + - cron: '0 10 * * *' |
| 15 | + |
| 16 | +jobs: |
| 17 | + create-prs: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + pull-requests: write |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Configure Git |
| 30 | + run: | |
| 31 | + git config user.name "github-actions[bot]" |
| 32 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 33 | + |
| 34 | + - name: Create and merge PRs |
| 35 | + env: |
| 36 | + GH_TOKEN: ${{ github.token }} |
| 37 | + PR_COUNT: ${{ github.event.inputs.pr_count || '5' }} |
| 38 | + run: | |
| 39 | + echo "Creating $PR_COUNT pull requests..." |
| 40 | + |
| 41 | + for i in $(seq 1 $PR_COUNT); do |
| 42 | + TIMESTAMP=$(date +%s) |
| 43 | + BRANCH="pull-shark-$TIMESTAMP-$i" |
| 44 | + FILE="pull-shark-$TIMESTAMP-$i.md" |
| 45 | + |
| 46 | + echo "Creating branch: $BRANCH" |
| 47 | + git checkout -b $BRANCH |
| 48 | + |
| 49 | + echo "Creating file: $FILE" |
| 50 | + cat > $FILE << EOF |
| 51 | +# Pull Shark PR #$i - $TIMESTAMP |
| 52 | + |
| 53 | +This is an automated pull request created by the Pull Shark workflow. |
| 54 | + |
| 55 | +- Created: $(date) |
| 56 | +- Branch: $BRANCH |
| 57 | +- PR Number: $i of $PR_COUNT |
| 58 | + |
| 59 | +## Purpose |
| 60 | +Working towards earning the Pull Shark achievement badge! |
| 61 | +EOF |
| 62 | + |
| 63 | + git add $FILE |
| 64 | + git commit -m "Add pull shark file $i: $FILE" |
| 65 | + git push origin $BRANCH |
| 66 | + |
| 67 | + echo "Creating PR for branch: $BRANCH" |
| 68 | + PR_URL=$(gh pr create \ |
| 69 | + --title "Pull Shark PR #$i - Automated" \ |
| 70 | + --body "Automated PR #$i for Pull Shark badge progress. Created at $TIMESTAMP" \ |
| 71 | + --base main \ |
| 72 | + --head $BRANCH) |
| 73 | + |
| 74 | + echo "PR created: $PR_URL" |
| 75 | + |
| 76 | + # Extract PR number from URL |
| 77 | + PR_NUMBER=$(echo $PR_URL | grep -oP '\d+$') |
| 78 | + |
| 79 | + # Wait a moment for PR to be fully created |
| 80 | + sleep 2 |
| 81 | + |
| 82 | + echo "Merging PR #$PR_NUMBER" |
| 83 | + gh pr merge $PR_NUMBER --merge --auto |
| 84 | + |
| 85 | + # Switch back to main and pull latest changes |
| 86 | + git checkout main |
| 87 | + git pull origin main |
| 88 | + |
| 89 | + echo "Completed PR $i of $PR_COUNT" |
| 90 | + echo "---" |
| 91 | + |
| 92 | + # Small delay between PRs |
| 93 | + sleep 3 |
| 94 | + done |
| 95 | + |
| 96 | + echo "Successfully created and merged $PR_COUNT pull requests!" |
| 97 | + |
| 98 | + - name: Summary |
| 99 | + run: | |
| 100 | + echo "## Pull Shark Automation Summary" >> $GITHUB_STEP_SUMMARY |
| 101 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 102 | + echo "✅ Created and merged ${{ github.event.inputs.pr_count || '5' }} pull requests" >> $GITHUB_STEP_SUMMARY |
| 103 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "View all PRs: https://github.com/${{ github.repository }}/pulls?q=is%3Apr" >> $GITHUB_STEP_SUMMARY |
0 commit comments