From 8d450c69d2d4e88ad53e2cfe22f0952461dd10da Mon Sep 17 00:00:00 2001 From: ajnart <49837342+ajnart@users.noreply.github.com> Date: Sat, 11 Jul 2026 15:41:06 +0200 Subject: [PATCH] fix(ci): fork-safe cleanup, manual triggers, draft PR skipping - cleanup: pull_request -> pull_request_target so fork PRs trigger cleanup - cleanup: add workflow_dispatch for manual stale image deletion - publish: skip fork PRs (no packages:write) and draft PRs - publish: add ready_for_review trigger - publish: add workflow_dispatch for manual fork PR builds - publish: unified tag derivation step --- .github/workflows/on-pr-docker-cleanup.yml | 10 +++++-- .github/workflows/on-pr-docker-publish.yml | 34 +++++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/.github/workflows/on-pr-docker-cleanup.yml b/.github/workflows/on-pr-docker-cleanup.yml index 3398bcab7..9e3e18505 100644 --- a/.github/workflows/on-pr-docker-cleanup.yml +++ b/.github/workflows/on-pr-docker-cleanup.yml @@ -1,17 +1,23 @@ name: "[PR] Cleanup Docker preview image" on: - pull_request: + pull_request_target: types: [closed] branches: - dev + workflow_dispatch: + inputs: + pr-number: + description: "PR number whose preview image to delete" + required: true + type: number permissions: packages: write env: REGISTRY: ghcr.io - IMAGE_TAG: pr-${{ github.event.number }} + IMAGE_TAG: pr-${{ github.event.inputs.pr-number || github.event.number }} jobs: delete-image: diff --git a/.github/workflows/on-pr-docker-publish.yml b/.github/workflows/on-pr-docker-publish.yml index 8a911416c..d2bb63e48 100644 --- a/.github/workflows/on-pr-docker-publish.yml +++ b/.github/workflows/on-pr-docker-publish.yml @@ -2,9 +2,20 @@ name: "[PR] Publish Docker preview image" on: pull_request: - types: [opened, synchronize, reopened] + types: [opened, synchronize, reopened, ready_for_review] branches: - dev + workflow_dispatch: + inputs: + pr-number: + description: "PR number (uses head ref of that PR)" + required: true + type: number + ref: + description: "Git ref to build (branch, tag, or SHA)" + required: false + type: string + default: "" permissions: contents: read @@ -17,18 +28,33 @@ env: TURBO_TELEMETRY_DISABLED: 1 concurrency: - group: pr-docker-${{ github.event.number }} + group: pr-docker-${{ github.event.inputs.pr-number || github.event.number }} cancel-in-progress: true jobs: build-and-push: name: Build and push PR preview image runs-on: ubuntu-latest - timeout-minutes: 20 + timeout-minutes: 25 + if: | + github.event_name == 'workflow_dispatch' || + ( + github.event_name == 'pull_request' && + github.event.pull_request.draft == false && + github.event.pull_request.head.repo.full_name == github.repository + ) steps: - uses: actions/checkout@v6 with: persist-credentials: false + ref: ${{ github.event.inputs.ref || '' }} + + - name: Determine tag + id: tag + run: | + PR_NUMBER="${{ github.event.inputs.pr-number || github.event.number }}" + echo "tag=pr-${PR_NUMBER}" >> "$GITHUB_OUTPUT" + echo "pr-number=${PR_NUMBER}" >> "$GITHUB_OUTPUT" - name: Docker meta id: meta @@ -36,7 +62,7 @@ jobs: with: images: "${{ env.GHCR_REPO }}" tags: | - type=raw,value=pr-${{ github.event.number }} + type=raw,value=${{ steps.tag.outputs.tag }} - name: Log in to the Container registry uses: docker/login-action@v4