name: 📦🚀 Trigger Dev Docker Build

on:
  push:
    paths-ignore:
      - "**.md"
    branches:
      - "long_lived/**"
      - "release/**"
  pull_request:
    paths-ignore:
      - "**.md"

concurrency:
  group: ${{ github.event_name == 'pull_request' && format('{0}-{1}', github.workflow_ref, github.event.pull_request.number) || github.run_id }}
  cancel-in-progress: true

permissions:
  id-token: write
  contents: read

jobs:
  trigger:
    name: Trigger building a new dev tag for the chia-docker image
    runs-on: ubuntu-latest
    steps:
      - name: Test for secrets access
        id: check_secrets
        shell: bash
        run: |
          unset HAS_SECRET

          if [ -n "$GLUE_API_URL" ]; then HAS_SECRET='true' ; fi
          echo HAS_SECRET=${HAS_SECRET} >> "$GITHUB_OUTPUT"
        env:
          GLUE_API_URL: "${{ secrets.GLUE_API_URL }}"

      - name: Trigger docker dev workflow via github-glue
        uses: Chia-Network/actions/github/glue@main
        if: steps.check_secrets.outputs.HAS_SECRET
        with:
          json_data: '{"sha":"${{ github.sha }}"}'
          glue_url: "${{ secrets.GLUE_API_URL }}"
          glue_project: "docker-build-dev/${{ github.sha }}"
          glue_path: "start"

      - name: Trigger docker dev success via github-glue
        uses: Chia-Network/actions/github/glue@main
        if: steps.check_secrets.outputs.HAS_SECRET
        with:
          json_data: '{"sha":"${{ github.sha }}"}'
          glue_url: "${{ secrets.GLUE_API_URL }}"
          glue_project: "docker-build-dev/${{ github.sha }}"
          glue_path: "success/build-dev"
