Skip to content
This repository was archived by the owner on Dec 25, 2025. It is now read-only.

Commit 88825da

Browse files
authored
Merge pull request #4 from Jebel-Quant/3-support-automerge
automerge enabled
2 parents 66e5713 + 3956fc3 commit 88825da

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
workflow_dispatch: # Allow manual triggering
1515

1616
permissions:
17-
contents: write # Needed to create releases
17+
contents: write # Needed to push commits
1818
pull-requests: write # Needed to create pull requests
1919

2020
jobs:
@@ -54,33 +54,51 @@ This action performs the following steps:
5454
5555
The action uses sparse checkout to minimize the amount of data that needs to be downloaded, making it efficient even with large template repositories.
5656
57-
The pull request creation step uses GitHub's REST API to check if a PR already exists for the branch and creates one if needed. This ensures that multiple workflow runs don't create duplicate PRs.
57+
Pull requests are created using the peter-evans/create-pull-request action, which opens or updates a PR from the sync branch and avoids creating duplicates across runs. When a PR is created, the next step enables auto-merge using GitHub CLI (gh pr merge --merge --auto --delete-branch) so that approved PRs merge automatically and the branch is cleaned up.
58+
59+
### Auto-merge
60+
61+
After a PR is created, this action enables auto-merge when a PR number is available (condition: `steps.create-pr.outputs.pull-request-number != ''`). It uses GitHub CLI with:
62+
63+
```
64+
gh pr merge <number> --merge --auto --delete-branch
65+
```
66+
67+
This merges the PR once it meets merge requirements and deletes the branch afterward.
5868
5969
### GitHub Token Permissions
6070
6171
When using this action to sync workflow files (files in `.github/workflows/`), you need to be aware of GitHub's token permission restrictions:
6272
63-
1. **Default `GITHUB_TOKEN`**: Does not have permission to update workflow files in a repository. If you try to sync workflow files using the default token, you'll get an error like:
73+
1. **Default `GITHUB_TOKEN`**: Does not have permission to update workflow files in a repository.
74+
If you try to sync workflow files using the default token, you'll get an error like:
75+
6476
```
6577
! [remote rejected] HEAD -> sync/update (refusing to allow a GitHub App to create or update workflow without `workflows` permission)
6678
```
6779
6880
2. **Personal Access Token (PAT)**: To sync workflow files, you must use a PAT with the `workflow` scope. Configure this in your workflow:
81+
6982
```yaml
7083
with:
7184
token: ${{ secrets.PAT_WITH_WORKFLOW_SCOPE }}
7285
```
7386

7487
3. **Repository Settings**: Alternatively, you can modify the default token permissions in your repository settings:
88+
7589
- Go to Settings > Actions > General
7690
- Under "Workflow permissions", select "Read and write permissions"
7791
- Check "Allow GitHub Actions to create and approve pull requests"
7892

79-
The action will automatically detect when workflow files are being modified and provide appropriate warnings.
93+
The action will automatically detect when workflow files are being modified
94+
and provide appropriate warnings.
8095

8196
### Configuration File
8297

83-
The action reads template configuration from a YAML file specified by the `source` parameter. This allows you to maintain template settings separately from your workflow files.
98+
The action reads template configuration from a YAML file
99+
specified by the `source` parameter.
100+
This allows you to maintain template settings separately
101+
from your workflow files.
84102

85103
Example configuration file (e.g., `template.yml`):
86104

@@ -104,6 +122,7 @@ exclude: |
104122
```
105123
106124
When using the configuration file:
125+
107126
1. You must specify the path to this file using the `source` parameter
108127
2. The file must contain at least the `template-repository` value
109128
3. Other values (`template-branch`, `include`, `exclude`) are optional
@@ -172,4 +191,5 @@ Contributions are welcome! Here's how you can contribute:
172191
6. Push to the branch (`git push origin feature/amazing-feature`)
173192
7. Open a Pull Request
174193

175-
Please make sure to update tests as appropriate and adhere to the existing coding style.
194+
Please make sure to update tests as appropriate and adhere
195+
to the existing coding style.

action.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,14 @@ runs:
165165
This PR updates configuration files from
166166
[${{ steps.config.outputs.template_repository }}@${{ steps.config.outputs.template_branch }}](https://github.com/${{ steps.config.outputs.template_repository }}/tree/${{ steps.config.outputs.template_branch }}).
167167
delete-branch: true
168+
169+
- name: Enable auto-merge
170+
shell: bash
171+
if: ${{ steps.create-pr.outputs.pull-request-number != '' }}
172+
env:
173+
GH_TOKEN: ${{ inputs.token }}
174+
run: |
175+
gh pr merge ${{ steps.create-pr.outputs.pull-request-number }} \
176+
--merge \
177+
--auto \
178+
--delete-branch

0 commit comments

Comments
 (0)