-
Notifications
You must be signed in to change notification settings - Fork 37
62 lines (55 loc) · 2.06 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Auto PR and Merge on Push by Specific User
on:
push:
branches:
- main
jobs:
auto-pr-and-merge:
runs-on: ubuntu-latest
steps:
- name: Check User
id: check_user
run: |
echo "user_matched=${{ github.actor == 'unclecode' }}"
echo "user_matched=${{ github.actor == 'unclecode' }}" >> $GITHUB_ENV
- name: Create Pull Request
if: env.user_matched == 'true'
id: create_pull_request
uses: actions/github-script@v5
with:
script: |
const payload = {
owner: context.repo.owner,
repo: context.repo.repo,
head: 'main',
base: 'live',
title: 'Auto PR from main to live',
body: 'Automatically generated PR to keep live branch up-to-date',
draft: false,
};
// Create the pull request
await github.rest.pulls.create(payload).then(pr => {
core.setOutput('pr_number', pr.data.number);
}).catch(err => core.setFailed(`Failed to create PR: ${err.message}`));
- name: Merge Pull Request
if: env.user_matched == 'true'
uses: actions/github-script@v5
with:
script: |
const pr_number = ${{ steps.create_pull_request.outputs.pr_number }};
if (!pr_number) {
core.setFailed('PR number is undefined, skipping merge.');
return;
}
const payload = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: parseInt(pr_number, 10),
merge_method: 'merge', // Options: 'merge', 'squash', or 'rebase'
};
// Attempt to merge the pull request
await github.rest.pulls.merge(payload).then(response => {
if (response.status !== 200) {
core.setFailed('Failed to merge the pull request');
}
}).catch(err => core.setFailed(`Failed to merge PR: ${err.message}`));