Repository navigation
87 lines (78 loc) · 2.84 KB
/
Copy pathsync-prod.yml
File metadata and controls
87 lines (78 loc) · 2.84 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Sync nightly → production
on:
schedule:
# Run weekly on Sundays at midnight UTC
- cron: "0 0 * * 0"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
concurrency:
group: sync-nightly-production
cancel-in-progress: true
jobs:
create-and-merge:
name: Create PR and merge into production
runs-on: ubuntu-latest
steps:
- name: Create or update PR and merge when possible
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const head = 'nightly';
const base = 'production';
const title = `chore: sync ${head} → ${base} (${new Date().toISOString().split('T')[0]})`;
const body = `Automated sync of ${head} into ${base} by workflow.`;
// Look for an existing open PR from nightly -> production
const { data: existing } = await github.rest.pulls.list({
owner,
repo,
state: 'open',
head: `${owner}:${head}`,
base,
});
let pr;
if (existing.length > 0) {
pr = existing[0];
core.info(`Found existing PR #${pr.number}`);
} else {
const { data: created } = await github.rest.pulls.create({
owner,
repo,
title,
head,
base,
body,
maintainer_can_modify: true,
});
pr = created;
core.info(`Created PR #${pr.number}`);
}
// Wait for GitHub to compute mergeability (it may be null initially)
let refreshed = pr;
for (let i = 0; i < 10; i++) {
const { data } = await github.rest.pulls.get({ owner, repo, pull_number: pr.number });
refreshed = data;
if (refreshed.mergeable !== null) break;
await new Promise((r) => setTimeout(r, 2000));
}
if (!refreshed.mergeable) {
core.setOutput('pr-number', String(pr.number));
core.info(`PR #${pr.number} is not mergeable (state=${refreshed.mergeable_state}). Leaving PR open for manual resolution.`);
return;
}
// Merge the PR
try {
const mergeRes = await github.rest.pulls.merge({
owner,
repo,
pull_number: pr.number,
merge_method: 'merge',
});
core.info(`Merged PR #${pr.number} — sha: ${mergeRes.data.sha}`);
core.setOutput('pr-number', String(pr.number));
} catch (err) {
core.setFailed(`Failed to merge PR #${pr.number}: ${err.message}`);
}