-
Notifications
You must be signed in to change notification settings - Fork 3
70 lines (63 loc) · 2.01 KB
/
sync-develop.yml
File metadata and controls
70 lines (63 loc) · 2.01 KB
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
70
name: Sync main into develop
on:
push:
tags:
- 'v*'
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Open PR from main to develop
uses: actions/github-script@v7
with:
script: |
const tag = context.ref.replace('refs/tags/', '');
const { owner, repo } = context.repo;
// Check if develop branch exists
try {
await github.rest.repos.getBranch({ owner, repo, branch: 'develop' });
} catch (e) {
if (e.status === 404) {
core.warning('Branch "develop" not found. Skipping PR creation.');
return;
}
throw e;
}
// Check if branches are already in sync
const comparison = await github.rest.repos.compareCommitsWithBasehead({
owner,
repo,
basehead: 'develop...main',
});
if (comparison.data.ahead_by === 0) {
core.info('Branches are already in sync. No PR needed.');
return;
}
// Check if a PR from main to develop already exists
const existingPRs = await github.rest.pulls.list({
owner,
repo,
state: 'open',
head: `${owner}:main`,
base: 'develop',
});
if (existingPRs.data.length > 0) {
core.info(`PR already exists: ${existingPRs.data[0].html_url}`);
return;
}
await github.rest.pulls.create({
owner,
repo,
title: `chore: sync ${tag} from main into develop`,
head: 'main',
base: 'develop',
body: `Automated back-merge after release ${tag}.`,
});