name: 'PVF Trigger' description: 'On a /pvf PR comment, resolve the candidate plugin version from the latest Build run and dispatch performance-validation.yml (in this repo or a separate dashboard-host repo)' inputs: comment: description: 'Comment body to scan for a /pvf command' required: true pr-number: description: 'Pull request number the comment was posted on' required: true build-workflow: description: 'Filename of the build workflow that uploads the candidate-version artifact' required: false default: build.yml rule-prefixes: description: 'Space-separated rule-key prefixes passed to the /pvf comment parser' required: false default: 'S' target-repo: description: 'owner/name of the repo that hosts performance-validation.yml. Defaults to the current repo (same-repo dispatch). Set to a separate private/internal repo to publish an SSO-gated dashboard while this repo stays public.' required: false default: ${{ github.repository }} target-ref: description: 'Git ref to dispatch performance-validation.yml on in target-repo. Empty falls back to the PR head ref (same-repo behaviour); set to the target repo default branch (e.g. master) for cross-repo dispatch.' required: false default: '' dispatch-token: description: 'Token used ONLY for the cross-repo workflow dispatch (needs actions:write on target-repo). Empty falls back to github.token, which only works for same-repo dispatch.' required: false default: '' runs: using: 'composite' steps: - name: Parse /pvf comment id: pvf uses: SonarSource/core-languages-tooling-public/pvf-comment@master with: comment: ${{ inputs.comment }} rule-prefixes: ${{ inputs.rule-prefixes }} - name: Trigger performance validation if: steps.pvf.outputs.found == 'true' shell: bash env: GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ inputs.pr-number }} RULES_REQUEST: ${{ steps.pvf.outputs.rules-request }} BUILD_WORKFLOW: ${{ inputs.build-workflow }} TARGET_REPO: ${{ inputs.target-repo }} TARGET_REF: ${{ inputs.target-ref }} DISPATCH_TOKEN: ${{ inputs.dispatch-token }} run: | set -euo pipefail pull="$(gh api "repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}")" head_ref="$(jq -r .head.ref <<<"$pull")" head_sha="$(jq -r .head.sha <<<"$pull")" title="$(jq -r .title <<<"$pull")" run_ids="$(gh api \ "repos/${GITHUB_REPOSITORY}/actions/workflows/${BUILD_WORKFLOW}/runs?head_sha=${head_sha}&event=pull_request&per_page=10" \ --jq '.workflow_runs[].id')" for run_id in $run_ids; do if gh run download "$run_id" --repo "$GITHUB_REPOSITORY" -n candidate-version; then break fi done if [ ! -f candidate-version.txt ]; then echo "No candidate-version artifact for ${head_sha}; wait for Build to finish" >&2 exit 1 fi TARGET_REPO="${TARGET_REPO:-$GITHUB_REPOSITORY}" token="${DISPATCH_TOKEN:-$GH_TOKEN}" extra_args=() if [ "$TARGET_REPO" != "$GITHUB_REPOSITORY" ]; then if [ -z "$TARGET_REF" ]; then echo "target-ref is required for cross-repo dispatch to ${TARGET_REPO}; set it to the host repo default branch (e.g. master)" >&2 exit 1 fi ref="$TARGET_REF" extra_args+=(-f "analyzer-repo=${GITHUB_REPOSITORY}") else # Same-repo dispatch: ref defaults to the PR head ref. ref="${TARGET_REF:-$head_ref}" fi GH_TOKEN="$token" gh workflow run performance-validation.yml \ --repo "$TARGET_REPO" \ --ref "$ref" \ -f "candidate-version=$(cat candidate-version.txt)" \ -f "rules-request=${RULES_REQUEST}" \ -f "pr-number=${PR_NUMBER}" \ -f "run-description=${title}" \ ${extra_args[@]+"${extra_args[@]}"}