name: Build and push packages

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  build:
    uses: 'flowfuse/github-actions-workflows/.github/workflows/build_node_package.yml@build_node_package/v1'
    with:
      node: '[
              {"version": "24", "tests": false, "lint": true},
            ]'

  publish:
    needs: build
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    uses: 'flowfuse/github-actions-workflows/.github/workflows/publish_node_package.yml@publish_node_package/v1'
    with:
      package_name: driver-k8s
      publish_package: true
    secrets:
      npm_registry_token: ${{ secrets.NPM_PUBLISH_TOKEN }}

  dispatch_container_build:
    needs: publish
    runs-on: ubuntu-latest
    steps:
      - name: Generate a token
        id: generate_token
        uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
        with:
          app-id: ${{ secrets.GH_BOT_APP_ID }}
          private-key: ${{ secrets.GH_BOT_APP_KEY }}
          owner: ${{ github.repository_owner }}
          repositories: helm
      - name: Trigger flowfuse container build
        uses: benc-uk/workflow-dispatch@31e2b3319479a63f0ab15bf800eff9e913504e26 # v1.3.2
        with:
          workflow: flowforge-container.yml
          repo: flowfuse/helm
          ref: main
          token: ${{ steps.generate_token.outputs.token }}    
  