forked from microsoft/graphrag
-
Notifications
You must be signed in to change notification settings - Fork 0
124 lines (105 loc) · 4.38 KB
/
Copy pathmonitor-upstream.yml
File metadata and controls
124 lines (105 loc) · 4.38 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Monitor Upstream Changes
on:
schedule:
- cron: '0 8 * * *' # Run daily at 08:00 UTC
workflow_dispatch: # Allow manual triggering
permissions:
contents: read
issues: write
jobs:
check-upstream:
runs-on: ubuntu-latest
steps:
- name: Checkout fork
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fetch upstream
run: |
git remote add upstream https://github.com/microsoft/graphrag.git
git fetch upstream main
- name: Compute outstanding changes
run: |
COUNT=$(git rev-list --count HEAD..upstream/main 2>/dev/null || echo "0")
echo "$COUNT" > /tmp/commit-count.txt
git log --oneline --no-merges -50 HEAD..upstream/main > /tmp/commit-list.txt 2>/dev/null || true
- name: Create or update tracking issue
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const count = parseInt(fs.readFileSync('/tmp/commit-count.txt', 'utf8').trim(), 10);
const rawList = fs.readFileSync('/tmp/commit-list.txt', 'utf8').trim();
// Ensure the tracking label exists
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'upstream-tracking',
});
} catch {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'upstream-tracking',
color: '0075ca',
description: 'Tracks outstanding changes from the upstream microsoft/graphrag repository',
});
}
const now = new Date().toUTCString();
const comparisonUrl =
'https://github.com/microsoft/graphrag/compare/main...sharpninja:graphrag:main';
const commitSection =
count === 0
? '_No outstanding commits — fork is up to date with upstream._'
: '```\n' + rawList + '\n```';
const body =
`@sharpninja\n\n` +
`## Outstanding Changes from \`microsoft/graphrag\`\n\n` +
`**${count} commit(s) pending** as of ${now}\n\n` +
`### Recent upstream commits not yet in this fork\n\n` +
commitSection + '\n\n' +
`---\n` +
`[View full comparison on GitHub](${comparisonUrl})\n\n` +
`*This issue is updated automatically every day by the [Monitor Upstream Changes]` +
`(../../actions/workflows/monitor-upstream.yml) workflow.*`;
const title = `\uD83D\uDD04 Upstream Tracking: ${count} pending change(s) from microsoft/graphrag`;
// Find an existing open tracking issue
const existing = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'upstream-tracking',
per_page: 1,
});
if (existing.data.length > 0) {
const issueNumber = existing.data[0].number;
// Update the issue body and title
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
title,
body,
});
// Add a comment so @sharpninja receives a new notification
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body:
`@sharpninja **Update ${now}**: ` +
`**${count}** outstanding change(s) from upstream detected.\n\n` +
`[View full comparison](${comparisonUrl})`,
});
console.log(`Updated issue #${issueNumber}`);
} else {
const created = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: ['upstream-tracking'],
});
console.log(`Created issue #${created.data.number}`);
}