diff --git a/.github/workflows/cloud-dispatch-build.yaml b/.github/workflows/cloud-dispatch-build.yaml index 16bb04c768..a681efa8b0 100644 --- a/.github/workflows/cloud-dispatch-build.yaml +++ b/.github/workflows/cloud-dispatch-build.yaml @@ -46,18 +46,35 @@ jobs: EVENT_NAME: ${{ github.event_name }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + ACTION: ${{ github.event.action }} + LABEL_NAME: ${{ github.event.label.name }} + PR_LABELS: ${{ toJson(github.event.pull_request.labels.*.name) }} run: | if [ "${EVENT_NAME}" = "pull_request" ]; then REF="${PR_HEAD_SHA}" BRANCH="${PR_HEAD_REF}" + + # Derive variant from labels + VARIANT="gpu" + if [ "${ACTION}" = "labeled" ]; then + [ "${LABEL_NAME}" = "preview-cpu" ] && VARIANT="cpu" + else + # synchronize — check existing labels on the PR + echo "${PR_LABELS}" | grep -q '"preview-cpu"' && VARIANT="cpu" + fi else REF="${GITHUB_SHA}" BRANCH="${GITHUB_REF_NAME}" + PR_NUMBER="" + VARIANT="" fi payload="$(jq -nc \ --arg ref "${REF}" \ --arg branch "${BRANCH}" \ - '{ref: $ref, branch: $branch}')" + --arg pr_number "${PR_NUMBER}" \ + --arg variant "${VARIANT}" \ + '{ref: $ref, branch: $branch, pr_number: $pr_number, variant: $variant}')" echo "json=${payload}" >> "${GITHUB_OUTPUT}" - name: Dispatch to cloud repo diff --git a/.github/workflows/cloud-dispatch-cleanup.yaml b/.github/workflows/cloud-dispatch-cleanup.yaml new file mode 100644 index 0000000000..764abffbd6 --- /dev/null +++ b/.github/workflows/cloud-dispatch-cleanup.yaml @@ -0,0 +1,39 @@ +--- +# Dispatches a frontend-preview-cleanup event to the cloud repo when a +# frontend PR with a preview label is closed or has its preview label +# removed. The cloud repo handles the actual environment teardown. +# +# This is fire-and-forget — it does NOT wait for the cloud workflow to +# complete. Status is visible in the cloud repo's Actions tab. + +name: Cloud Frontend Preview Cleanup Dispatch + +on: + pull_request: + types: [closed, unlabeled] + +permissions: {} + +jobs: + dispatch: + # Only dispatch when: + # - PR closed AND had a preview label + # - Preview label specifically removed + if: > + github.repository == 'Comfy-Org/ComfyUI_frontend' && + ((github.event.action == 'closed' && + (contains(github.event.pull_request.labels.*.name, 'preview') || + contains(github.event.pull_request.labels.*.name, 'preview-cpu') || + contains(github.event.pull_request.labels.*.name, 'preview-gpu'))) || + (github.event.action == 'unlabeled' && + contains(fromJSON('["preview","preview-cpu","preview-gpu"]'), github.event.label.name))) + runs-on: ubuntu-latest + steps: + - name: Dispatch to cloud repo + uses: peter-evans/repository-dispatch@28959ce8df70de7be546dd1250a005dd32156697 # v4.0.1 + with: + token: ${{ secrets.CLOUD_DISPATCH_TOKEN }} + repository: Comfy-Org/cloud + event-type: frontend-preview-cleanup + client-payload: >- + {"pr_number": "${{ github.event.pull_request.number }}"}