Index: automation/builds/gecko.js |
diff --git a/automation/builds/gecko.js b/automation/builds/gecko.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c0cfccbdd786358d61bdea93d83a1035fd60de02 |
--- /dev/null |
+++ b/automation/builds/gecko.js |
@@ -0,0 +1,89 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-present eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+/* eslint-env node */ |
+ |
+"use strict"; |
+ |
+const path = require("path"); |
+const {exec} = require("child_process"); |
+const signAddon = require("sign-addon").default; |
+const fs = require("fs"); |
+ |
+let buildnum = undefined; |
Sebastian Noack
2018/10/04 19:56:53
Do these really need to be global variables? Why?
tlucas
2018/10/15 10:26:19
Done.
|
+let version = undefined; |
+let appId = undefined; |
+let auth = JSON.parse( |
+ fs.readFileSync(path.resolve(process.env.AMO_OAUTH_CREDENTIALS))); |
Sebastian Noack
2018/10/04 19:56:53
I'm not sure if using sync APIs is justified here.
tlucas
2018/10/15 10:26:20
I "promisified" fs.readFile(), so that we can wait
|
+ |
+function execPromise(command) |
+{ |
+ return new Promise((resolve, reject) => |
+ { |
+ exec( |
+ command, |
+ (error, stdout, stderr) => |
+ { |
+ if (error) |
+ { |
+ console.error(stderr); |
+ reject(error); |
+ } |
+ else resolve(stdout.replace(/(\r\n|\n|\r)/gm, "")); |
Sebastian Noack
2018/10/04 19:56:53
Nit: Please a new line after the else statement.
Sebastian Noack
2018/10/04 19:56:53
Do you really want to remove every new line (and i
tlucas
2018/10/15 10:26:20
It was trimming. Done.
|
+ } |
+ ); |
+ }); |
+} |
+ |
+function pythonMetadata(section, option) |
+{ |
+ let cmd = "python -c \"" + |
+ "from buildtools.chainedconfigparser import ChainedConfigParser; " + |
+ "p = ChainedConfigParser(); " + |
+ "p.read('metadata.gecko'); " + |
+ `print p.get('${section}', '${option}')"`; |
+ return execPromise(cmd.trim()); |
+} |
+ |
+let getBuildNum = execPromise("git rev-list --count --branches --tags HEAD"); |
+ |
+Promise.all([ |
+ pythonMetadata("general", "version"), |
+ pythonMetadata("general", "app_id_devbuild"), |
+ getBuildNum |
+]).then(([v, i, b]) => |
+{ |
+ version = v; |
+ buildnum = b; |
+ appId = i; |
+ return execPromise( |
+ `bash -c "python build.py build -t gecko -b \ |
Sebastian Noack
2018/10/04 19:56:53
Calling the command through bash seems unnecessary
tlucas
2018/10/15 10:26:20
Done.
|
+ ${buildnum} adblockplusfirefox-${version}.${buildnum}.xpi"`); |
+}).then(() => |
+ signAddon({ |
+ xpiPath: `adblockplusfirefox-${version}.${buildnum}.xpi`, |
+ version: `${version}.${buildnum}`, |
+ apiKey: auth["AMO_KEY"], |
+ apiSecret: auth["AMO_SECRET"], |
+ channel: "unlisted", |
+ id: appId |
+ }) |
+).then(result => |
+{ |
+ if (!result.success) |
+ process.exit(1); |
Sebastian Noack
2018/10/04 19:56:52
Is there any error we can log in this case?
tlucas
2018/10/15 10:26:19
signAddon itself prints the reason to the console,
|
+}); |