Skip to content

Sync main to develop #74

Sync main to develop

Sync main to develop #74

name: Sync main to develop
on:
workflow_run:
workflows:
- Deploy Documentation
types:
- completed
permissions:
contents: read
pull-requests: write
concurrency:
group: sync-main-to-develop
cancel-in-progress: false
jobs:
open-sync-pr:
name: Open main -> develop sync PR
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'main'
runs-on: ubuntu-latest
steps:
- name: Create or reuse sync PR
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const base = "develop";
const head = "main";
// Only open a PR when main is ahead of develop.
const compare = await github.rest.repos.compareCommitsWithBasehead({
owner,
repo,
basehead: `${base}...${head}`,
});
if (compare.data.ahead_by === 0) {
core.info("main is not ahead of develop; no sync PR needed.");
return;
}
const existing = await github.rest.pulls.list({
owner,
repo,
state: "open",
base,
head: `${owner}:${head}`,
per_page: 10,
});
if (existing.data.length > 0) {
core.info(`Sync PR already open: #${existing.data[0].number}`);
return;
}
const run = context.payload.workflow_run;
const body = [
"Automated branch sync after successful post-merge checks on main.",
"",
`Source commit: ${run.head_sha}`,
`Source workflow run: ${run.html_url}`,
].join("\n");
const created = await github.rest.pulls.create({
owner,
repo,
title: "chore(sync): merge main into develop",
head,
base,
body,
maintainer_can_modify: true,
});
core.info(`Created sync PR #${created.data.number}`);