summaryrefslogtreecommitdiff
path: root/.github/workflows/android-merge.js
diff options
context:
space:
mode:
Diffstat (limited to '.github/workflows/android-merge.js')
-rw-r--r--.github/workflows/android-merge.js129
1 files changed, 103 insertions, 26 deletions
diff --git a/.github/workflows/android-merge.js b/.github/workflows/android-merge.js
index 44ab56e44..315f81ba0 100644
--- a/.github/workflows/android-merge.js
+++ b/.github/workflows/android-merge.js
@@ -6,9 +6,12 @@
6 6
7const fs = require("fs"); 7const fs = require("fs");
8// which label to check for changes 8// which label to check for changes
9const CHANGE_LABEL = 'android-merge'; 9const CHANGE_LABEL_MAINLINE = 'android-merge';
10const CHANGE_LABEL_EA = 'android-ea-merge';
10// how far back in time should we consider the changes are "recent"? (default: 24 hours) 11// how far back in time should we consider the changes are "recent"? (default: 24 hours)
11const DETECTION_TIME_FRAME = (parseInt(process.env.DETECTION_TIME_FRAME)) || (24 * 3600 * 1000); 12const DETECTION_TIME_FRAME = (parseInt(process.env.DETECTION_TIME_FRAME)) || (24 * 3600 * 1000);
13const BUILD_EA = process.env.BUILD_EA == 'true';
14const MAINLINE_TAG = process.env.MAINLINE_TAG;
12 15
13async function checkBaseChanges(github) { 16async function checkBaseChanges(github) {
14 // query the commit date of the latest commit on this branch 17 // query the commit date of the latest commit on this branch
@@ -40,20 +43,7 @@ async function checkBaseChanges(github) {
40 43
41async function checkAndroidChanges(github) { 44async function checkAndroidChanges(github) {
42 if (checkBaseChanges(github)) return true; 45 if (checkBaseChanges(github)) return true;
43 const query = `query($owner:String!, $name:String!, $label:String!) { 46 const pulls = getPulls(github, false);
44 repository(name:$name, owner:$owner) {
45 pullRequests(labels: [$label], states: OPEN, first: 100) {
46 nodes { number headRepository { pushedAt } }
47 }
48 }
49 }`;
50 const variables = {
51 owner: 'yuzu-emu',
52 name: 'yuzu',
53 label: CHANGE_LABEL,
54 };
55 const result = await github.graphql(query, variables);
56 const pulls = result.repository.pullRequests.nodes;
57 for (let i = 0; i < pulls.length; i++) { 47 for (let i = 0; i < pulls.length; i++) {
58 let pull = pulls[i]; 48 let pull = pulls[i];
59 if (new Date() - new Date(pull.headRepository.pushedAt) <= DETECTION_TIME_FRAME) { 49 if (new Date() - new Date(pull.headRepository.pushedAt) <= DETECTION_TIME_FRAME) {
@@ -83,7 +73,13 @@ async function tagAndPush(github, owner, repo, execa, commit=false) {
83 }; 73 };
84 const tags = await github.graphql(query, variables); 74 const tags = await github.graphql(query, variables);
85 const tagList = tags.repository.refs.nodes; 75 const tagList = tags.repository.refs.nodes;
86 const lastTag = tagList[0] ? tagList[0].name : 'dummy-0'; 76 let lastTag = 'android-1';
77 for (let i = 0; i < tagList.length; ++i) {
78 if (tagList[i].name.includes('android-')) {
79 lastTag = tagList[i].name;
80 break;
81 }
82 }
87 const tagNumber = /\w+-(\d+)/.exec(lastTag)[1] | 0; 83 const tagNumber = /\w+-(\d+)/.exec(lastTag)[1] | 0;
88 const channel = repo.split('-')[1]; 84 const channel = repo.split('-')[1];
89 const newTag = `${channel}-${tagNumber + 1}`; 85 const newTag = `${channel}-${tagNumber + 1}`;
@@ -101,6 +97,48 @@ async function tagAndPush(github, owner, repo, execa, commit=false) {
101 console.info('Successfully pushed new changes.'); 97 console.info('Successfully pushed new changes.');
102} 98}
103 99
100async function tagAndPushEA(github, owner, repo, execa) {
101 let altToken = process.env.ALT_GITHUB_TOKEN;
102 if (!altToken) {
103 throw `Please set ALT_GITHUB_TOKEN environment variable. This token should have write access to ${owner}/${repo}.`;
104 }
105 const query = `query ($owner:String!, $name:String!) {
106 repository(name:$name, owner:$owner) {
107 refs(refPrefix: "refs/tags/", orderBy: {field: TAG_COMMIT_DATE, direction: DESC}, first: 10) {
108 nodes { name }
109 }
110 }
111 }`;
112 const variables = {
113 owner: owner,
114 name: repo,
115 };
116 const tags = await github.graphql(query, variables);
117 const tagList = tags.repository.refs.nodes;
118 let lastTag = 'ea-1';
119 for (let i = 0; i < tagList.length; ++i) {
120 if (tagList[i].name.includes('ea-')) {
121 lastTag = tagList[i].name;
122 break;
123 }
124 }
125 const tagNumber = /\w+-(\d+)/.exec(lastTag)[1] | 0;
126 const newTag = `ea-${tagNumber + 1}`;
127 console.log(`New tag: ${newTag}`);
128 console.info('Pushing tags to GitHub ...');
129 await execa("git", ["remote", "add", "android", "https://github.com/yuzu-emu/yuzu-android.git"]);
130 await execa("git", ["fetch", "android"]);
131
132 await execa("git", ['tag', newTag]);
133 await execa("git", ['push', 'android', `${newTag}`]);
134
135 fs.writeFile('tag-name.txt', newTag, (err) => {
136 if (err) throw 'Could not write tag name to file!'
137 })
138
139 console.info('Successfully pushed new changes.');
140}
141
104async function generateReadme(pulls, context, mergeResults, execa) { 142async function generateReadme(pulls, context, mergeResults, execa) {
105 let baseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/`; 143 let baseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/`;
106 let output = 144 let output =
@@ -202,10 +240,7 @@ async function resetBranch(execa) {
202 } 240 }
203} 241}
204 242
205async function mergebot(github, context, execa) { 243async function getPulls(github) {
206 // Reset our local copy of master to what appears on yuzu-emu/yuzu - master
207 await resetBranch(execa);
208
209 const query = `query ($owner:String!, $name:String!, $label:String!) { 244 const query = `query ($owner:String!, $name:String!, $label:String!) {
210 repository(name:$name, owner:$owner) { 245 repository(name:$name, owner:$owner) {
211 pullRequests(labels: [$label], states: OPEN, first: 100) { 246 pullRequests(labels: [$label], states: OPEN, first: 100) {
@@ -215,13 +250,49 @@ async function mergebot(github, context, execa) {
215 } 250 }
216 } 251 }
217 }`; 252 }`;
218 const variables = { 253 const mainlineVariables = {
219 owner: 'yuzu-emu', 254 owner: 'yuzu-emu',
220 name: 'yuzu', 255 name: 'yuzu',
221 label: CHANGE_LABEL, 256 label: CHANGE_LABEL_MAINLINE,
222 }; 257 };
223 const result = await github.graphql(query, variables); 258 const mainlineResult = await github.graphql(query, mainlineVariables);
224 const pulls = result.repository.pullRequests.nodes; 259 const pulls = mainlineResult.repository.pullRequests.nodes;
260 if (BUILD_EA) {
261 const eaVariables = {
262 owner: 'yuzu-emu',
263 name: 'yuzu',
264 label: CHANGE_LABEL_EA,
265 };
266 const eaResult = await github.graphql(query, eaVariables);
267 const eaPulls = eaResult.repository.pullRequests.nodes;
268 return pulls.concat(eaPulls);
269 }
270 return pulls;
271}
272
273async function getMainlineTag(execa) {
274 console.log(`::group::Getting mainline tag android-${MAINLINE_TAG}`);
275 let hasFailed = false;
276 try {
277 await execa("git", ["remote", "add", "mainline", "https://github.com/yuzu-emu/yuzu-android.git"]);
278 await execa("git", ["fetch", "mainline", "--tags"]);
279 await execa("git", ["checkout", `tags/android-${MAINLINE_TAG}`]);
280 await execa("git", ["submodule", "update", "--init", "--recursive"]);
281 } catch (err) {
282 console.log('::error title=Failed pull tag');
283 hasFailed = true;
284 }
285 console.log("::endgroup::");
286 if (hasFailed) {
287 throw 'Failed pull mainline tag. Aborting!';
288 }
289}
290
291async function mergebot(github, context, execa) {
292 // Reset our local copy of master to what appears on yuzu-emu/yuzu - master
293 await resetBranch(execa);
294
295 const pulls = await getPulls(github);
225 let displayList = []; 296 let displayList = [];
226 for (let i = 0; i < pulls.length; i++) { 297 for (let i = 0; i < pulls.length; i++) {
227 let pull = pulls[i]; 298 let pull = pulls[i];
@@ -231,11 +302,17 @@ async function mergebot(github, context, execa) {
231 console.table(displayList); 302 console.table(displayList);
232 await fetchPullRequests(pulls, "https://github.com/yuzu-emu/yuzu", execa); 303 await fetchPullRequests(pulls, "https://github.com/yuzu-emu/yuzu", execa);
233 const mergeResults = await mergePullRequests(pulls, execa); 304 const mergeResults = await mergePullRequests(pulls, execa);
234 await generateReadme(pulls, context, mergeResults, execa); 305
235 await tagAndPush(github, 'yuzu-emu', `yuzu-android`, execa, true); 306 if (BUILD_EA) {
307 await tagAndPushEA(github, 'yuzu-emu', `yuzu-android`, execa);
308 } else {
309 await generateReadme(pulls, context, mergeResults, execa);
310 await tagAndPush(github, 'yuzu-emu', `yuzu-android`, execa, true);
311 }
236} 312}
237 313
238module.exports.mergebot = mergebot; 314module.exports.mergebot = mergebot;
239module.exports.checkAndroidChanges = checkAndroidChanges; 315module.exports.checkAndroidChanges = checkAndroidChanges;
240module.exports.tagAndPush = tagAndPush; 316module.exports.tagAndPush = tagAndPush;
241module.exports.checkBaseChanges = checkBaseChanges; 317module.exports.checkBaseChanges = checkBaseChanges;
318module.exports.getMainlineTag = getMainlineTag;