-
Notifications
You must be signed in to change notification settings - Fork 123
69 lines (63 loc) · 2.08 KB
/
stage.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
63
64
65
66
67
68
69
name: Create or Update PR from staging to main
on:
push:
branches:
- staging
pull_request:
types:
- closed
branches:
- staging
jobs:
create-or-update-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check for existing PR
id: check_pr
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: 'staging',
base: 'main'
});
return pullRequests.length > 0 ? 'true' : 'false';
- name: Create Pull Request
if: steps.check_pr.outputs.result == 'false'
uses: repo-sync/pull-request@v2
with:
source_branch: "staging"
destination_branch: "main"
pr_title: "Merge staging into main"
pr_body: "This PR was automatically created to merge changes from staging into main."
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Update Pull Request
if: steps.check_pr.outputs.result == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: 'staging',
base: 'main'
});
if (pullRequests.length > 0) {
const prNumber = pullRequests[0].number;
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: 'This PR has been automatically updated with the latest changes from staging.'
});
console.log(`Updated PR #${prNumber}`);
}