ActivityWatch/aw-webui

View on GitHub
.github/workflows/nodejs.yml

Summary

Maintainability
Test Coverage
name: Build

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    name: Build (node-${{ matrix.node-version }})
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16]
        python-version: ['3.9']
        include:
        - node-version: '16'
          python-version: '3.9'

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: 'recursive'
    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
    - name: Install
      run: npm ci
    - name: Build
      run: npm run build
    - name: Upload build
      uses: actions/upload-artifact@v3.1.2
      with:
        name: build
        path: dist/*

  test:
    name: Test (node-${{ matrix.node-version }}, py-${{ matrix.python-version }}, ${{ matrix.aw-server }} ${{ matrix.aw-version }})
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        node-version: [16]
        python-version: ['3.9']
        aw-server: ["aw-server", "aw-server-rust"]
        aw-version: ["v0.12.3b11"]
        include:
        - node-version: '16'
          python-version: '3.9'
          aw-server: "aw-server-rust"
          aw-version: "master"

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: 'recursive'
    - name: Setup Node.js
      uses: actions/setup-node@v4
      with:
        node-version: ${{ matrix.node-version }}
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: ${{ matrix.python-version }}

    # TODO: Refactor out getting ActivityWatch builds (both release and nightly) into an action
    - name: Install and run ActivityWatch
      if: ${{ matrix.aw-version != 'master' }}
      run: |
        wget --no-verbose -O activitywatch.zip https://github.com/ActivityWatch/activitywatch/releases/download/${{ matrix.aw-version }}/activitywatch-${{ matrix.aw-version }}-linux-x86_64.zip
        unzip activitywatch.zip
        ./.github/configure_server.sh
        ./activitywatch/${{ matrix.aw-server }}/${{ matrix.aw-server }} --testing &

    - name: Download aw-server-rust nightly
      if: ${{ matrix.aw-server == 'aw-server-rust' && matrix.aw-version == 'master' }}
      uses: dawidd6/action-download-artifact@v3
      with:
        repo: ActivityWatch/aw-server-rust
        # Required, workflow file name or ID
        workflow: build.yml
        # Optional, the status or conclusion of a completed workflow to search for
        # Can be one of a workflow conclusion::
        # "failure", "success", "neutral", "cancelled", "skipped", "timed_out", "action_required"
        # Or a workflow status:
        # "completed", "in_progress", "queued"
        # Default: "completed,success"
        workflow_conclusion: "completed"  # FIXME: Don't try to use builds that fail on Linux
        branch: master
        event: push
        # Uploaded artifact name,
        name: binaries-Linux  # NOTE: debug build
        # Directory where to extract artifact
        path: aw-server-rust
        # Search for the last valid run with the desired artifact
        search_artifacts: true

    - name: Install and run aw-server-rust nightly
      if: ${{ matrix.aw-server == 'aw-server-rust' && matrix.aw-version == 'master' }}
      run: |
        chmod +x ./aw-server-rust/debug/aw-server
        LOG_LEVEL=debug ./aw-server-rust/debug/aw-server --testing &

    - name: Insert fake data into aw-server
      run: |
        pip install click git+https://github.com/ActivityWatch/aw-client.git
        wget --no-verbose -O fakedata.py https://raw.githubusercontent.com/ActivityWatch/aw-fakedata/master/aw_fakedata.py
        GITDATE=$(git show -s --format=%ci HEAD | sed -r 's/ .+//g')
        STARTDATE=$(date --date="${GITDATE} -30 day" +%Y-%m-%d)
        ENDDATE=$(date --date="${GITDATE} +1 day" +%Y-%m-%d)
        python3 fakedata.py --since $STARTDATE --until $ENDDATE

    - name: Install
      run: npm ci
    - name: Run tests
      run: |
        npm test
        bash <(curl -s https://codecov.io/bash)
    - name: Serve webui
      run: |
          npm run serve &
          sleep 3  # give a few seconds
    - name: Run e2e tests with testcafe
      id: e2e
      uses: DevExpress/testcafe-action@latest
      with:
        # NOTE: --skip-js-errors should be removed when things work properly
        args: "--skip-js-errors chrome test/e2e/"
    - name: Move screenshots to subdir
      # Run this step even if e2e tests flag failure
      if: ${{ success() || steps.e2e.conclusion == 'failure'}}
      env:
        aw_server: ${{ matrix.aw-server }}
        aw_version: ${{ matrix.aw-version }}
      run: |
        mkdir -p screenshots/dist/$aw_server/$aw_version
        mv screenshots/*.png screenshots/dist/$aw_server/$aw_version
    - name: Upload screenshots
      if: ${{ success() || steps.e2e.conclusion == 'failure'}}
      uses: actions/upload-artifact@v3.1.2
      with:
        name: screenshots
        path: screenshots/dist/*
    - name: Print server logs to console
      if: ${{ always() }}
      shell: bash
      run:
        for file in ~/.cache/activitywatch/log/*/*.log; do echo $file; cat $file; echo; done
    - name: Move logs to subdir
      # Run this step even if e2e tests flag failure
      if: ${{ always() }}
      env:
        aw_server: ${{ matrix.aw-server }}
        aw_version: ${{ matrix.aw-version }}
      run: |
        mkdir -p logs/dist/$aw_server/$aw_version
        mv ~/.cache/activitywatch/log/*/*.log logs/dist/$aw_server/$aw_version
    - name: Upload logs
      if: ${{ always() }}
      uses: actions/upload-artifact@v3.1.2
      with:
        name: logs
        path: logs/dist/*