diff --git a/.github/workflows/pr-labeler.yml b/.github/workflows/pr-labeler.yml new file mode 100644 index 0000000..1d41195 --- /dev/null +++ b/.github/workflows/pr-labeler.yml @@ -0,0 +1,76 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +# Applies the label for each title prefix listed in the "Pull request titles" +# section of CONTRIBUTING.md, and removes prefix labels the title no longer has. +# pull_request_target is needed so that pull requests from forks can be +# labeled. It is safe here because the job never checks out the pull request +# and reads the title only through the environment. +name: "Pull Request Labeler" + +on: + pull_request_target: # zizmor: ignore[dangerous-triggers] + types: [opened, edited, reopened] + +permissions: + pull-requests: write + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: false + +jobs: + label: + name: Label from title prefix + runs-on: ubuntu-24.04 + steps: + - name: Sync labels with the title prefix + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + TITLE=$(gh api "repos/${REPO}/pulls/${PR_NUMBER}" --jq '.title') + declare -A label_for=( + [Fixture]=fixtures [Tooling]=tooling [CI]=ci + [Docs]=docs [Policy]=policy [Infra]=infra + ) + prefixes='Fixture|Tooling|CI|Docs|Policy|Infra' + pattern="^((${prefixes})(, (${prefixes}))*): " + if [[ ! "$TITLE" =~ $pattern ]]; then + echo "Title has no valid prefix, leaving labels unchanged." + exit 0 + fi + + declare -A wanted=() + IFS=',' read -ra kinds <<< "${BASH_REMATCH[1]}" + for kind in "${kinds[@]}"; do + wanted[${label_for[${kind# }]}]=1 + done + + current=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/labels" --jq '.[].name') + for label in "${label_for[@]}"; do + if grep -qxF "$label" <<< "$current"; then + if [[ -z "${wanted[$label]:-}" ]]; then + echo "Removing label: ${label}" + gh api -X DELETE "repos/${REPO}/issues/${PR_NUMBER}/labels/${label}" > /dev/null + fi + elif [[ -n "${wanted[$label]:-}" ]]; then + echo "Adding label: ${label}" + gh api -X POST "repos/${REPO}/issues/${PR_NUMBER}/labels" -f "labels[]=${label}" > /dev/null + fi + done diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000..cec1a94 --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -0,0 +1,49 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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 +# +# http://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. + +# Checks that the pull request title starts with a prefix from the +# "Pull request titles" section of CONTRIBUTING.md. +name: "Pull Request Title" + +on: + pull_request: + types: [opened, edited, reopened, synchronize] + +permissions: {} + +jobs: + check-title: + name: Check pull request title + runs-on: ubuntu-24.04 + steps: + - name: Check prefix + env: + # The title is untrusted input, so it is passed through the environment + # and never interpolated into the script. + TITLE: ${{ github.event.pull_request.title }} + run: | + prefixes='Fixture|Tooling|CI|Docs|Policy|Infra' + pattern="^(${prefixes})(, (${prefixes}))*: [^[:space:]]" + if [[ "$TITLE" =~ $pattern ]]; then + echo "Title has a valid prefix." + exit 0 + fi + echo "::error title=Missing title prefix::The title must start with one of" \ + "Fixture, Tooling, CI, Docs, Policy or Infra, then ': ' and a summary," \ + "e.g. 'Fixture: Add reference table for ...'. See the" \ + "'Pull request titles' section of CONTRIBUTING.md." + exit 1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97123d2..9a5db9e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -269,6 +269,33 @@ to you, but it has to cover: It has to settle the comparison rule and how a failure is labeled. Pseudocode is one way to do that and prose is another. +### Pull request titles + +A pull request title starts with a prefix naming the kind of change: + +``` +Fixture: Add reference table for primitive types read from Parquet +``` + +Pull requests are squash-merged with the title as the commit message, so the +prefix is how `main`'s history is read by kind. + +| Prefix | Label | Use for | +| --------- | ---------- | ------------------------------------------------------------------------------------------ | +| `Fixture` | `fixtures` | A new surface, new cases or reference tables, or a correction to a committed fixture. | +| `Tooling` | `tooling` | Validators and schemas under `dev/`, the table generator, runners, formatting, `Makefile`. | +| `CI` | `ci` | Workflows under `.github/workflows`. | +| `Docs` | `docs` | README and CONTRIBUTING changes that change no rule a contributor must follow. | +| `Policy` | `policy` | Rules a contributor or a fixture must follow, wherever they are written. | +| `Infra` | `infra` | `.asf.yaml`, repository settings, and issue and pull request templates. | + +A change that changes what a contributor must do is `Policy`, otherwise it is +`Docs`. A pull request that is substantially two kinds lists both, separated by +a comma, as in `Fixture, Tooling:`. Tooling changes that only support a new +fixture stay under `Fixture`. Open a draft pull request instead of marking the +title `[WIP]`. CI checks the title on every pull request and applies the +label for each prefix. + ## Before opening a pull request Run `make install` once to install the tooling, then `make format` to format the