name: Docker Image CI

on:
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      version:
        description: 'Version to publish (e.g. 1.2.5, patch, minor, major)'
        required: true
        default: 'patch'

permissions:
  id-token: write  # Required for OIDC
  contents: write  # Required to push the version bump commit and tags

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6          
      - uses: actions/setup-node@v6
        with:
          node-version: '24.x'
          registry-url: 'https://registry.npmjs.org'
      - run: npm ci
      - name: Test
        run: npm run test
      - name: Build
        run: |
          npm run build
        env:
          NOTION_API_KEY: ${{ secrets.NOTION_API_KEY }}
      - name: Bump version
        run: |
          git config --global user.email "guido.bellomo@gmail.com"
          git config --global user.name "Guido Bellomo"
          git add .
          git commit -m "build"
          npm version ${{ github.event.inputs.version || github.ref_name }}
      - name: Push changes to repository
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          git push origin HEAD:master && git push --tags          
      - run: npm publish
        name: Publish
  
#  docker:
#    needs: build
#    runs-on: ubuntu-latest
#    steps:
#      - name: Checkout repository
#        uses: actions/checkout@v3
#      - name: Set up QEMU
#        uses: docker/setup-qemu-action@v2
#      - name: Set up Docker Buildx
#        uses: docker/setup-buildx-action@v2
#      - name: Login to DockerHub
#        uses: docker/login-action@v2
#        with:
#          username: ${{ secrets.DOCKERHUB_USERNAME }}
#          password: ${{ secrets.DOCKERHUB_TOKEN }}
#      - name: Build and push
#        uses: docker/build-push-action@v3
#        with:
#          platforms: linux/amd64,linux/arm64
#          push: true
#          tags: guidone/redbot:latest
#      - name: notification
#        if: cancelled() == false
#        uses: xinthink/action-telegram@v1.1
#        with:
#          botToken: ${{ secrets.BotToken }}
#          chatId: ${{ secrets.ChatID }}
#          jobStatus: ${{ job.status }}
#          skipSuccess: false
