Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/pr-text-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Check the subject and description of each PR for basic best practices and
# fail with an error if a PR doesn't meet the conditions.

name: Pull request text checker
run-name: >-
Check title and description of PR
#${{github.event.inputs.pr-number || github.event.pull_request.number}}
by ${{github.actor}}

on:
pull_request:
types:
- opened
- reopened
- synchronize
branches:
- main

workflow_dispatch:
inputs:
pr-number:
description: 'The PR number of the PR to check:'
type: string
required: true
debug:
description: 'Run with debugging options'
type: boolean
default: true

permissions: read-all

jobs:
check-pr-text:
name: "Title & description check"
if: github.repository_owner == 'quantumlib'
runs-on: ubuntu-slim
timeout-minutes: 5
steps:
- name: Enable shell debugging if requested
if: ${{inputs.debug || runner.debug}}
run: echo "SHELLOPTS=xtrace" >> "${GITHUB_ENV}"

# Note that this workflow does not need to check out the git repo because
# it does not need to read any files in the repo.
- name: Check title and description
run: |
pr_title=$(jq -r ".pull_request.title" "${GITHUB_EVENT_PATH}")
pr_body=$(jq -r ".pull_request.body" "${GITHUB_EVENT_PATH}")

declare -a problems=()
if [[ -z "${pr_title}" ]]; then
problems+=("PR title cannot be empty.")
else
read -ra title_words <<< "${pr_title}"
if [[ ${#title_words[@]} -lt 2 ]]; then
problems+=("PR title must contain at least two words.")
fi
fi

if [[ -z "${pr_body}" || ${#pr_body} -lt 10 ]]; then
problems+=("PR description must be at least 10 characters long.")
fi

if [[ ${#problems[@]} -gt 0 ]]; then
# shellcheck disable=SC2034
Copy link
Collaborator

@pavoljuhas pavoljuhas Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this code ever visited by shellcheck? If not, please remove.

{
echo "Please fix the following problem(s) with this PR:"
printf -- ":x: %s\n" "${problems[@]}"
} >> "${GITHUB_STEP_SUMMARY}"
Copy link
Collaborator

@pavoljuhas pavoljuhas Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add exit 1 or such to indicate check failure.

fi

# Point people to the list of problems. Done as a separate step to make
# this text easier for people to find in the workflow results.
- name: Report outcome
run: |
if [[ "${result}" == "error" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ${result} parameter is unset so the block will never run.
Consider replacing with GHA's if: failure()

echo '::error::Failed checks. Please check the workflow summary.'
exit 1
fi
Loading