Skip to content

Commit 2c5762f

Browse files
author
deeleeramone
committed
ci(sync): auto-open main to develop PR after main checks
1 parent 5bd3917 commit 2c5762f

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Sync main to develop
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- Deploy Documentation
7+
types:
8+
- completed
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
concurrency:
15+
group: sync-main-to-develop
16+
cancel-in-progress: false
17+
18+
jobs:
19+
open-sync-pr:
20+
name: Open main -> develop sync PR
21+
if: >-
22+
github.event.workflow_run.conclusion == 'success' &&
23+
github.event.workflow_run.event == 'push' &&
24+
github.event.workflow_run.head_branch == 'main'
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Create or reuse sync PR
28+
uses: actions/github-script@v7
29+
with:
30+
script: |
31+
const owner = context.repo.owner;
32+
const repo = context.repo.repo;
33+
const base = "develop";
34+
const head = "main";
35+
36+
// Only open a PR when main is ahead of develop.
37+
const compare = await github.rest.repos.compareCommitsWithBasehead({
38+
owner,
39+
repo,
40+
basehead: `${base}...${head}`,
41+
});
42+
43+
if (compare.data.ahead_by === 0) {
44+
core.info("main is not ahead of develop; no sync PR needed.");
45+
return;
46+
}
47+
48+
const existing = await github.rest.pulls.list({
49+
owner,
50+
repo,
51+
state: "open",
52+
base,
53+
head: `${owner}:${head}`,
54+
per_page: 10,
55+
});
56+
57+
if (existing.data.length > 0) {
58+
core.info(`Sync PR already open: #${existing.data[0].number}`);
59+
return;
60+
}
61+
62+
const run = context.payload.workflow_run;
63+
const body = [
64+
"Automated branch sync after successful post-merge checks on main.",
65+
"",
66+
`Source commit: ${run.head_sha}`,
67+
`Source workflow run: ${run.html_url}`,
68+
].join("\n");
69+
70+
const created = await github.rest.pulls.create({
71+
owner,
72+
repo,
73+
title: "chore(sync): merge main into develop",
74+
head,
75+
base,
76+
body,
77+
maintainer_can_modify: true,
78+
});
79+
80+
core.info(`Created sync PR #${created.data.number}`);

0 commit comments

Comments
 (0)