diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml new file mode 100644 index 0000000..37fa5f9 --- /dev/null +++ b/.github/workflows/auto-merge.yml @@ -0,0 +1,47 @@ +name: Auto Merge + +on: + workflow_run: + workflows: ["CI"] + types: [completed] + +jobs: + auto-merge: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.event == 'pull_request' + permissions: + contents: write + pull-requests: write + steps: + - name: Find and merge master → main PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}" + echo "Workflow ran on branch: $HEAD_BRANCH" + + if [ "$HEAD_BRANCH" != "master" ]; then + echo "Not a master branch PR, skipping" + exit 0 + fi + + PR_NUMBER=$(gh pr list \ + --repo "$GITHUB_REPOSITORY" \ + --base main \ + --head master \ + --state open \ + --json number \ + --jq '.[0].number') + + if [ -z "$PR_NUMBER" ]; then + echo "No open PR from master to main found, skipping" + exit 0 + fi + + echo "Merging PR #$PR_NUMBER" + gh pr merge "$PR_NUMBER" \ + --repo "$GITHUB_REPOSITORY" \ + --merge \ + --delete-branch=false diff --git a/.github/workflows/auto-pr.yml b/.github/workflows/auto-pr.yml new file mode 100644 index 0000000..79d9991 --- /dev/null +++ b/.github/workflows/auto-pr.yml @@ -0,0 +1,34 @@ +name: Auto PR (master → main) + +on: + push: + branches: [master] + +jobs: + create-pr: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Create or update PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + EXISTING_PR=$(gh pr list --base main --head master --state open --json number --jq '.[0].number') + + if [ -n "$EXISTING_PR" ]; then + echo "PR #$EXISTING_PR already exists — new commits will appear automatically" + else + echo "Creating new PR: master → main" + gh pr create \ + --base main \ + --head master \ + --title "Sync: master → main" \ + --body "Automated PR to sync master branch changes to main. + + This PR was created automatically and will be merged once CI checks pass." + fi diff --git a/.github/workflows/sync-branches.yml b/.github/workflows/sync-branches.yml deleted file mode 100644 index 34f4493..0000000 --- a/.github/workflows/sync-branches.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: Sync main and master branches - -on: - push: - branches: - - main - - master - -jobs: - sync: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Sync branches - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - - if [ "${{ github.ref }}" = "refs/heads/main" ]; then - echo "main was updated, syncing master..." - git checkout master - git reset --hard origin/main - git push origin master --force - elif [ "${{ github.ref }}" = "refs/heads/master" ]; then - echo "master was updated, syncing main..." - git checkout main - git reset --hard origin/master - git push origin main --force - fi