amo-upload.mjs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { rename, writeFile } from 'fs/promises';
  2. import { join } from 'path';
  3. import { FatalError, signAddon } from 'amo-upload';
  4. import { readManifest, buildUpdatesList } from './manifest-helper.js';
  5. import { getVersion, isBeta } from './version-helper.js';
  6. import { hasAsset, notifyReleaseStatus } from './release-helper.mjs';
  7. async function main() {
  8. const manifest = await readManifest();
  9. const rawVersion = process.env.VERSION;
  10. const version = getVersion();
  11. const beta = isBeta();
  12. const fileName = `violentmonkey-${version}${beta ? 'b' : ''}.xpi`;
  13. const url = `https://github.com/violentmonkey/violentmonkey/releases/download/v${rawVersion}/${fileName}`;
  14. if (await hasAsset(fileName)) {
  15. // Throw an error so `updates.json` won't be updated in the next step.
  16. throw new Error('File already downloaded, skipping');
  17. }
  18. const pollOptions = !beta ? {
  19. // disable status checking for listed versions since
  20. // we don't need to download the signed version
  21. pollRetry: 0,
  22. } : {
  23. pollInterval: 30000,
  24. pollRetry: 30,
  25. };
  26. const tempFile = join(process.env.TEMP_DIR, Math.random().toString(36).slice(2, 8).toString());
  27. const releaseUrl = `https://github.com/violentmonkey/violentmonkey/releases/tag/v${version}`;
  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. releaseNotes: {
  42. 'en-US': `\
  43. Please follow the link below to view the change log:
  44. ${releaseUrl}
  45. `,
  46. },
  47. output: tempFile,
  48. ...pollOptions,
  49. });
  50. const xpiFile = join(process.env.ASSETS_DIR, fileName);
  51. await rename(tempFile, xpiFile);
  52. const updates = await buildUpdatesList(version, url);
  53. await writeFile(join(process.env.TEMP_DIR, 'updates/updates.json'), JSON.stringify(updates, null, 2), 'utf8');
  54. }
  55. main().then(() => {
  56. notifyReleaseStatus({
  57. title: `AMO Release Success: ${process.env.RELEASE_NAME}`,
  58. description: `See the changelog at https://github.com/violentmonkey/violentmonkey/releases/tag/v${process.env.VERSION}.`,
  59. });
  60. }, err => {
  61. // if (err instanceof FatalError) {
  62. notifyReleaseStatus({
  63. title: `AMO Release Failure: ${process.env.RELEASE_NAME}`,
  64. description: [
  65. 'An error occurred:',
  66. '',
  67. `> ${err}`,
  68. ...process.env.ACTION_BUILD_URL ? [
  69. '',
  70. `See ${process.env.ACTION_BUILD_URL} for more details.`,
  71. ] : [],
  72. ].join('\n'),
  73. success: false,
  74. });
  75. // }
  76. console.error(err);
  77. process.exitCode = 1;
  78. });