name: linea-sequencer-plugin-testing

permissions:
  contents: read
  actions: read

on:
  workflow_call:

concurrency:
  group: linea-sequencer-plugin-testing-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
  run-linea-sequencer-plugins-unit-tests:
    name: "Linea Sequencer Plugin Unit Tests"
    runs-on: gha-runner-scale-set-ubuntu-22.04-amd64-small
    steps:
      - uses: actions/checkout@v4
      - uses: gradle/actions/wrapper-validation@v4

      - name: Set up Java
        uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b #v4.5.0
        with:
          distribution: temurin
          java-version: 21
      - name: spotless
        run: ./gradlew --no-daemon --parallel clean besu-plugins:linea-sequencer:spotlessCheck

      - name: Build
        run: ./gradlew besu-plugins:linea-sequencer:build
        env:
          JAVA_OPTS: -Xmx2g -Dorg.gradle.daemon=false

      - name: Upload distribution artifacts
        uses: actions/upload-artifact@v4
        with:
          name: distributions
          path: besu-plugins/linea-sequencer/sequencer/build/libs

      - name: Run unit tests
        run: ./gradlew besu-plugins:linea-sequencer:sequencer:test
        env:
          JAVA_OPTS: -Dorg.gradle.daemon=false
      - name: Upload test report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: unit-test-report
          path: besu-plugins/linea-sequencer/sequencer/build/reports/tests/test/

  run-linea-sequencer-plugins-acceptance-tests:
    name: "Linea Sequencer Plugin Acceptance Tests"
    runs-on: gha-runner-scale-set-ubuntu-22.04-amd64-large
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up JDK 21
        uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b #v4.5.0
        with:
          java-version: 21
          distribution: temurin

      - name: Run acceptance tests
        run: ./gradlew besu-plugins:linea-sequencer:acceptance-tests:acceptanceTests
        env:
          JAVA_OPTS: -Dorg.gradle.daemon=false

      - name: Upload test report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: acceptance-test-report
          path: besu-plugins/linea-sequencer/acceptance-tests/build/reports/tests/
