amo-upload.mjs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { rename, writeFile } from 'fs/promises';
  2. import { join } from 'path';
  3. import { signAddon } from 'amo-upload';
  4. import { readManifest, buildUpdatesList } from './manifest-helper.js';
  5. import { getVersion, isBeta } from './version-helper.js';
  6. import { hasAsset } from './release-helper.js';
  7. async function main() {
  8. const manifest = await readManifest();
  9. const rawVersion = process.env.VERSION;
  10. // version may be suffixed for unlisted version
  11. const version = getVersion();
  12. const beta = isBeta();
  13. const fileName = `violentmonkey-${version}-an+fx.xpi`;
  14. const url = `https://github.com/violentmonkey/violentmonkey/releases/download/v${rawVersion}/${fileName}`;
  15. if (await hasAsset(fileName)) {
  16. // Throw an error so `updates.json` won't be updated in the next step.
  17. throw new Error('File already downloaded, skipping');
  18. }
  19. const pollOptions = !beta ? {
  20. // disable status checking for listed versions since
  21. // we don't need to download the signed version
  22. pollRetry: 0,
  23. } : {
  24. pollInterval: 30000,
  25. pollRetry: 30,
  26. };
  27. const tempFile = join(process.env.TEMP_DIR, Math.random().toString(36).slice(2, 8).toString());
  28. await signAddon({
  29. apiKey: process.env.AMO_KEY,
  30. apiSecret: process.env.AMO_SECRET,
  31. addonId: manifest.browser_specific_settings.gecko.id,
  32. addonVersion: version,
  33. channel: beta ? 'unlisted' : 'listed',
  34. distFile: beta
  35. ? join(process.env.TEMP_DIR, process.env.ASSET_SELF_HOSTED_ZIP)
  36. : join(process.env.ASSETS_DIR, process.env.ASSET_ZIP),
  37. sourceFile: join(process.env.TEMP_DIR, process.env.SOURCE_ZIP),
  38. approvalNotes: `\
  39. yarn && yarn build
  40. `,
  41. output: tempFile,
  42. ...pollOptions,
  43. });
  44. const xpiFile = join(process.env.ASSETS_DIR, fileName);
  45. await rename(tempFile, xpiFile);
  46. const updates = await buildUpdatesList(version, url);
  47. await writeFile(join(process.env.TEMP_DIR, 'updates/updates.json'), JSON.stringify(updates, null, 2), 'utf8');
  48. }
  49. main().catch(err => {
  50. console.error(err);
  51. process.exitCode = 1;
  52. });