amo-upload.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. 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. }
  48. : {}),
  49. output: tempFile,
  50. // Don't poll since the review process takes quite a long time
  51. pollRetry: 0,
  52. });
  53. const xpiFile = join(process.env.ASSETS_DIR, fileName);
  54. await mkdir(process.env.ASSETS_DIR, { recursive: true });
  55. await rename(tempFile, xpiFile);
  56. const updates = await buildUpdatesList(version, url);
  57. await writeFile(
  58. join(process.env.TEMP_DIR, 'updates/updates.json'),
  59. JSON.stringify(updates, null, 2),
  60. 'utf8',
  61. );
  62. }
  63. async function main() {
  64. let error;
  65. try {
  66. await handleAddon();
  67. } catch (err) {
  68. if (err?.message === 'Polling skipped') {
  69. error = beta ? new Error('Pending review') : undefined;
  70. } else {
  71. error = err;
  72. }
  73. }
  74. if (error) throw error;
  75. }
  76. main().then(
  77. () => {
  78. notifyReleaseStatus({
  79. title: `AMO Release Success: ${process.env.RELEASE_NAME}`,
  80. description: `See the changelog at https://github.com/violentmonkey/violentmonkey/releases/tag/v${process.env.VERSION}.`,
  81. });
  82. },
  83. (err) => {
  84. // if (err instanceof FatalError) {
  85. notifyReleaseStatus({
  86. title: `AMO Release Failure: ${process.env.RELEASE_NAME}`,
  87. description: [
  88. 'An error occurred:',
  89. '',
  90. `> ${err}`,
  91. ...(process.env.ACTION_BUILD_URL
  92. ? ['', `See ${process.env.ACTION_BUILD_URL} for more details.`]
  93. : []),
  94. ].join('\n'),
  95. success: false,
  96. });
  97. // }
  98. console.error(err);
  99. process.exitCode = 1;
  100. },
  101. );