| # reusable workflow | |
| name: .dco | |
| # TODO: hide reusable workflow from the UI. Tracked in https://github.com/community/community/discussions/12025 | |
| # Permissions must be granted by the calling workflow. | |
| permissions: {} | |
| on: | |
| workflow_call: | |
| jobs: | |
| run: | |
| permissions: | |
| pull-requests: read | |
| runs-on: ubuntu-26.04 | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Validate DCO | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| run: | | |
| # Skip the check on non-PR events, but don't skip the check itself, | |
| # because other jobs may depend on it ("needs: validate-dco"). | |
| if [ -z "$PR_NUMBER" ]; then | |
| echo "Skipping DCO validation; not a pull request." | |
| exit 0 | |
| fi | |
| 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")" | |
| badCommits="$( | |
| jq -r ' | |
| def githubUsername: | |
| # "Username may only contain alphanumeric characters or dashes and cannot begin with a dash" | |
| "[a-zA-Z0-9][a-zA-Z0-9-]+"; | |
| def dco: | |
| # https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work | |
| "^(Docker-DCO-1\\.1-)?Signed-off-by: ([^<]+) <([^<>@]+@[^<>]+)>( \\(github: (" | |
| + githubUsername | |
| + ")\\))?$"; | |
| .[][] | |
| # Skip merge commits. | |
| | select(.parents | length <= 1) | |
| | select( | |
| .commit.message | |
| | split("\n") | |
| | any(test(dco)) | |
| | not | |
| ) | |
| | .sha | |
| ' "$RUNNER_TEMP/pr-commits.json" | |
| )" | |
| if [ -z "$badCommits" ]; then | |
| echo "Checked ${commitCount} commit(s); all commits are properly signed with the DCO." | |
| exit 0 | |
| fi | |
| echo "::error::One or more commits are missing a valid DCO 'Signed-off-by:' trailer." | |
| while read -r commit; do | |
| echo " - ${commit}" | |
| done <<< "$badCommits" | |
| echo | |
| echo "The sign-off certifies that you wrote the contribution or have the right to submit it." | |
| echo "Use your real name, not a GitHub username, handle, or pseudonym:" | |
| echo | |
| echo " Signed-off-by: YourFirstName YourLastName <yourname@example.org>" | |
| echo | |
| echo "Git can add this automatically with 'git commit -s'." | |
| echo "See https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work" | |
| echo "DCO 1.1: https://developercertificate.org/" | |
| exit 1 |