name: 'Post release'
on:
  workflow_dispatch:
    inputs:
      version:
        description: 'Version'
        required: true
        default: 'latest'
  workflow_run:
    workflows: [ "Release" ]
    types:
      - completed
  push:
    paths:
      - '.github/workflows/post-release.yml'
    branches:
      - 'master'

env:
  VERSION: ${{ github.event.inputs.version || 'latest' }}

# touch to trigger
jobs:
  cli:
    runs-on: ubuntu-24.04
    name: 'E2E tests via CLI'
    timeout-minutes: 60
    strategy:
      fail-fast: false
      matrix:
        node-version: [24.x]
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: 1.90.0
          # override: true # this is by default on
          rustflags: ""
          components: rustfmt
          target: x86_64-unknown-linux-gnu
          cache: false
      - name: Install Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
      - name: Restore lerna
        uses: actions/cache@v4
        with:
          # npm cache files are stored in `~/.npm` on Linux/macOS
          path: |
            ~/.npm
            node_modules
            rust/cubestore/node_modules
            packages/*/node_modules
          key: ${{ runner.os }}-workspace-main-20.x-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-workspace-main-20.x-
      - name: Set Yarn version
        run: yarn policies set-version v1.22.22
      - name: Yarn install
        uses: nick-fields/retry@v3
        env:
          CUBESTORE_SKIP_POST_INSTALL: true
        with:
          max_attempts: 3
          retry_on: error
          retry_wait_seconds: 15
          timeout_minutes: 20
          command: yarn install --frozen-lockfile
      - name: Build client
        run: yarn build
      - name: Lerna tsc
        run: yarn tsc
      - name: Build cubejs-backend-native (without Python)
        run: yarn run native:build-release
        working-directory: ./packages/cubejs-backend-native
      - name: Birdbox
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
        run: |
          cd packages/cubejs-testing/
          npx cubejs-cli@"$VERSION" create birdbox-test-project -d postgres
          export BIRDBOX_CUBEJS_VERSION="$VERSION"
          yarn run dataset:minimal
          yarn run birdbox:cli:postgresql
      - name: Slack Failure
        if: failure()
        uses: voxmedia/github-action-slack-notify-build@v1
        with:
          channel: oss-ci
          status: FAILED
          color: danger
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

  docker:
    runs-on: ubuntu-24.04
    name: 'E2E tests via Docker'
    timeout-minutes: 60
    strategy:
      fail-fast: false
      matrix:
        target: ['postgresql', 'postgresql-cubestore', 'postgresql-pre-aggregations']
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Node.js 24.x
        uses: actions/setup-node@v4
        with:
          node-version: 24.x
      - name: Restore lerna
        uses: actions/cache@v4
        with:
          # npm cache files are stored in `~/.npm` on Linux/macOS
          path: |
            ~/.npm
            node_modules
            rust/cubestore/node_modules
            packages/*/node_modules
          key: ${{ runner.os }}-workspace-main-20.x-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-workspace-main-20.x-
      - name: Set Yarn version
        run: yarn policies set-version v1.22.22
      - name: Yarn install
        uses: nick-fields/retry@v3
        env:
          CUBESTORE_SKIP_POST_INSTALL: true
        with:
          max_attempts: 3
          retry_on: error
          retry_wait_seconds: 15
          timeout_minutes: 20
          command: yarn install --frozen-lockfile
      - name: Build client
        run: yarn build
      - name: Lerna tsc
        run: yarn tsc
      - name: Birdbox
        run: |
          cd packages/cubejs-testing/
          export DEBUG=testcontainers
          export BIRDBOX_CUBEJS_VERSION="$VERSION"
          yarn run dataset:minimal
          yarn run birdbox:${{ matrix.target }}
      - name: Slack Failure
        if: failure()
        uses: voxmedia/github-action-slack-notify-build@v1
        with:
          channel: oss-ci
          status: FAILED
          color: danger
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}

  cypress:
    runs-on: ${{ matrix.os }}
    name: 'Cypress E2E tests via Docker'
    timeout-minutes: 60
    strategy:
      fail-fast: false
      matrix:
        browser: [chrome]
        include:
          - browser: chrome
            os: ubuntu-24.04
            container: cypress/browsers:node18.12.0-chrome107
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Node.js 24.x
        uses: actions/setup-node@v4
        with:
          node-version: 24.x
      - name: Restore lerna
        uses: actions/cache@v4
        with:
          # npm cache files are stored in `~/.npm` on Linux/macOS
          path: |
            ~/.npm
            node_modules
            rust/cubestore/node_modules
            packages/*/node_modules
          key: ${{ runner.os }}-workspace-main-20.x-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-workspace-main-20.x-
      - name: Set Yarn version
        run: yarn policies set-version v1.22.22
      - name: Yarn install
        uses: nick-fields/retry@v3
        env:
          CUBESTORE_SKIP_POST_INSTALL: true
        with:
          max_attempts: 3
          retry_on: error
          retry_wait_seconds: 15
          timeout_minutes: 20
          command: yarn install --frozen-lockfile
      - name: Lerna tsc
        run: yarn tsc
      - name: Birdbox
        env:
          CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
        run: |
          cd packages/cubejs-testing/
          export DEBUG=testcontainers
          export BIRDBOX_CYPRESS_BROWSER=${{ matrix.browser }}
          export BIRDBOX_CUBEJS_VERSION="$VERSION"
          yarn run cypress:install
          yarn run dataset:minimal
          yarn run cypress:birdbox
      - name: Slack Failure
        if: failure()
        uses: voxmedia/github-action-slack-notify-build@v1
        with:
          channel: oss-ci
          status: FAILED
          color: danger
        env:
          SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
