name: deploy to production

on: "push"

jobs:
    deploy:
        name: deploy
        runs-on: ubuntu-latest
        container:
            image: gitbase.de/actions/ubuntu:latest
            volumes:
                - /data:/data
        steps:
            - uses: actions/checkout@v4
              with:
                  fetch-depth: 0
                  lfs: true
                  submodules: true

            - run: |
                  git fetch --force --tags

            - name: setup node
              uses: actions/setup-node@v4
              with:
                  node-version: 22

            - name: install dependencies
              run: |
                  npm install -g yarn
                  yarn install

            - name: validate
              run: |
                  yarn validate

            - name: modify config
              run: ./scripts/ci-modify-config.sh

            - name: build
              env:
                  FORCE_COLOR: "true"
              run: |
                  yarn build

            - name: build ssr
              env:
                  FORCE_COLOR: "true"
              run: |
                  yarn build:server

            - name: upload sourcemaps to sentry
              env:
                  SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
              run: ./scripts/ci-upload-sourcemaps.sh

            - name: staging
              if: github.ref == 'refs/heads/dev'
              env:
                  API_BASEDIR: /data/${{ github.repository }}/${{ github.ref_name }}
                  COMPOSE_PROJECT_NAME: ${{ github.repository }}-${{ github.ref_name }}
              run: ./scripts/ci-staging.sh

            - name: deploy
              if: github.ref == 'refs/heads/master'
              env:
                  RSYNC_USER: ${{ github.repository }}
                  RSYNC_PASS: ${{ github.token }}
                  BRANCH: ${{ github.ref_name }}
              run: ./scripts/ci-deploy.sh
