name: 'Setup build environment'
description: 'Install Joplin build dependencies'
runs:
  using: 'composite'
  steps:
    # Trying to fix random networking issues on Windows
    # https://github.com/actions/runner-images/issues/1187#issuecomment-686735760
    # - name: Disable TCP/UDP offload on Windows
    #   if: runner.os == 'Windows'
    #   shell: pwsh
    #   run: Disable-NetAdapterChecksumOffload -Name * -TcpIPv4 -UdpIPv4 -TcpIPv6 -UdpIPv6

    - name: Disable TCP/UDP offload on Linux
      if: runner.os == 'Linux'
      shell: bash
      run: sudo ethtool -K eth0 tx off rx off

    - name: Disable TCP/UDP offload on macOS
      if: runner.os == 'macOS'
      shell: bash
      run: |
        sudo sysctl -w net.link.generic.system.hwcksum_tx=0
        sudo sysctl -w net.link.generic.system.hwcksum_rx=0

    # Silence apt-get update errors (for example when a module doesn't
    # exist) since otherwise it will make the whole build fails, even though
    # it might work without update. libsecret-1-dev is required for keytar -
    # https://github.com/atom/node-keytar

    - name: Install Linux dependencies
      if: runner.os == 'Linux'
      shell: bash
      run: |
        sudo apt-get update || true
        sudo apt-get install -y gettext
        sudo apt-get install -y libsecret-1-dev
        sudo apt-get install -y translate-toolkit
        sudo apt-get install -y rsync
        # Provides a virtual display on Linux. Used for Playwright integration
        # testing.
        sudo apt-get install -y xvfb

    - name: Install macOs dependencies
      if: runner.os == 'macOS'
      shell: bash
      run: |
        # Required for building the canvas package
        brew install pango

    - uses: olegtarasov/get-tag@v2.1.4
    - uses: dtolnay/rust-toolchain@stable
      if: ${{ runner.os != 'Windows' }}

    - uses: actions/setup-node@v6
      with:
        node-version: '24'
        # Disable the cache on ARM runners. For now, we don't run "yarn install" on these
        # environments and this breaks actions/setup-node.
        # See https://github.com/laurent22/joplin/commit/47d0d3eb9e89153a609fb5441344da10904c6308#commitcomment-159577783.
        # cache: ${{ (!contains(runner.os, 'arm') && 'yarn') || '' }}

    - name: Install Yarn
      shell: bash
      run: |
        # https://yarnpkg.com/getting-started/install
        corepack enable

    # macos-latest ships with Python 3.12 by default, but this removes a
    # utility that's used by electron-builder (distutils) so we need to pin
    # Python to an earlier version.
    # Fixes error `ModuleNotFoundError: No module named 'distutils'`
    # Ref: https://github.com/nodejs/node-gyp/issues/2869
    - uses: actions/setup-python@v5
      with:
        python-version: '3.14'
