<commit_before>name: "Stats"

on:
  push:
    branches:
    - develop
    - ci
    - next
  pull_request:
    types: [synchronize, opened]

jobs:

  stats:
    runs-on: ubuntu-latest

    env:
      CI_BRANCH_BASE: develop

    steps:
      - uses: actions/checkout@v2

      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '12.x'

      - name: Cache Node.js modules
        uses: actions/cache@v2
        with:
          path: |
            **/node_modules
          key: ${{ runner.OS }}-node-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.OS }}-node-
            ${{ runner.OS }}-

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Angular bundlewatch
        uses: jackyef/bundlewatch-gh-action@master
        with:
          build-script: npm run build -- --analyze-bundle
          branch-base: develop
          bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}

      - name: PeerTube client stats
        if: github.event_name != 'pull_request'
        run: |
          node dist/scripts/client-build-stats.js > client-build-stats.json

      - name: PeerTube code stats
        if: github.event_name != 'pull_request'
        run: |
          wget "https://github.com/boyter/scc/releases/download/v3.0.0/scc-3.0.0-x86_64-unknown-linux.zip"
          unzip "scc-3.0.0-x86_64-unknown-linux.zip"
          ./scc --format=json --exclude-dir .git,node_modules,client/node_modules,client/dist,dist,yarn.lock,client/yarn.lock,client/src/locale,test1,test2,test3,client/src/assets/images,config,storage,server/tests/fixtures,support/openapi,.idea,.vscode,docker-volume,ffmpeg-3,ffmpeg-4 > ./scc.json

      - name: Display stats
        if: github.event_name != 'pull_request'
        run: |
          cat client-build-stats.json
          cat scc.json

      - name: Upload stats
        if: github.event_name != 'pull_request'
        env:
          STATS_DEPLOYEMENT_KNOWN_HOSTS: ${{ secrets.STATS_DEPLOYEMENT_KNOWN_HOSTS }}
          STATS_DEPLOYEMENT_KEY: ${{ secrets.STATS_DEPLOYEMENT_KEY }}
          STATS_DEPLOYEMENT_USER: ${{ secrets.STATS_DEPLOYEMENT_USER }}
          STATS_DEPLOYEMENT_HOST: ${{ secrets.STATS_DEPLOYEMENT_HOST }}
        run: |
          mkdir -p ~/.ssh
          chmod 700  ~/.ssh
          if [ ! -z ${STATS_DEPLOYEMENT_KNOWN_HOSTS+x} ]; then
            echo "Adding ssh key to known hosts"
            echo -e "${STATS_DEPLOYEMENT_KNOWN_HOSTS}" > ~/.ssh/known_hosts;
          fi

          eval `ssh-agent -s`

          if [ ! -z ${STATS_DEPLOYEMENT_KEY+x} ]; then
            echo "Adding ssh reployement key"
            ssh-add <(echo "${STATS_DEPLOYEMENT_KEY}");
          fi

          if [ ! -z ${STATS_DEPLOYEMENT_KEY+x} ]; then
            echo "Uploading files"
            scp client-build-stats.json scc.json ${STATS_DEPLOYEMENT_USER}@${STATS_DEPLOYEMENT_HOST}:../../web/peertube-stats;
          fi<commit_msg>Add lighthouse to github action<commit_after>name: "Stats"

on:
  push:
    branches:
    - develop
    - ci
    - next
  pull_request:
    types: [synchronize, opened]

jobs:

  stats:
    runs-on: ubuntu-latest

    env:
      CI_BRANCH_BASE: develop

    steps:
      - uses: actions/checkout@v2

      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '12.x'

      - name: Cache Node.js modules
        uses: actions/cache@v2
        with:
          path: |
            **/node_modules
          key: ${{ runner.OS }}-node-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.OS }}-node-
            ${{ runner.OS }}-

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Angular bundlewatch
        uses: jackyef/bundlewatch-gh-action@master
        with:
          build-script: npm run build -- --analyze-bundle
          branch-base: develop
          bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}

      - name: PeerTube code stats
        if: github.event_name != 'pull_request'
        run: |
          wget "https://github.com/boyter/scc/releases/download/v3.0.0/scc-3.0.0-x86_64-unknown-linux.zip"
          unzip "scc-3.0.0-x86_64-unknown-linux.zip"
          ./scc --format=json --exclude-dir .git,node_modules,client/node_modules,client/dist,dist,yarn.lock,client/yarn.lock,client/src/locale,test1,test2,test3,client/src/assets/images,config,storage,server/tests/fixtures,support/openapi,.idea,.vscode,docker-volume,ffmpeg-3,ffmpeg-4 > ./scc.json

      - name: PeerTube client stats
        if: github.event_name != 'pull_request'
        run: |
          node dist/scripts/client-build-stats.js > client-build-stats.json

      - name: PeerTube client lighthouse report
        if: github.event_name != 'pull_request'
        run: |
          sudo apt-get install chromium-browser
          sudo npm install -g lighthouse
          lighthouse --chrome-flags="--headless" https://peertube2.cpy.re --output=json --output-path=./lighthouse.json

      - name: Display stats
        if: github.event_name != 'pull_request'
        run: |
          cat client-build-stats.json
          cat scc.json
          cat lighthouse.json

      - name: Upload stats
        if: github.event_name != 'pull_request'
        env:
          STATS_DEPLOYEMENT_KNOWN_HOSTS: ${{ secrets.STATS_DEPLOYEMENT_KNOWN_HOSTS }}
          STATS_DEPLOYEMENT_KEY: ${{ secrets.STATS_DEPLOYEMENT_KEY }}
          STATS_DEPLOYEMENT_USER: ${{ secrets.STATS_DEPLOYEMENT_USER }}
          STATS_DEPLOYEMENT_HOST: ${{ secrets.STATS_DEPLOYEMENT_HOST }}
        run: |
          mkdir -p ~/.ssh
          chmod 700  ~/.ssh
          if [ ! -z ${STATS_DEPLOYEMENT_KNOWN_HOSTS+x} ]; then
            echo "Adding ssh key to known hosts"
            echo -e "${STATS_DEPLOYEMENT_KNOWN_HOSTS}" > ~/.ssh/known_hosts;
          fi

          eval `ssh-agent -s`

          if [ ! -z ${STATS_DEPLOYEMENT_KEY+x} ]; then
            echo "Adding ssh reployement key"
            ssh-add <(echo "${STATS_DEPLOYEMENT_KEY}");
          fi

          if [ ! -z ${STATS_DEPLOYEMENT_KEY+x} ]; then
            echo "Uploading files"
            scp lighthouse.json client-build-stats.json scc.json ${STATS_DEPLOYEMENT_USER}@${STATS_DEPLOYEMENT_HOST}:../../web/peertube-stats;
          fi
{'fraction_non_alphanumeric': 0.12368874275872867, 'fraction_numerical': 0.009550649757319556, 'mean_word_length': 2.0549976087996176, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2237349', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2097, 'n_words': 377}