blob: eefae7d350052e92156944f1c7baf46de12304a5 [file] [edit]
name: validate-pr
permissions:
pull-requests: read
on:
pull_request:
types: [opened, reopened, edited, synchronize, labeled, unlabeled]
jobs:
check-labels:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-check-labels
cancel-in-progress: true
if: ${{ github.repository == 'moby/moby' && github.event.pull_request.state == 'open' }}
runs-on: ubuntu-26.04
timeout-minutes: 5
steps:
- name: Missing `area/` label
if: always() && contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'area/')
run: |
echo "::error::Every PR with an 'impact/*' label should also have an 'area/*' label"
exit 1
- name: Missing `kind/` label
if: always() && contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') && !contains(join(github.event.pull_request.labels.*.name, ','), 'kind/')
run: |
echo "::error::Every PR with an 'impact/*' label should also have a 'kind/*' label"
exit 1
- name: OK
run: exit 0
check-changelog:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-check-changelog
cancel-in-progress: true
if: ${{ github.repository == 'moby/moby' && github.event.pull_request.state == 'open' }}
runs-on: ubuntu-26.04
timeout-minutes: 5
env:
HAS_IMPACT_LABEL: ${{ contains(join(github.event.pull_request.labels.*.name, ','), 'impact/') }}
PR_BODY: |
${{ github.event.pull_request.body }}
steps:
- name: Check changelog description
run: |
# Extract the `markdown changelog` note code block
block=$(echo -n "$PR_BODY" | tr -d '\r' | awk '/^```markdown changelog$/{flag=1;next}/^```$/{flag=0}flag')
# Strip empty lines
desc=$(echo "$block" | awk NF)
if [ "$HAS_IMPACT_LABEL" = "true" ]; then
if [ -z "$desc" ]; then
echo "::error::Changelog section is empty. Please provide a description for the changelog."
exit 1
fi
len=$(echo -n "$desc" | wc -c)
if [[ $len -le 6 ]]; then
echo "::error::Description looks too short: $desc"
exit 1
fi
else
if [ -n "$desc" ]; then
echo "::error::PR has a changelog description, but no changelog label"
echo "::error::Please add the relevant 'impact/' label to the PR or remove the changelog description"
exit 1
fi
fi
echo "This PR will be included in the release notes with the following note:"
echo "$desc"
check-commit-references:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-check-commit-references
cancel-in-progress: true
if: ${{ github.event.pull_request.state == 'open' }}
runs-on: ubuntu-26.04
timeout-minutes: 5
steps:
- name: Check GitHub references
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh api --paginate --slurp "/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}/commits" > "$RUNNER_TEMP/pr-commits.json"
# Number of commits, excluding merge commits.
commitCount="$(jq '[.[][] | select(.parents | length <= 1)] | length' "$RUNNER_TEMP/pr-commits.json")"
references="$(
jq -r '
def ghref:
"(^|[^[:alnum:]_])#[0-9]+"
+ "|(^|[^[:alnum:]_./-])[[:alnum:]_.-]+#[0-9]+"
+ "|(^|[^[:alnum:]_./-])[[:alnum:]_.-]+/[[:alnum:]_.-]+#[0-9]+"
+ "|https?://(www\\.)?github\\.com/[^[:space:]/]+/[^[:space:]/]+/(issues|pull)/[0-9]+";
.[][]
# Skip merge commits.
| select(.parents | length <= 1)
| select(.commit.message | test(ghref))
| .sha
' "$RUNNER_TEMP/pr-commits.json"
)"
if [ -z "$references" ]; then
echo "Checked ${commitCount} commit(s); no GitHub issue or PR references found."
exit 0
fi
while read -r commit; do
echo "::error::commit ${commit} contains a GitHub issue or PR reference; use a commit hash instead if a reference is needed."
done <<< "$references"
echo
echo "Remove GitHub issue or PR references from commit messages."
echo "Use commit hashes instead if a reference is needed."
echo "Keep GitHub issue or PR references in GitHub-visible text, such as PR descriptions or comments."
exit 1
check-agent-coauthors:
permissions:
contents: read
pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-check-agent-coauthors
cancel-in-progress: true
if: ${{ github.event.pull_request.state == 'open' }}
runs-on: ubuntu-26.04
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: .github/scripts
- name: Check agent co-authorship
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const check = require('./.github/scripts/check-agent-coauthors.js');
await check({ github, context, core });
check-pr-branch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-check-pr-branch
cancel-in-progress: true
if: ${{ github.repository == 'moby/moby' && github.event.pull_request.state == 'open' }}
runs-on: ubuntu-26.04
timeout-minutes: 5
env:
PR_TITLE: ${{ github.event.pull_request.title }}
steps:
# Backports or PR that target a release branch directly should mention the target branch in the title, for example:
# [X.Y backport] Some change that needs backporting to X.Y
# [X.Y] Change directly targeting the X.Y branch
- name: Check release branch
id: title_branch
run: |
# If PR targets a different branch than master, the PR title should mention the target branch in square brackets, for example:
# [27.1 backport] Some change that needs backporting to 27.1
# [27.1] Change directly targeting the 27.1 branch
# [docker-29.x] Change directly targeting the docker-29.x branch
# [docker-29.x backport] Some change that needs backporting to docker-29.x
# get the intended major version prefix ("[27.1 backport]" -> "27.") from the PR title.
target_branch=$(echo "$PR_TITLE" | sed -nE 's/^\[([^]]+)\].*/\1/p' | sed 's/ backport$//')
echo "target_branch: $target_branch"
echo "GITHUB_BASE_REF: $GITHUB_BASE_REF"
# If the PR is opened against the master branch and the target branch is not specified, exit early.
if [[ "$GITHUB_BASE_REF" == "master" && "$target_branch" == "" ]]; then
exit 0
fi
if [[ "$target_branch" != "$GITHUB_BASE_REF" ]]; then
echo "::error::PR is opened against the $GITHUB_BASE_REF branch, but its title suggests otherwise."
exit 1
fi