<commit_before>// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import { join, resolve } from 'path';
import { readdir as readdirCallback } from 'fs';

import pify from 'pify';

import { notarize } from 'electron-notarize';

import * as packageJson from '../../package.json';

const readdir = pify(readdirCallback);

/* eslint-disable no-console */

go().catch(error => {
  console.error(error.stack);

  process.exit(1);
});

async function go() {
  if (process.platform !== 'darwin') {
    console.log('notarize: Skipping, not on macOS');

    return;
  }

  const appPaths = await findDMGs();
  const appBundleId = packageJson.build.appId;
  if (!appBundleId) {
    throw new Error(
      'appBundleId must be provided in package.json: build.appId'
    );
  }

  const appleId = process.env.APPLE_USERNAME;
  if (!appleId) {
    throw new Error(
      'appleId must be provided in environment variable APPLE_USERNAME'
    );
  }

  const appleIdPassword = process.env.APPLE_PASSWORD;
  if (!appleIdPassword) {
    throw new Error(
      'appleIdPassword must be provided in environment variable APPLE_PASSWORD'
    );
  }

  console.log('Notarizing with...');
  console.log(`  files: ${appPaths.join(', ')}`);
  console.log(`  primaryBundleId: ${appBundleId}`);
  console.log(`  username: ${appleId}`);

  await Promise.all(
    appPaths.map(async appPath => {
      return notarize({
        appBundleId,
        appPath,
        appleId,
        appleIdPassword,
      });
    })
  );
}

const IS_DMG = /\.dmg$/;
async function findDMGs(): Promise<Array<string>> {
  const releaseDir = resolve('release');
  const files: Array<string> = await readdir(releaseDir);

  const max = files.length;
  const results = new Array<string>();
  for (let i = 0; i < max; i += 1) {
    const file = files[i];
    const fullPath = join(releaseDir, file);

    if (IS_DMG.test(file)) {
      results.push(fullPath);
    }
  }

  if (results.length === 0) {
    throw new Error("No suitable files found in 'release' folder!");
  }

  return results;
}
<commit_msg>Don't notarize releases in parallel<commit_after>// Copyright 2019-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import { join, resolve } from 'path';
import { readdir as readdirCallback } from 'fs';

import pify from 'pify';

import { notarize } from 'electron-notarize';

import * as packageJson from '../../package.json';

const readdir = pify(readdirCallback);

/* eslint-disable no-console */

go().catch(error => {
  console.error(error.stack);

  process.exit(1);
});

async function go() {
  if (process.platform !== 'darwin') {
    console.log('notarize: Skipping, not on macOS');

    return;
  }

  const appPaths = await findDMGs();
  const appBundleId = packageJson.build.appId;
  if (!appBundleId) {
    throw new Error(
      'appBundleId must be provided in package.json: build.appId'
    );
  }

  const appleId = process.env.APPLE_USERNAME;
  if (!appleId) {
    throw new Error(
      'appleId must be provided in environment variable APPLE_USERNAME'
    );
  }

  const appleIdPassword = process.env.APPLE_PASSWORD;
  if (!appleIdPassword) {
    throw new Error(
      'appleIdPassword must be provided in environment variable APPLE_PASSWORD'
    );
  }

  console.log('Notarizing with...');
  console.log(`  files: ${appPaths.join(', ')}`);
  console.log(`  primaryBundleId: ${appBundleId}`);
  console.log(`  username: ${appleId}`);

  for (const appPath of appPaths) {
    // eslint-disable-next-line no-await-in-loop
    await notarize({
      appBundleId,
      appPath,
      appleId,
      appleIdPassword,
    });
  }
}

const IS_DMG = /\.dmg$/;
async function findDMGs(): Promise<Array<string>> {
  const releaseDir = resolve('release');
  const files: Array<string> = await readdir(releaseDir);

  const max = files.length;
  const results = new Array<string>();
  for (let i = 0; i < max; i += 1) {
    const file = files[i];
    const fullPath = join(releaseDir, file);

    if (IS_DMG.test(file)) {
      results.push(fullPath);
    }
  }

  if (results.length === 0) {
    throw new Error("No suitable files found in 'release' folder!");
  }

  return results;
}

{'fraction_non_alphanumeric': 0.14146688820318062, 'fraction_numerical': 0.006646095418941372, 'mean_word_length': 3.243705941591138, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6160773', 'n_tokens_mistral': 1433, 'n_tokens_neox': 1374, 'n_words': 363}