azput.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* eslint-disable camelcase */
  2. const { BlobServiceClient } = require('@azure/storage-blob');
  3. const fs = require('fs');
  4. const path = require('path');
  5. const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.ELECTRON_ARTIFACTS_BLOB_STORAGE);
  6. const args = require('minimist')(process.argv.slice(2));
  7. let { prefix = '/', key_prefix = '', _: files } = args;
  8. if (prefix && !prefix.endsWith(path.sep)) prefix = path.resolve(prefix) + path.sep;
  9. function filenameToKey (file) {
  10. file = path.resolve(file);
  11. if (file.startsWith(prefix)) file = file.substr(prefix.length - 1);
  12. return key_prefix + (path.sep === '\\' ? file.replace(/\\/g, '/') : file);
  13. }
  14. let anErrorOccurred = false;
  15. function next (done) {
  16. const file = files.shift();
  17. if (!file) return done();
  18. let key = filenameToKey(file);
  19. // TODO: When we drop s3put, migrate the key to not include atom-shell in the callsites
  20. key = key.replace('atom-shell/dist/', 'headers/dist/');
  21. key = key.replace('atom-shell/symbols/', 'symbols/');
  22. key = key.replace('atom-shell/tmp/', 'checksums-scratchpad/');
  23. key = key.replace('electron-artifacts/', 'release-builds/');
  24. const [containerName, ...keyPath] = key.split('/');
  25. const blobKey = keyPath.join('/');
  26. console.log(`Uploading '${file}' to container '${containerName}' with key '${blobKey}'...`);
  27. const containerClient = blobServiceClient.getContainerClient(containerName);
  28. const blockBlobClient = containerClient.getBlockBlobClient(blobKey);
  29. blockBlobClient.uploadFile(file)
  30. .then((uploadBlobResponse) => {
  31. console.log(`Upload block blob ${blobKey} successfully: https://artifacts.electronjs.org/${key}`, uploadBlobResponse.requestId);
  32. })
  33. .catch((err) => {
  34. console.error(err);
  35. anErrorOccurred = true;
  36. })
  37. .then(() => next(done));
  38. }
  39. next(() => {
  40. process.exit(anErrorOccurred ? 1 : 0);
  41. });