Auto PR & Merge mri_team_count → master #3667
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto PR & Merge mri_team_count → master | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 * * * *' # every hour | |
| jobs: | |
| auto-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up GitHub CLI repository | |
| run: | | |
| curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg | |
| echo "deb [arch=amd64 signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null | |
| sudo apt-get update | |
| sudo apt-get install gh | |
| - name: Ensure mri_team_count branch exists | |
| run: | | |
| if ! git ls-remote --exit-code --heads origin mri_team_count; then | |
| echo "Branch mri_team_count does not exist. Creating branch." | |
| git checkout -b mri_team_count | |
| git push origin mri_team_count | |
| else | |
| echo "Branch mri_team_count exists." | |
| fi | |
| - name: Fetch all branches | |
| run: git fetch --all | |
| - name: Check if PR exists and create if missing | |
| id: create_pr | |
| run: | | |
| echo "Checking for existing PR..." | |
| EXISTING_PR=$(gh pr list --base master --head mri_team_count --state open --limit 1) | |
| if [ -z "$EXISTING_PR" ]; then | |
| echo "No existing PR. Checking for commit differences..." | |
| git fetch origin master | |
| COMMITS=$(git rev-list origin/master..origin/mri_team_count) | |
| if [ -z "$COMMITS" ]; then | |
| echo "No commits between master and mri_team_count. Skipping PR creation." | |
| exit 0 | |
| fi | |
| echo "Creating new PR..." | |
| gh pr create \ | |
| --base master \ | |
| --head mri_team_count \ | |
| --title "Auto PR: Update MRI Team Count" \ | |
| --body "This PR was automatically created to update the mri_team_count view." > pr_output.txt | |
| PR_URL=$(grep -Eo 'https://github\.com/[^ ]+' pr_output.txt) | |
| echo "PR_URL=$PR_URL" >> $GITHUB_ENV | |
| else | |
| echo "PR already exists." | |
| fi | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |