From 44ea7533febe27b1ead9f44dc3e98ece5e270ed9 Mon Sep 17 00:00:00 2001 From: David Galloway Date: Wed, 7 May 2025 11:03:39 -0400 Subject: [PATCH] .github: Add pr-job-dispatcher workflow This will automatically run on PR creation and repush. It will check if only docs files have been modified and, if so, will trigger the PR status faker workflow. If it is not a docs-only PR, it will dispatch the regular Jenkins jobs we run for every PR. Signed-off-by: David Galloway --- .github/workflows/pr-job-dispatcher.yml | 128 ++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 .github/workflows/pr-job-dispatcher.yml diff --git a/.github/workflows/pr-job-dispatcher.yml b/.github/workflows/pr-job-dispatcher.yml new file mode 100644 index 0000000000000..4827943fe238b --- /dev/null +++ b/.github/workflows/pr-job-dispatcher.yml @@ -0,0 +1,128 @@ +name: Pull Request Job Dispatcher + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + pr-job-dispatcher: + runs-on: ubuntu-latest + permissions: + pull-requests: read + contents: read + outputs: + only_docs: ${{ steps.check-if-docs-only-pr.outputs.only_docs }} + only_container: ${{ steps.check-if-container-only-pr.outputs.only_container }} + pr_number: ${{ steps.get-pr-metadata.outputs.pr_number }} + pr_sha: ${{ steps.get-pr-metadata.outputs.pr_sha }} + + steps: + - name: Get PR metadata + id: get-pr-metadata + run: | + echo "pr_number=${{ github.event.pull_request.number }}" >> "$GITHUB_OUTPUT" + echo "pr_sha=${{ github.event.pull_request.head.sha }}" >> "$GITHUB_OUTPUT" + + - name: Get list of changed files + id: get-pr-changed-files + uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c + + - name: Check if only docs-related files changed + id: check-if-docs-only-pr + run: | + is_docs_file() { + local f="$1" + [[ "$f" == doc/* || + "$f" == admin/* || + "$f" == src/sample.ceph.conf || + "$f" == CodingStyle || + "$f" == *.rst || + "$f" == *.md || + "$f" == COPYING* || + "$f" == README.* || + "$f" == SubmittingPatches || + "$f" == .readthedocs.yml || + "$f" == PendingReleaseNotes ]] && return 0 + return 1 + } + + only_docs=true + + changed_files="${{ steps.get-pr-changed-files.outputs.all_changed_files }}" + for file in $changed_files; do + echo "Checking: [$file]" + if ! is_docs_file "$file"; then + echo "$file is not a docs file" + only_docs=false + break + fi + done + + echo "only_docs=$only_docs" >> "$GITHUB_OUTPUT" + + - name: Check if only container-related files changed + id: check-if-container-only-pr + run: | + is_container_file() { + local f="$1" + [[ "$f" == container/* || + "$f" == Dockerfile.build || + "$f" == src/script/buildcontainer-setup.sh || + "$f" == src/script/build-with-container.py ]] && return 0 + return 1 + } + + only_container=true + + changed_files="${{ steps.get-pr-changed-files.outputs.all_changed_files }}" + for file in $changed_files; do + echo "Checking: [$file]" + if ! is_container_file "$file"; then + echo "$file is not a container file" + only_container=false + break + fi + done + + echo "only_container=$only_container" >> "$GITHUB_OUTPUT" + + trigger-fake-status-checks: + if: needs.pr-job-dispatcher.outputs.only_docs == 'true' || needs.pr-job-dispatcher.outputs.only_container == 'true' + permissions: + pull-requests: read + statuses: write + needs: pr-job-dispatcher + uses: ./.github/workflows/pr-checks-faker.yml + with: + pr_number: ${{ needs.pr-job-dispatcher.outputs.pr_number }} + pr_sha: ${{ needs.pr-job-dispatcher.outputs.pr_sha }} + triggered_by: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} + + trigger-jenkins-jobs: + if: needs.pr-job-dispatcher.outputs.only_docs != 'true' && needs.pr-job-dispatcher.outputs.only_container != 'true' + permissions: + contents: read + pull-requests: read + needs: pr-job-dispatcher + runs-on: ubuntu-latest + steps: + - name: Trigger Jenkins jobs with parameters + run: | + GH_PULL_REQUEST_ID="${{ needs.pr-job-dispatcher.outputs.pr_number }}" + GH_PULL_REQUEST_SHA="${{ needs.pr-job-dispatcher.outputs.pr_sha }}" + + for job in ceph-pull-requests ceph-pull-requests-arm64 ceph-windows-pull-requests ceph-api; do + echo "Triggering $job ..." + for attempt in {1..5}; do + curl --fail --retry 4 --retry-delay 5 --retry-connrefused \ + -X POST "https://jenkins.ceph.com/job/$job/buildWithParameters" \ + --user "${{ secrets.JENKINS_USER }}:${{ secrets.JENKINS_API_TOKEN }}" \ + --data-urlencode "GH_PULL_REQUEST_ID=$GH_PULL_REQUEST_ID" \ + --data-urlencode "GH_PULL_REQUEST_SHA=$GH_PULL_REQUEST_SHA" \ + --data-urlencode "TRIGGER_METHOD=Branch push" \ + --data-urlencode "TRIGGERED_BY=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" && break + + echo "Attempt $attempt for $job failed. Retrying..." + sleep 3 + done + done -- 2.39.5