amo-upload.mjs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { signAddon } from 'amo-upload';
  2. import { mkdir, rename, writeFile } from 'fs/promises';
  3. import { join } from 'path';
  4. import { buildUpdatesList, readManifest } from './manifest-helper.js';
  5. import { hasAsset, notifyReleaseStatus } from './release-helper.mjs';
  6. import { getVersion, isBeta } from './version-helper.js';
  7. const version = getVersion();
  8. const beta = isBeta();
  9. async function handleAddon() {
  10. const manifest = await readManifest();
  11. const fileName = `violentmonkey-${version}${beta ? 'b' : ''}.xpi`;
  12. const url = `https://github.com/violentmonkey/violentmonkey/releases/download/v${version}/${fileName}`;
  13. if (await hasAsset(fileName)) {
  14. // Throw an error so `updates.json` won't be updated in the next step.
  15. throw new Error('File already downloaded, skipping');
  16. }
  17. const tempFile = join(
  18. process.env.TEMP_DIR,
  19. Math.random().toString(36).slice(2, 8).toString(),
  20. );
  21. const releaseUrl = `https://github.com/violentmonkey/violentmonkey/releases/tag/v${version}`;
  22. await signAddon({
  23. apiKey: process.env.AMO_KEY,
  24. apiSecret: process.env.AMO_SECRET,
  25. addonId: manifest.browser_specific_settings.gecko.id,
  26. addonVersion: version,
  27. channel: beta ? 'unlisted' : 'listed',
  28. compatibility: {
  29. android: { min: '121.0a1' },
  30. firefox: { min: '57.0' },
  31. },
  32. ...(process.env.AMO_PUBLISH
  33. ? {
  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. # please use nodejs 20 or 24 because nodejs 22 is known to fail
  40. yarn && yarn build
  41. `,
  42. releaseNotes: {
  43. 'en-US': `\
  44. Please follow the link below to view the change log:
  45. ${releaseUrl}
  46. `,
  47. },
  48. }
  49. : {}),
  50. output: tempFile,
  51. // Don't poll since the review process takes quite a long time
  52. pollRetry: 0,
  53. });
  54. const xpiFile = join(process.env.ASSETS_DIR, fileName);
  55. await mkdir(process.env.ASSETS_DIR, { recursive: true });
  56. await rename(tempFile, xpiFile);
  57. const updates = await buildUpdatesList(version, url);
  58. await writeFile(
  59. join(process.env.TEMP_DIR, 'updates/updates.json'),
  60. JSON.stringify(updates, null, 2),
  61. 'utf8',
  62. );
  63. }
  64. async function main() {
  65. let error;
  66. try {
  67. await handleAddon();
  68. } catch (err) {
  69. if (err?.message === 'Polling skipped') {
  70. error = beta ? new Error('Pending review') : undefined;
  71. } else {
  72. error = err;
  73. }
  74. }
  75. if (error) throw error;
  76. }
  77. main().then(
  78. () => {
  79. notifyReleaseStatus({
  80. title: `AMO Release Success: ${process.env.RELEASE_NAME}`,
  81. description: `See the changelog at https://github.com/violentmonkey/violentmonkey/releases/tag/v${process.env.VERSION}.`,
  82. });
  83. },
  84. (err) => {
  85. // if (err instanceof FatalError) {
  86. notifyReleaseStatus({
  87. title: `AMO Release Failure: ${process.env.RELEASE_NAME}`,
  88. description: [
  89. 'An error occurred:',
  90. '',
  91. `> ${err}`,
  92. ...(process.env.ACTION_BUILD_URL
  93. ? ['', `See ${process.env.ACTION_BUILD_URL} for more details.`]
  94. : []),
  95. ].join('\n'),
  96. success: false,
  97. });
  98. // }
  99. console.error(err);
  100. process.exitCode = 1;
  101. },
  102. );