name: CI
on:
  push:
    tags:
      - '*'
jobs:
  build:
    runs-on: woryzen
    steps:
      - name: Checkout sources
        uses: actions/checkout@v4
      - name: Execute Gradle build
        run: ./gradlew build
      - name: Prepare Docker image build
        run: ./gradlew prepareDockerBuild
      - name: Get project version
        id: retrieve-version
        run: ./gradlew -q version >> "$GITHUB_OUTPUT"
      - name: Login to Gitea container registry
        uses: docker/login-action@v3
        with:
          registry: gitea.woggioni.net
          username: woggioni
          password: ${{ secrets.PUBLISHER_TOKEN }}
      -
        name: Build rbcs Docker image
        uses: docker/build-push-action@v5.3.0
        with:
          builder: "multiplatform-builder"
          context: "docker/build/docker"
          platforms: linux/amd64,linux/arm64
          push: true
          pull: true
          tags: |
            gitea.woggioni.net/woggioni/rbcs:latest
            gitea.woggioni.net/woggioni/rbcs:${{ steps.retrieve-version.outputs.VERSION }}
          target: release-vanilla
      -
        name: Build rbcs memcache Docker image
        uses: docker/build-push-action@v5.3.0
        with:
          builder: "multiplatform-builder"
          context: "docker/build/docker"
          platforms: linux/amd64,linux/arm64
          push: true
          pull: true
          tags: |
            gitea.woggioni.net/woggioni/rbcs:memcache
            gitea.woggioni.net/woggioni/rbcs:${{ steps.retrieve-version.outputs.VERSION }}-memcache
          target: release-memcache
      -
        name: Build rbcs redis Docker image
        uses: docker/build-push-action@v5.3.0
        with:
          builder: "multiplatform-builder"
          context: "docker/build/docker"
          platforms: linux/amd64,linux/arm64
          push: true
          pull: true
          tags: |
            gitea.woggioni.net/woggioni/rbcs:redis
            gitea.woggioni.net/woggioni/rbcs:${{ steps.retrieve-version.outputs.VERSION }}-redis
          target: release-redis
      -
        name: Build rbcs full Docker image
        uses: docker/build-push-action@v5.3.0
        with:
          builder: "multiplatform-builder"
          context: "docker/build/docker"
          platforms: linux/amd64,linux/arm64
          push: true
          pull: true
          tags: |
            gitea.woggioni.net/woggioni/rbcs:full
            gitea.woggioni.net/woggioni/rbcs:${{ steps.retrieve-version.outputs.VERSION }}-full
          target: release-full
      -
        name: Build rbcs native Docker image
        uses: docker/build-push-action@v5.3.0
        with:
          builder: "multiplatform-builder"
          context: "docker/build/docker"
          platforms: linux/amd64
          push: true
          pull: true
          tags: |
            gitea.woggioni.net/woggioni/rbcs:native
            gitea.woggioni.net/woggioni/rbcs:${{ steps.retrieve-version.outputs.VERSION }}-native
          target: release-native
      -
        name: Build rbcs jlink Docker image
        uses: docker/build-push-action@v5.3.0
        with:
          builder: "multiplatform-builder"
          context: "docker/build/docker"
          platforms: linux/amd64
          push: true
          pull: true
          tags: |
            gitea.woggioni.net/woggioni/rbcs:jlink
            gitea.woggioni.net/woggioni/rbcs:${{ steps.retrieve-version.outputs.VERSION }}-jlink
          target: release-jlink
      - name: Publish artifacts
        env:
          PUBLISHER_TOKEN: ${{ secrets.PUBLISHER_TOKEN }}
        run: ./gradlew publish

