name: 📦🚀 Trigger Dev Docker Build

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

concurrency:
  # SHA is added to the end if on `main` to let all main workflows run
  group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/') || startsWith(github.ref, 'refs/heads/long_lived/')) && github.sha || '' }}
  cancel-in-progress: true

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_ACCESS_TOKEN" ]; then HAS_SECRET='true' ; fi
          echo HAS_SECRET=${HAS_SECRET} >> $GITHUB_OUTPUT
        env:
          GLUE_ACCESS_TOKEN: "${{ secrets.GLUE_ACCESS_TOKEN }}"

      - name: Trigger docker dev workflow via github-glue
        if: steps.check_secrets.outputs.HAS_SECRET
        run: |
          curl -s -XPOST -H "Authorization: Bearer ${{ secrets.GLUE_ACCESS_TOKEN }}" --data '{"sha":"${{ github.sha }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/docker-build-dev/${{ github.sha }}/start
          curl -s -XPOST -H "Authorization: Bearer ${{ secrets.GLUE_ACCESS_TOKEN }}" --data '{"sha":"${{ github.sha }}"}' ${{ secrets.GLUE_API_URL }}/api/v1/docker-build-dev/${{ github.sha }}/success/build-dev
