name: Setup
description: Setup the environment for the project

inputs:
  working-directory:
    description: 'Working directory to run in, default .'
    required: false
    default: '.'
  download-translations:
    description: 'Whether to download translations as part of setup, default true'
    required: false
    default: 'true'

runs:
  using: composite
  steps:
    - name: Install node
      uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
      with:
        node-version: 22
    - name: Install yarn
      run: npm install -g yarn
      shell: bash
      if: ${{ env.ACT }}
    - name: Get Node version
      id: get-node
      run: echo "version=$(node -v)" >> "$GITHUB_OUTPUT"
      shell: bash
    - name: Cache
      uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
      id: cache
      with:
        path: ${{ format('{0}/**/node_modules', inputs.working-directory) }}
        key: yarn-v1-${{ runner.os }}-${{ steps.get-node.outputs.version }}-${{ hashFiles(format('{0}/**/yarn.lock', inputs.working-directory)) }}
    - name: Ensure Lage cache directory exists
      run: mkdir -p ${{ format('{0}/.lage', inputs.working-directory) }}
      shell: bash
    - name: Cache Lage
      uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
      with:
        path: ${{ format('{0}/.lage', inputs.working-directory) }}
        key: lage-${{ runner.os }}-${{ github.sha }}
        restore-keys: |
          lage-${{ runner.os }}-
    - name: Install
      working-directory: ${{ inputs.working-directory }}
      run: yarn --immutable
      shell: bash
      if: steps.cache.outputs.cache-hit != 'true'
    - name: Download translations
      uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
      with:
        repository: actualbudget/translations
        path: ${{ inputs.working-directory }}/packages/desktop-client/locale
      if: ${{ inputs.download-translations == 'true' }}
    - name: Remove untranslated languages
      run: packages/desktop-client/bin/remove-untranslated-languages
      shell: bash
      if: ${{ inputs.download-translations == 'true' }}
