name: Cider Chores

on:
  push:
    branches:
      - main

jobs:
  update-lockfile:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18]

    permissions:
      contents: write

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          # Make sure the actual branch is checked out when running on pull requests
          ref: ${{ github.head_ref }}

      - uses: pnpm/action-setup@v2.2.2
        with:
          version: 7

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v2
        with:
          node-version: ${{ matrix.node-version }}
          cache: "pnpm"

      - name: Update lockfile
        run: pnpm i --lockfile-only

      - name: Commit Updated Lockfile
        uses: stefanzweifel/git-auto-commit-action@v4.14.1
        with:
          commit_message: "chore: Updated Lockfile"
          commit_user_name: "cider-chore[bot]"
          commit_user_email: "cider-chore[bot]@users.noreply.github.com"

  prettier:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18]

    permissions:
      contents: write

    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          # Make sure the actual branch is checked out when running on pull requests
          ref: ${{ github.head_ref }}

      - name: Prettify code
        run: npm run format:write

      - name: Commit Prettier Code
        uses: stefanzweifel/git-auto-commit-action@v4.14.1
        with:
          commit_message: "chore: Prettified Code\n [ci skip]"
          commit_user_name: "cider-chore[bot]"
          commit_user_email: "cider-chore[bot]@users.noreply.github.com"

  synchronize-with-crowdin:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: crowdin action
        uses: crowdin/github-action@1.4.13
        with:
          upload_translations: true
          download_translations: false
          project_id: ${{ secrets.CROWDIN_PROJECT_ID }}
          token: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
          source: '/src/i18n/source/**.*'
          translation: '/src/i18n/%locale_with_underscore%.json'
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
          CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
          CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
