name: early-access

on:
  workflow_dispatch:
    inputs:
      currentDevelopmentVersion:
        description: 'The current development version'
        required: true

jobs:
  pre-release-build-linux:
    name: Build Pre-release Artifacts (Linux)
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout Wanaku Capabilities SDK Main Project
        uses: actions/checkout@v6
        with:
          repository: wanaku-ai/wanaku-capabilities-java-sdk
          persist-credentials: false
          ref: main
          path: wanaku-capabilities-java-sdk
      - name: Set up JDK 21
        uses: actions/setup-java@v5
        with:
          java-version: '21'
          distribution: 'temurin'
          cache: maven
      - name: Build Wanaku Capabilities SDK Main Project
        run: mvn --no-transfer-progress -DskipTests clean install
        working-directory: ${{ github.workspace }}/wanaku-capabilities-java-sdk
      - name: Checkout
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - uses: graalvm/setup-graalvm@v1.3.4
        with:
          java-version: '21'
          distribution: 'graalvm'
          github-token: ${{ secrets.GITHUB_TOKEN }}
          native-image-job-reports: 'true'
          cache: maven

      - name: Login to Container Registry
        uses: docker/login-action@v3
        with:
          registry: quay.io
          username: ${{ secrets.QUAY_USERNAME }}
          password: ${{ secrets.QUAY_PASSWORD }}

      - name: Create a snapshot build (with container push)
        run: |
          mvn --no-transfer-progress -Dnative -Pdist \
          -Dquarkus.container-image.build=true \
          -Dquarkus.container-image.push=true \
          -Dquarkus.container-image.additional-tags=${{ github.event.inputs.currentDevelopmentVersion }} \
          clean package

      - name: Run JReleaser (Linux)
        uses: jreleaser/release-action@v2
        env:
          JRELEASER_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          JRELEASER_PROJECT_VERSION: ${{ github.event.inputs.currentDevelopmentVersion }}
          JRELEASER_PROJECT_SNAPSHOT_LABEL: early-access
          JRELEASER_SELECT_CURRENT_PLATFORM: true
          JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
          JRELEASER_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
          JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_PRIVATE_KEY }}

      # Persist logs

      - name: JReleaser release output
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: jreleaser-release-linux
          path: |
            out/jreleaser/trace.log
            out/jreleaser/output.properties