name: Reusable - Examples

on:
  workflow_call:
    inputs:
      cache-read-only:
        type: boolean
        required: false
      no-build-cache:
        type: boolean
        required: false

jobs:
  examples:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up JDK for running Gradle
        uses: actions/setup-java@v3
        with:
          distribution: temurin
          java-version: 17

      - name: Set up Gradle cache
        uses: gradle/gradle-build-action@v2
        with:
          cache-read-only: ${{ inputs.cache-read-only }}

      - name: Local publish of artifacts
        # javadoc task fails sporadically fetching https://docs.oracle.com/javase/8/docs/api/
        run: ./gradlew publishToMavenLocal -x javadoc

      - name: Local publish of gradle plugins
        # javadoc task fails sporadically fetching https://docs.oracle.com/javase/8/docs/api/
        run: ./gradlew publishToMavenLocal -x javadoc
        working-directory: gradle-plugins

      - name: Build distro
        run: ./gradlew build --init-script ../../.github/scripts/local.init.gradle.kts${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
        working-directory: examples/distro

      - name: Build extension
        run: ./gradlew build --init-script ../../.github/scripts/local.init.gradle.kts${{ inputs.no-build-cache && ' --no-build-cache' || '' }}
        working-directory: examples/extension

      - name: Run muzzle check against extension
        run: ./gradlew muzzle --init-script ../../.github/scripts/local.init.gradle.kts
        working-directory: examples/extension
