name: Openfire Mac Release Artifact

on:
  release:
    types: [created]

jobs:
  build:

    name: Build Openfire from source
    runs-on: macos-latest
    strategy:
      matrix:
        java: [ 17 ]

    steps:
      - uses: actions/checkout@v4
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v4
        with:
          java-version: ${{ matrix.java }}
          distribution: zulu
          cache: maven
      - name: Compute Version
        id: get-id
        run: |
          set -x
          version=$(echo ${{ github.ref }} | cut -d '/' -f3 | cut -c 2- | sed 's/\./_/g')
          echo "version=$version" >> $GITHUB_OUTPUT
          echo "version is '$version'"

      - name: Get release
        id: get_release
        uses: bruceadams/get-release@v1.3.2
        env:
          GITHUB_TOKEN: ${{ github.token }}

      - name: Build with Maven
        run: ./mvnw -B package -Pcoverage --file pom.xml

      - name: Build Artifact
        run: |
          bash build/osx/build_dmg.sh

      - name: Push Artifact to Github Release
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ steps.get_release.outputs.upload_url }}
          asset_path: distribution/build/osx/Openfire.dmg
          asset_name: openfire_${{ steps.get-id.outputs.version }}.dmg
          asset_content_type: application/octet-stream

