Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0482082
ci(auto-merge): add action to automatically merge PRs with 'auto-merg…
Dec 9, 2025
92b0d19
ci: update action to include repository input and enhance authenticat…
Dec 9, 2025
361a38b
ci(auto-merge): update workflow to use dynamic PR number and improve …
Dec 9, 2025
51bb00d
ci(auto-merge): refine installation and authentication steps for gh
Dec 10, 2025
6b301bb
ci(auto-merge): wait for required checks to pass before merging PRs
Dec 10, 2025
4b1c8f5
feat(auto-merge): add auto-merge action for labeled PRs with passing …
Dec 11, 2025
e0cd093
Merge branch 'master' into auto-merge
michalby24 Dec 11, 2025
7ae4a68
ci(auto-merge): update test workflow to use dynamic repository input
Dec 11, 2025
967c805
Merge branch 'auto-merge' of https://github.com/MapColonies/shared-wo…
Dec 11, 2025
d6da8a4
docs(auto-merge): add README for auto-merge
Dec 11, 2025
d35edd1
ci: refine commit message format and update PR labels handling
Dec 15, 2025
c37435c
ci: add merge_method input to configure merge strategy
Dec 15, 2025
e897d92
fix: correct typo in installation message for gh
Dec 29, 2025
3928196
trigger CI
Jan 1, 2026
356f898
ci: add test action with labels for auto-merge workflow
Jan 1, 2026
ae3bcd9
ci: update checkout actions and repository references in auto-merge w…
Jan 1, 2026
cb6ef65
fix: update branch references from main to master in auto-merge workflow
Jan 1, 2026
30b60bb
ci: update GitHub token secret for auto-merge action
Jan 1, 2026
363b9f4
trigger CI
Jan 1, 2026
5c8fcd9
ci: update GitHub token secret from GITHUB_TOKEN to GH_PAT in auto-me…
Jan 1, 2026
d629dea
ci: add dependency on create_pr step for auto-merge action
Jan 1, 2026
d5e48f9
ci: add dependency on create_pr step for auto-merge action
Jan 1, 2026
927a018
ci: update GitHub token secret to GH_PAT_TEST in auto-merge workflow
Jan 1, 2026
4d9cfed
trigger CI
Jan 4, 2026
0a7aa15
trigger CI
Jan 4, 2026
b3d7dcf
ci: update GitHub token secret from GH_PAT_TEST to GH_PAT in auto-mer…
Jan 4, 2026
30fbb4b
trigger CI
Jan 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/test-auto-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Test auto-merge action

on:
pull_request:
paths:
- "actions/auto-merge/**"

jobs:
test-action:
runs-on: ubuntu-latest
steps:
- name: Checkout this repo
uses: actions/checkout@v6

- name: Run auto-merge action
uses: ./actions/auto-merge
with:
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 repo
uses: actions/checkout@v6
with:
repository: MapColonies/test-site
token: ${{ secrets.GH_PAT }}
ref: master
persist-credentials: false

- name: Create empty commit in test repo
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 }}
repository: MapColonies/test-site
branch: "auto-merge-e2e-${{ github.sha }}"
base: master
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: MapColonies/test-site
45 changes: 45 additions & 0 deletions actions/auto-merge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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 | |
| `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

<!-- x-release-please-start-version -->

```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 }}
```

<!-- x-release-please-end-version -->
113 changes: 113 additions & 0 deletions actions/auto-merge/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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
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"
merge_method:
description: "Merge method to use (merge, squash, rebase). Defaults to 'squash'."
required: false
default: "squash"

runs:
using: "composite"
steps:
- name: Install gh (for act)
shell: bash
run: |
if command -v gh >/dev/null; then
echo "gh already instlled"; 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: Check for '${{ inputs.merge_label }}' label
id: check_label
shell: bash
env:
GH_TOKEN: ${{ inputs.github_token }}
run: |
set -euo pipefail
labels=$(gh pr view "${{ inputs.pr_number }}" --repo "${{ inputs.repository }}" --json labels -q '.labels[].name')

if grep -qx "${{ inputs.merge_label }}" <<< "$labels"; then
echo "has_label=true" >> "$GITHUB_OUTPUT"
else
echo "has_label=false" >> "$GITHUB_OUTPUT"
fi

- 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 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 '${{ inputs.merge_label }}' found)"
gh pr merge "${{ inputs.pr_number }}" \
--repo "${{ inputs.repository }}" \
--${{ inputs.merge_method }} \

- name: Skip merge (label missing)
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 '${{ inputs.merge_label }}'"
5 changes: 5 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"release-type": "simple",
"package-name": "update-chart-version",
"extra-files": ["README.md"]
},
"actions/auto-merge": {
"release-type": "simple",
"package-name": "auto-merge",
"extra-files": ["README.md"]
}
}
}
Loading