---
name: CI
on: [ workflow_dispatch, push, pull_request ]
jobs:
  omnilint:
    uses: lpenz/omnilint/.github/workflows/omnilint.yml@v0.5.2
  rust:
    uses: lpenz/ghworkflow-rust/.github/workflows/rust.yml@v0.23.4
    with:
      dependencies_debian: git
      coveralls: true
      publish_cratesio: false
      publish_github_release: false
    secrets:
      CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  docker-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4.2.2
      - uses: docker/build-push-action@v6.12.0
        with:
          push: false
  publish-cratesio:
    needs: [ omnilint, rust, docker-build ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4.2.2
      - id: version
        uses: ./
      - uses: actions-rs/toolchain@v1.0.7
        with:
          toolchain: stable
          override: true
      - name: publish crate on crates.io
        uses: katyo/publish-crates@v2
        if: steps.version.outputs.version_tagged != ''
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        with:
          registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
  publish-dockerhub:
    needs: [ omnilint, rust, docker-build ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4.2.2
      - id: version
        uses: ./
      - uses: docker/login-action@v3.3.0
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
        if: steps.version.outputs.version_docker_ci != 'null'
      - uses: docker/build-push-action@v6.12.0
        with:
          push: ${{ steps.version.outputs.version_docker_ci != 'null' }}
          tags: ${{ github.repository }}:${{ steps.version.outputs.version_docker_ci }}
  publish-github-release:
    needs: [ omnilint, rust, docker-build ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4.2.2
      - id: version
        uses: ./
      - name: publish github release
        uses: "marvinpinto/action-automatic-releases@v1.2.1"
        if: steps.version.outputs.version_tagged != ''
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          prerelease: false
