# This defines the name of the workflow as it will appear in the "Actions" tab of the Gitea repository.
name: Production deployment

on:
  push:
    tags:
      - 'v*'

env:
  IMAGE_NAME: "jdrbot"
  DEPLOYMENT_NAME: "jdrbot"

jobs:
  build-docker:
    name: Building and pushing
    runs-on: skydust-runner
    timeout-minutes: 30
    steps:
      - name: Check out repo's default branch
        uses: actions/checkout@v4
      - name: Getting version
        uses: https://gitea.skydust.fr/actions/get-version@main
      - name: Update java package version
        run: |
          log_info "Updating gradle.properties version to $(yellow)$NEW_VERSION"
          sed -Ei "s|^(version=).*|\1${NEW_VERSION}|" gradle.properties
          cat gradle.properties
      - name: Docker login
        uses: https://gitea.skydust.fr/actions/docker-login-skydust@main
        with:
          user: ${{ gitea.repository_owner }}
          pass: ${{ secrets.DOCKER_WRITEABLE_TOKEN }}
      - name: Build and push
        uses: https://gitea.skydust.fr/actions/docker-build-skydust@main
        with:
          imageName: "${{ env.IMAGE_NAME }}:latest"
          push: true
          pullCache: true
      - name: Container scanning
        uses: https://gitea.skydust.fr/actions/grype-container-scanning@main
        with:
          imageName: "${{ env.IMAGE_NAME }}:latest"
      - name: Restarting deployment
        uses: https://gitea.skydust.fr/actions/restart-kube-app@main
        with:
          deploymentName: "${{ env.DEPLOYMENT_NAME }}"
