From 0482082cfa7833e178eb585143772b7a3815c6a9 Mon Sep 17 00:00:00 2001 From: michsi24 Date: Tue, 9 Dec 2025 09:24:19 +0200 Subject: [PATCH 01/25] ci(auto-merge): add action to automatically merge PRs with 'auto-merge' label --- .github/workflows/test-auto-merge.yaml | 17 +++++++++ actions/auto-merge/action.yaml | 52 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/test-auto-merge.yaml create mode 100644 actions/auto-merge/action.yaml diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml new file mode 100644 index 0000000..bb8414a --- /dev/null +++ b/.github/workflows/test-auto-merge.yaml @@ -0,0 +1,17 @@ +name: Test update-charts-pr action + +on: + workflow_call: + +jobs: + test-action: + runs-on: ubuntu-latest + steps: + - name: Checkout this repo + uses: actions/checkout@v5 + + - name: Run auto-merge action + uses: ./actions/auto-merge + with: + pr_number: 1 + github_token: ${{ secrets.GH_PAT }} diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml new file mode 100644 index 0000000..8b982da --- /dev/null +++ b/actions/auto-merge/action.yaml @@ -0,0 +1,52 @@ +name: "Auto-merge PR by label" +description: "Checks if a PR has the 'auto-merge' label and merges it using gh if present" + +inputs: + pr_number: + description: "Pull Request number to check and merge" + required: true + github_token: + description: "GitHub token with permissions to merge PRs (repo scope)" + required: true + +runs: + using: "composite" + steps: + - name: Authenticate gh + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.github_token }} + run: | + set -euo pipefail + echo "$GITHUB_TOKEN" | gh auth login --with-token + + - name: Check for 'auto-merge' label + id: check_label + shell: bash + run: | + set -euo pipefail + LABELS=$(gh pr view "${{ inputs.pr_number }}" --json labels -q '.labels[].name') + echo "Labels on PR #${{ inputs.pr_number }}:" + echo "$LABELS" | tr ' ' '\n' || true + if echo "$LABELS" | grep -xq "auto-merge"; then + echo "has_label=true" >> "$GITHUB_OUTPUT" + else + echo "has_label=false" >> "$GITHUB_OUTPUT" + fi + + - name: Merge PR if labeled + if: steps.check_label.outputs.has_label == 'true' + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.github_token }} + run: | + set -euo pipefail + echo "Merging PR #${{ inputs.pr_number }} (label 'auto-merge' found)" + # --merge creates a merge commit; adjust flags if you prefer --squash or --rebase + gh pr merge "${{ inputs.pr_number }}" --merge --delete-branch --admin + + - name: Skip merge (label missing) + if: steps.check_label.outputs.has_label != 'true' + shell: bash + run: | + echo "Skipping merge: PR #${{ inputs.pr_number }} does not have label 'auto-merge'" From 92b0d1999d0c5c7decdd90d25886bde3acc0bdcd Mon Sep 17 00:00:00 2001 From: michsi24 Date: Tue, 9 Dec 2025 12:04:47 +0200 Subject: [PATCH 02/25] ci: update action to include repository input and enhance authentication process --- .github/workflows/test-auto-merge.yaml | 5 +-- actions/auto-merge/action.yaml | 49 ++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index bb8414a..cc37103 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -1,4 +1,4 @@ -name: Test update-charts-pr action +name: Test auto-merge action on: workflow_call: @@ -13,5 +13,6 @@ jobs: - name: Run auto-merge action uses: ./actions/auto-merge with: - pr_number: 1 + pr_number: 46 github_token: ${{ secrets.GH_PAT }} + repository: MapColonies/test-site diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index 8b982da..db3a0dc 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -8,25 +8,60 @@ inputs: github_token: description: "GitHub token with permissions to merge PRs (repo scope)" required: true + repository: + description: "Target repository (owner/repo). Defaults to the current repository." + required: true runs: using: "composite" steps: - - name: Authenticate gh + - name: Install gh (for act) + shell: bash + run: | + if command -v gh >/dev/null; then + echo "gh already installed"; exit 0; + fi + sudo apt-get update -y + sudo apt-get install -y git curl + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ + | sudo tee /usr/share/keyrings/githubcli-archive-keyring.gpg >/dev/null + echo "deb [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 -y + sudo apt-get install -y gh + + - name: Authenticate gh with github_token shell: bash env: + # Provide token to gh both ways for compatibility GITHUB_TOKEN: ${{ inputs.github_token }} + GH_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail - echo "$GITHUB_TOKEN" | gh auth login --with-token + # If GH_TOKEN/GITHUB_TOKEN is set, gh uses it automatically; avoid forcing login. + if gh auth status >/dev/null 2>&1; then + echo "gh is already authenticated" + else + # Probe API to confirm token works; this avoids storing credentials when env vars are set. + if gh api user >/dev/null 2>&1; then + echo "gh authenticated via environment token" + else + echo "Environment token appears invalid; attempting login via --with-token" + echo -n "$GITHUB_TOKEN" | gh auth login --with-token + gh auth status + fi + fi - name: Check for 'auto-merge' label id: check_label shell: bash + env: + GITHUB_TOKEN: ${{ inputs.github_token }} + GH_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail - LABELS=$(gh pr view "${{ inputs.pr_number }}" --json labels -q '.labels[].name') - echo "Labels on PR #${{ inputs.pr_number }}:" + LABELS=$(gh pr view "${{ inputs.pr_number }}" --repo "${{ inputs.repository }}" --json labels -q '.labels[].name') + echo "Labels on PR #${{ inputs.pr_number }} in repo '${{ inputs.repository }}':" echo "$LABELS" | tr ' ' '\n' || true if echo "$LABELS" | grep -xq "auto-merge"; then echo "has_label=true" >> "$GITHUB_OUTPUT" @@ -41,12 +76,12 @@ runs: GITHUB_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail - echo "Merging PR #${{ inputs.pr_number }} (label 'auto-merge' found)" + echo "Merging PR #${{ inputs.pr_number }} in repo '${{ inputs.repository }}' (label 'auto-merge' found)" # --merge creates a merge commit; adjust flags if you prefer --squash or --rebase - gh pr merge "${{ inputs.pr_number }}" --merge --delete-branch --admin + gh pr merge "${{ inputs.pr_number }}" --repo "${{ inputs.repository }}" --merge --delete-branch --admin - name: Skip merge (label missing) if: steps.check_label.outputs.has_label != 'true' shell: bash run: | - echo "Skipping merge: PR #${{ inputs.pr_number }} does not have label 'auto-merge'" + echo "Skipping merge: PR #${{ inputs.pr_number }} in repo '${{ inputs.repository }}' does not have label 'auto-merge'" From 361a38b9e8ada704f24f4e5c2229fe8b2b6a7873 Mon Sep 17 00:00:00 2001 From: michsi24 Date: Tue, 9 Dec 2025 13:56:29 +0200 Subject: [PATCH 03/25] ci(auto-merge): update workflow to use dynamic PR number and improve label check logic --- .github/workflows/test-auto-merge.yaml | 4 +- actions/auto-merge/action.yaml | 86 +++++++++++++------------- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index cc37103..ea2375c 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -1,7 +1,7 @@ name: Test auto-merge action on: - workflow_call: + pull_request: jobs: test-action: @@ -13,6 +13,6 @@ jobs: - name: Run auto-merge action uses: ./actions/auto-merge with: - pr_number: 46 + pr_number: ${{ github.event.pull_request.number }} github_token: ${{ secrets.GH_PAT }} repository: MapColonies/test-site diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index db3a0dc..0b76639 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -15,55 +15,52 @@ inputs: runs: using: "composite" steps: - - name: Install gh (for act) - shell: bash - run: | - if command -v gh >/dev/null; then - echo "gh already installed"; exit 0; - fi - sudo apt-get update -y - sudo apt-get install -y git curl - curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ - | sudo tee /usr/share/keyrings/githubcli-archive-keyring.gpg >/dev/null - echo "deb [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 -y - sudo apt-get install -y gh + # - name: Install gh (for act) + # shell: bash + # run: | + # if command -v gh >/dev/null; then + # echo "gh already installed"; exit 0; + # fi + # sudo apt-get update -y + # sudo apt-get install -y git curl + # curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ + # | sudo tee /usr/share/keyrings/githubcli-archive-keyring.gpg >/dev/null + # echo "deb [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 -y + # sudo apt-get install -y gh - - name: Authenticate gh with github_token - shell: bash - env: - # Provide token to gh both ways for compatibility - GITHUB_TOKEN: ${{ inputs.github_token }} - GH_TOKEN: ${{ inputs.github_token }} - run: | - set -euo pipefail - # If GH_TOKEN/GITHUB_TOKEN is set, gh uses it automatically; avoid forcing login. - if gh auth status >/dev/null 2>&1; then - echo "gh is already authenticated" - else - # Probe API to confirm token works; this avoids storing credentials when env vars are set. - if gh api user >/dev/null 2>&1; then - echo "gh authenticated via environment token" - else - echo "Environment token appears invalid; attempting login via --with-token" - echo -n "$GITHUB_TOKEN" | gh auth login --with-token - gh auth status - fi - fi + # - name: Authenticate gh with github_token + # shell: bash + # env: + # GITHUB_TOKEN: ${{ inputs.github_token }} + # GH_TOKEN: ${{ inputs.github_token }} + # run: | + # set -euo pipefail + # # If GH_TOKEN/GITHUB_TOKEN is set, gh uses it automatically; avoid forcing login. + # if gh auth status >/dev/null 2>&1; then + # echo "gh is already authenticated" + # else + # # Probe API to confirm token works; this avoids storing credentials when env vars are set. + # if gh api user >/dev/null 2>&1; then + # echo "gh authenticated via environment token" + # else + # echo "Environment token appears invalid; attempting login via --with-token" + # echo -n "$GITHUB_TOKEN" | gh auth login --with-token + # gh auth status + # fi + # fi - name: Check for 'auto-merge' label id: check_label shell: bash env: - GITHUB_TOKEN: ${{ inputs.github_token }} GH_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail - LABELS=$(gh pr view "${{ inputs.pr_number }}" --repo "${{ inputs.repository }}" --json labels -q '.labels[].name') - echo "Labels on PR #${{ inputs.pr_number }} in repo '${{ inputs.repository }}':" - echo "$LABELS" | tr ' ' '\n' || true - if echo "$LABELS" | grep -xq "auto-merge"; then + labels=$(gh pr view "${{ inputs.pr_number }}" --repo "${{ inputs.repository }}" --json labels -q '.labels[].name') + + if grep -qx "auto-merge" <<< "$labels"; then echo "has_label=true" >> "$GITHUB_OUTPUT" else echo "has_label=false" >> "$GITHUB_OUTPUT" @@ -73,12 +70,13 @@ runs: if: steps.check_label.outputs.has_label == 'true' shell: bash env: - GITHUB_TOKEN: ${{ inputs.github_token }} + GH_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail - echo "Merging PR #${{ inputs.pr_number }} in repo '${{ inputs.repository }}' (label 'auto-merge' found)" - # --merge creates a merge commit; adjust flags if you prefer --squash or --rebase - gh pr merge "${{ inputs.pr_number }}" --repo "${{ inputs.repository }}" --merge --delete-branch --admin + echo "Merging PR #${{ inputs.pr_number }} in '${{ inputs.repository }}' (label 'auto-merge' found)" + gh pr merge "${{ inputs.pr_number }}" \ + --repo "${{ inputs.repository }}" \ + --squash \ - name: Skip merge (label missing) if: steps.check_label.outputs.has_label != 'true' From 51bb00dd29ac2e10bb99e38a31b6c50ff812d549 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Wed, 10 Dec 2025 13:23:51 +0200 Subject: [PATCH 04/25] ci(auto-merge): refine installation and authentication steps for gh --- actions/auto-merge/action.yaml | 68 +++++++++++++++++----------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index 0b76639..d767e1d 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -15,41 +15,41 @@ inputs: runs: using: "composite" steps: - # - name: Install gh (for act) - # shell: bash - # run: | - # if command -v gh >/dev/null; then - # echo "gh already installed"; exit 0; - # fi - # sudo apt-get update -y - # sudo apt-get install -y git curl - # curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ - # | sudo tee /usr/share/keyrings/githubcli-archive-keyring.gpg >/dev/null - # echo "deb [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 -y - # sudo apt-get install -y gh + - name: Install gh (for act) + shell: bash + run: | + if command -v gh >/dev/null; then + echo "gh already installed"; exit 0; + fi + sudo apt-get update -y + sudo apt-get install -y git curl + curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \ + | sudo tee /usr/share/keyrings/githubcli-archive-keyring.gpg >/dev/null + echo "deb [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 -y + sudo apt-get install -y gh - # - name: Authenticate gh with github_token - # shell: bash - # env: - # GITHUB_TOKEN: ${{ inputs.github_token }} - # GH_TOKEN: ${{ inputs.github_token }} - # run: | - # set -euo pipefail - # # If GH_TOKEN/GITHUB_TOKEN is set, gh uses it automatically; avoid forcing login. - # if gh auth status >/dev/null 2>&1; then - # echo "gh is already authenticated" - # else - # # Probe API to confirm token works; this avoids storing credentials when env vars are set. - # if gh api user >/dev/null 2>&1; then - # echo "gh authenticated via environment token" - # else - # echo "Environment token appears invalid; attempting login via --with-token" - # echo -n "$GITHUB_TOKEN" | gh auth login --with-token - # gh auth status - # fi - # fi + - name: Authenticate gh with github_token + shell: bash + env: + GITHUB_TOKEN: ${{ inputs.github_token }} + GH_TOKEN: ${{ inputs.github_token }} + run: | + set -euo pipefail + # If GH_TOKEN/GITHUB_TOKEN is set, gh uses it automatically; avoid forcing login. + if gh auth status >/dev/null 2>&1; then + echo "gh is already authenticated" + else + # Probe API to confirm token works; this avoids storing credentials when env vars are set. + if gh api user >/dev/null 2>&1; then + echo "gh authenticated via environment token" + else + echo "Environment token appears invalid; attempting login via --with-token" + echo -n "$GITHUB_TOKEN" | gh auth login --with-token + gh auth status + fi + fi - name: Check for 'auto-merge' label id: check_label From 6b301bbe1dde1d5a2e40095a1d3007b0639912d6 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Wed, 10 Dec 2025 16:04:34 +0200 Subject: [PATCH 05/25] ci(auto-merge): wait for required checks to pass before merging PRs --- .github/workflows/test-auto-merge.yaml | 2 +- actions/auto-merge/action.yaml | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index ea2375c..7845202 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -13,6 +13,6 @@ jobs: - name: Run auto-merge action uses: ./actions/auto-merge with: - pr_number: ${{ github.event.pull_request.number }} + pr_number: github_token: ${{ secrets.GH_PAT }} repository: MapColonies/test-site diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index d767e1d..e996bca 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -73,6 +73,13 @@ runs: GH_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail + echo "Waiting for required checks to pass on PR #${{ inputs.pr_number }}" + # Wait for all required checks/workflows to complete successfully + gh pr checks "${{ inputs.pr_number }}" \ + --repo "${{ inputs.repository }}" \ + --watch \ + --required + echo "Merging PR #${{ inputs.pr_number }} in '${{ inputs.repository }}' (label 'auto-merge' found)" gh pr merge "${{ inputs.pr_number }}" \ --repo "${{ inputs.repository }}" \ From 4b1c8f5a393d3f21681cd15c966b9d97e0e8e5b4 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 11 Dec 2025 11:14:01 +0200 Subject: [PATCH 06/25] feat(auto-merge): add auto-merge action for labeled PRs with passing checks --- .github/workflows/test-auto-merge.yaml | 2 +- actions/auto-merge/action.yaml | 27 +++++++++++++++++++------- release-please-config.json | 5 +++++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 7845202..ea2375c 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -13,6 +13,6 @@ jobs: - name: Run auto-merge action uses: ./actions/auto-merge with: - pr_number: + pr_number: ${{ github.event.pull_request.number }} github_token: ${{ secrets.GH_PAT }} repository: MapColonies/test-site diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index e996bca..ad30904 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -66,20 +66,33 @@ runs: echo "has_label=false" >> "$GITHUB_OUTPUT" fi - - name: Merge PR if labeled + - name: Wait for PR checks + id: wait_checks if: steps.check_label.outputs.has_label == 'true' shell: bash env: GH_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail - echo "Waiting for required checks to pass on PR #${{ inputs.pr_number }}" - # Wait for all required checks/workflows to complete successfully - gh pr checks "${{ inputs.pr_number }}" \ - --repo "${{ inputs.repository }}" \ - --watch \ - --required + echo "Waiting for all checks on PR #${{ inputs.pr_number }} to complete" + if gh pr checks "${{ inputs.pr_number }}" \ + --repo "${{ inputs.repository }}" \ + --watch; then + echo "All checks completed." + echo "passed=true" >> "$GITHUB_OUTPUT" + else + echo "Checks did not complete successfully." + echo "passed=false" >> "$GITHUB_OUTPUT" + exit 1 + fi + - name: Merge PR if labeled + if: steps.check_label.outputs.has_label == 'true' && steps.wait_checks.outputs.passed == 'true' + shell: bash + env: + GH_TOKEN: ${{ inputs.github_token }} + run: | + set -euo pipefail echo "Merging PR #${{ inputs.pr_number }} in '${{ inputs.repository }}' (label 'auto-merge' found)" gh pr merge "${{ inputs.pr_number }}" \ --repo "${{ inputs.repository }}" \ diff --git a/release-please-config.json b/release-please-config.json index f4e1f39..2a30012 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -23,6 +23,11 @@ "release-type": "simple", "package-name": "validate-domain", "extra-files": ["README.md"] + }, + "actions/auto-merge": { + "release-type": "simple", + "package-name": "auto-merge", + "extra-files": ["README.md"] } } } From 7ae4a685e2b102616ee48ae7d510dd4dee85412b Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 11 Dec 2025 11:21:22 +0200 Subject: [PATCH 07/25] ci(auto-merge): update test workflow to use dynamic repository input --- .github/workflows/test-auto-merge.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index ea2375c..23ba1aa 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -2,6 +2,8 @@ name: Test auto-merge action on: pull_request: + paths: + - "actions/auto-merge/**" jobs: test-action: @@ -15,4 +17,4 @@ jobs: with: pr_number: ${{ github.event.pull_request.number }} github_token: ${{ secrets.GH_PAT }} - repository: MapColonies/test-site + repository: ${{ github.repository }} From d6da8a4d19c50b272d0f7d7b8c949c4f6d88ba69 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 11 Dec 2025 11:28:04 +0200 Subject: [PATCH 08/25] docs(auto-merge): add README for auto-merge --- actions/auto-merge/README.md | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 actions/auto-merge/README.md diff --git a/actions/auto-merge/README.md b/actions/auto-merge/README.md new file mode 100644 index 0000000..b840717 --- /dev/null +++ b/actions/auto-merge/README.md @@ -0,0 +1,44 @@ +# Auto-merge PR by label + +Checks if a pull request has the `auto-merge` label, waits for all checks to pass, and then merges the PR. + +--- + +## ✨ What It Does + +- Verifies the PR has the `auto-merge` label +- Waits for all PR checks to complete and pass +- Merges the PR with a squash strategy +- Skips merge if the label is missing or checks fail + +--- + +## 🛠 Inputs + +| Name | Description | Required | Default | +|------|-------------|----------|---------| +| `pr_number` | Pull Request number to check and merge | ✅ Yes | | +| `github_token` | GitHub token with permissions to merge PRs | ✅ Yes | | +| `repository` | Target repository in `owner/repo` format (typically `${{ github.repository }}`) | ✅ Yes | | + +--- + +## 🚀 Usage + + + +```yaml +permissions: + contents: write + pull-requests: write + +steps: + - name: Auto-merge PR by label + uses: MapColonies/shared-workflows/actions/auto-merge@auto-merge-v0.1.0 + with: + pr_number: ${{ github.event.pull_request.number }} + github_token: ${{ secrets.GH_PAT }} + repository: ${{ github.repository }} +``` + + From d35edd181c4c3571d7833db3ac5a7b59e513b261 Mon Sep 17 00:00:00 2001 From: michsi24 Date: Mon, 15 Dec 2025 13:53:48 +0200 Subject: [PATCH 09/25] ci: refine commit message format and update PR labels handling --- actions/auto-merge/README.md | 1 + actions/auto-merge/action.yaml | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/actions/auto-merge/README.md b/actions/auto-merge/README.md index b840717..3df7cd6 100644 --- a/actions/auto-merge/README.md +++ b/actions/auto-merge/README.md @@ -20,6 +20,7 @@ Checks if a pull request has the `auto-merge` label, waits for all checks to pas | `pr_number` | Pull Request number to check and merge | ✅ Yes | | | `github_token` | GitHub token with permissions to merge PRs | ✅ Yes | | | `repository` | Target repository in `owner/repo` format (typically `${{ github.repository }}`) | ✅ Yes | | +| `merge_label` | Label that triggers auto-merge (if present on the PR) | ❌ No | `auto-merge` | --- diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index ad30904..0fd999d 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -11,6 +11,10 @@ inputs: repository: description: "Target repository (owner/repo). Defaults to the current repository." required: true + merge_label: + description: "Label that triggers auto-merge" + required: false + default: "auto-merge" runs: using: "composite" @@ -51,7 +55,7 @@ runs: fi fi - - name: Check for 'auto-merge' label + - name: Check for '${{ inputs.merge_label }}' label id: check_label shell: bash env: @@ -60,7 +64,7 @@ runs: set -euo pipefail labels=$(gh pr view "${{ inputs.pr_number }}" --repo "${{ inputs.repository }}" --json labels -q '.labels[].name') - if grep -qx "auto-merge" <<< "$labels"; then + if grep -qx "${{ inputs.merge_label }}" <<< "$labels"; then echo "has_label=true" >> "$GITHUB_OUTPUT" else echo "has_label=false" >> "$GITHUB_OUTPUT" @@ -93,7 +97,7 @@ runs: GH_TOKEN: ${{ inputs.github_token }} run: | set -euo pipefail - echo "Merging PR #${{ inputs.pr_number }} in '${{ inputs.repository }}' (label 'auto-merge' found)" + echo "Merging PR #${{ inputs.pr_number }} in '${{ inputs.repository }}' (label '${{ inputs.merge_label }}' found)" gh pr merge "${{ inputs.pr_number }}" \ --repo "${{ inputs.repository }}" \ --squash \ @@ -102,4 +106,4 @@ runs: if: steps.check_label.outputs.has_label != 'true' shell: bash run: | - echo "Skipping merge: PR #${{ inputs.pr_number }} in repo '${{ inputs.repository }}' does not have label 'auto-merge'" + echo "Skipping merge: PR #${{ inputs.pr_number }} in repo '${{ inputs.repository }}' does not have label '${{ inputs.merge_label }}'" From c37435c3818937627b9dc8181a1c0bb6f805c92f Mon Sep 17 00:00:00 2001 From: michsi24 Date: Mon, 15 Dec 2025 14:27:28 +0200 Subject: [PATCH 10/25] ci: add merge_method input to configure merge strategy --- actions/auto-merge/README.md | 2 +- actions/auto-merge/action.yaml | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/actions/auto-merge/README.md b/actions/auto-merge/README.md index 3df7cd6..8307669 100644 --- a/actions/auto-merge/README.md +++ b/actions/auto-merge/README.md @@ -21,8 +21,8 @@ Checks if a pull request has the `auto-merge` label, waits for all checks to pas | `github_token` | GitHub token with permissions to merge PRs | ✅ Yes | | | `repository` | Target repository in `owner/repo` format (typically `${{ github.repository }}`) | ✅ Yes | | | `merge_label` | Label that triggers auto-merge (if present on the PR) | ❌ No | `auto-merge` | +| `merge_method` | Merge method to use (merge, squash, rebase). Defaults to `squash`. | ❌ No | `squash` | ---- ## 🚀 Usage diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index 0fd999d..a5381cd 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -15,6 +15,10 @@ inputs: description: "Label that triggers auto-merge" required: false default: "auto-merge" + merge_method: + description: "Merge method to use (merge, squash, rebase). Defaults to 'squash'." + required: false + default: "squash" runs: using: "composite" @@ -100,7 +104,7 @@ runs: echo "Merging PR #${{ inputs.pr_number }} in '${{ inputs.repository }}' (label '${{ inputs.merge_label }}' found)" gh pr merge "${{ inputs.pr_number }}" \ --repo "${{ inputs.repository }}" \ - --squash \ + --${{ inputs.merge_method }} \ - name: Skip merge (label missing) if: steps.check_label.outputs.has_label != 'true' From e897d92a981c148663c48de39b9bae4d95ad39db Mon Sep 17 00:00:00 2001 From: michsi24 Date: Mon, 29 Dec 2025 15:59:44 +0200 Subject: [PATCH 11/25] fix: correct typo in installation message for gh --- actions/auto-merge/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/auto-merge/action.yaml b/actions/auto-merge/action.yaml index a5381cd..fd1b17d 100644 --- a/actions/auto-merge/action.yaml +++ b/actions/auto-merge/action.yaml @@ -27,7 +27,7 @@ runs: shell: bash run: | if command -v gh >/dev/null; then - echo "gh already installed"; exit 0; + echo "gh already instlled"; exit 0; fi sudo apt-get update -y sudo apt-get install -y git curl From 392819651eada3fa9bef86a19dcf34643bcee0a1 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 12:34:34 +0200 Subject: [PATCH 12/25] trigger CI From 356f898a56cca98b4aba46497fd875dbd3b5f61e Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 13:04:34 +0200 Subject: [PATCH 13/25] ci: add test action with labels for auto-merge workflow --- .github/workflows/test-auto-merge.yaml | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 23ba1aa..284d830 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -18,3 +18,48 @@ jobs: pr_number: ${{ github.event.pull_request.number }} github_token: ${{ secrets.GH_PAT }} repository: ${{ github.repository }} + + test-action-with-labels: + runs-on: ubuntu-latest + steps: + - name: Checkout this repo + uses: actions/checkout@v6 + + - name: Checkout test-site repo + uses: actions/checkout@v6 + with: + repository: michalby24/site-values-michal-test + token: ${{ secrets.GH_PAT }} + ref: main + path: test-site + persist-credentials: false + + - name: Create empty commit in test-site + working-directory: test-site + run: | + git config user.name "GitHub Actions Bot" + git config user.email "actions@github.com" + git commit --allow-empty -m "chore: empty PR for auto-merge test (${GITHUB_SHA})" + + - name: Create Pull Request + id: create_pr + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GH_PAT }} + path: test-site + repository: michalby24/site-values-michal-test + branch: "auto-merge-e2e-${{ github.sha }}" + base: main + title: 'chore: auto-merge e2e test' + body: | + Trigger commit: https://github.com/${{ github.repository }}/commit/${{ github.sha }} + + Empty commit PR for auto-merge test. + labels: auto-merge + + - name: Run auto-merge action + uses: ./actions/auto-merge + with: + pr_number: ${{ steps.create_pr.outputs.pull-request-number }} + github_token: ${{ secrets.GH_PAT }} + repository: michalby24/site-values-michal-test From ae3bcd9a6fb17f2da1991fa1cc1bc9b8e771bee7 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 13:27:03 +0200 Subject: [PATCH 14/25] ci: update checkout actions and repository references in auto-merge workflow --- .github/workflows/test-auto-merge.yaml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 284d830..8cfaee3 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout this repo - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Run auto-merge action uses: ./actions/auto-merge @@ -25,17 +25,15 @@ jobs: - name: Checkout this repo uses: actions/checkout@v6 - - name: Checkout test-site repo + - name: Checkout test repo uses: actions/checkout@v6 with: - repository: michalby24/site-values-michal-test + repository: MapColonies/test-site token: ${{ secrets.GH_PAT }} ref: main - path: test-site persist-credentials: false - - name: Create empty commit in test-site - working-directory: test-site + - name: Create empty commit in test repo run: | git config user.name "GitHub Actions Bot" git config user.email "actions@github.com" @@ -46,8 +44,7 @@ jobs: uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.GH_PAT }} - path: test-site - repository: michalby24/site-values-michal-test + repository: MapColonies/test-site branch: "auto-merge-e2e-${{ github.sha }}" base: main title: 'chore: auto-merge e2e test' @@ -62,4 +59,4 @@ jobs: with: pr_number: ${{ steps.create_pr.outputs.pull-request-number }} github_token: ${{ secrets.GH_PAT }} - repository: michalby24/site-values-michal-test + repository: MapColonies/test-site From cb6ef650a0390ce1d94f0a272621c3877e906b1e Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 13:29:20 +0200 Subject: [PATCH 15/25] fix: update branch references from main to master in auto-merge workflow --- .github/workflows/test-auto-merge.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 8cfaee3..3f455c1 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -30,7 +30,7 @@ jobs: with: repository: MapColonies/test-site token: ${{ secrets.GH_PAT }} - ref: main + ref: master persist-credentials: false - name: Create empty commit in test repo @@ -46,7 +46,7 @@ jobs: token: ${{ secrets.GH_PAT }} repository: MapColonies/test-site branch: "auto-merge-e2e-${{ github.sha }}" - base: main + base: master title: 'chore: auto-merge e2e test' body: | Trigger commit: https://github.com/${{ github.repository }}/commit/${{ github.sha }} From 30b60bbbebfc23059dbee5f40fb1ec6581369a5d Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 13:32:37 +0200 Subject: [PATCH 16/25] ci: update GitHub token secret for auto-merge action --- .github/workflows/test-auto-merge.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 3f455c1..8618ca1 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -58,5 +58,5 @@ jobs: uses: ./actions/auto-merge with: pr_number: ${{ steps.create_pr.outputs.pull-request-number }} - github_token: ${{ secrets.GH_PAT }} + github_token: ${{ secrets.GITHUB_TOKEN }} repository: MapColonies/test-site From 363b9f49e46fcf534a88245688589e6675f49d86 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 13:46:35 +0200 Subject: [PATCH 17/25] trigger CI From 5c8fcd91d46d09388d9289583b3b0a7952ffef99 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 14:29:56 +0200 Subject: [PATCH 18/25] ci: update GitHub token secret from GITHUB_TOKEN to GH_PAT in auto-merge workflow --- .github/workflows/test-auto-merge.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 8618ca1..3f455c1 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -58,5 +58,5 @@ jobs: uses: ./actions/auto-merge with: pr_number: ${{ steps.create_pr.outputs.pull-request-number }} - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.GH_PAT }} repository: MapColonies/test-site From d629deaf14935b0d2bd3b5fe43973eba1f463164 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 14:33:16 +0200 Subject: [PATCH 19/25] ci: add dependency on create_pr step for auto-merge action --- .github/workflows/test-auto-merge.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 3f455c1..2a49c88 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -55,6 +55,7 @@ jobs: labels: auto-merge - name: Run auto-merge action + needs: create_pr uses: ./actions/auto-merge with: pr_number: ${{ steps.create_pr.outputs.pull-request-number }} From d5e48f9448c7db9c0ef4185bf7ee4ba652da638b Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 14:43:47 +0200 Subject: [PATCH 20/25] ci: add dependency on create_pr step for auto-merge action --- .github/workflows/test-auto-merge.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 2a49c88..3f455c1 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -55,7 +55,6 @@ jobs: labels: auto-merge - name: Run auto-merge action - needs: create_pr uses: ./actions/auto-merge with: pr_number: ${{ steps.create_pr.outputs.pull-request-number }} From 927a018c82d53263ce9d1bc8511f9147d5f905f0 Mon Sep 17 00:00:00 2001 From: michalby24 Date: Thu, 1 Jan 2026 14:50:18 +0200 Subject: [PATCH 21/25] ci: update GitHub token secret to GH_PAT_TEST in auto-merge workflow --- .github/workflows/test-auto-merge.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 3f455c1..99aa913 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -16,7 +16,7 @@ jobs: uses: ./actions/auto-merge with: pr_number: ${{ github.event.pull_request.number }} - github_token: ${{ secrets.GH_PAT }} + github_token: ${{ secrets.GH_PAT_TEST }} repository: ${{ github.repository }} test-action-with-labels: @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v6 with: repository: MapColonies/test-site - token: ${{ secrets.GH_PAT }} + token: ${{ secrets.GH_PAT_TEST }} ref: master persist-credentials: false @@ -43,7 +43,7 @@ jobs: id: create_pr uses: peter-evans/create-pull-request@v6 with: - token: ${{ secrets.GH_PAT }} + token: ${{ secrets.GH_PAT_TEST }} repository: MapColonies/test-site branch: "auto-merge-e2e-${{ github.sha }}" base: master @@ -58,5 +58,5 @@ jobs: uses: ./actions/auto-merge with: pr_number: ${{ steps.create_pr.outputs.pull-request-number }} - github_token: ${{ secrets.GH_PAT }} + github_token: ${{ secrets.GH_PAT_TEST }} repository: MapColonies/test-site From 4d9cfed8117eea6fe6694f1489a51810cde28d36 Mon Sep 17 00:00:00 2001 From: michsi24 Date: Sun, 4 Jan 2026 11:40:05 +0200 Subject: [PATCH 22/25] trigger CI From 0a7aa15545ffe4af5a602ea915c3cddf28360241 Mon Sep 17 00:00:00 2001 From: michsi24 Date: Sun, 4 Jan 2026 11:42:04 +0200 Subject: [PATCH 23/25] trigger CI From b3d7dcf7daaa2d04eeab0a2daf2ff6a4120cec2c Mon Sep 17 00:00:00 2001 From: michsi24 Date: Sun, 4 Jan 2026 11:44:56 +0200 Subject: [PATCH 24/25] ci: update GitHub token secret from GH_PAT_TEST to GH_PAT in auto-merge workflow --- .github/workflows/test-auto-merge.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-auto-merge.yaml b/.github/workflows/test-auto-merge.yaml index 99aa913..3f455c1 100644 --- a/.github/workflows/test-auto-merge.yaml +++ b/.github/workflows/test-auto-merge.yaml @@ -16,7 +16,7 @@ jobs: uses: ./actions/auto-merge with: pr_number: ${{ github.event.pull_request.number }} - github_token: ${{ secrets.GH_PAT_TEST }} + github_token: ${{ secrets.GH_PAT }} repository: ${{ github.repository }} test-action-with-labels: @@ -29,7 +29,7 @@ jobs: uses: actions/checkout@v6 with: repository: MapColonies/test-site - token: ${{ secrets.GH_PAT_TEST }} + token: ${{ secrets.GH_PAT }} ref: master persist-credentials: false @@ -43,7 +43,7 @@ jobs: id: create_pr uses: peter-evans/create-pull-request@v6 with: - token: ${{ secrets.GH_PAT_TEST }} + token: ${{ secrets.GH_PAT }} repository: MapColonies/test-site branch: "auto-merge-e2e-${{ github.sha }}" base: master @@ -58,5 +58,5 @@ jobs: uses: ./actions/auto-merge with: pr_number: ${{ steps.create_pr.outputs.pull-request-number }} - github_token: ${{ secrets.GH_PAT_TEST }} + github_token: ${{ secrets.GH_PAT }} repository: MapColonies/test-site From 30fbb4bad9c8477127604b1465a847f474b382e0 Mon Sep 17 00:00:00 2001 From: michsi24 Date: Sun, 4 Jan 2026 11:46:17 +0200 Subject: [PATCH 25/25] trigger CI