[BACKPORT 2025.2][DEVOPS-3735] ci: github actions for PR static check #17
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "yb-gh" | |
| # The title/description checks are only really needed on open/edit events, | |
| # But then it won't be available from head commit if the PR is synchronized. | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened, edited ] | |
| paths-ignore: | |
| - README.md | |
| - 'docs/**' | |
| jobs: | |
| pr-title: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check PR title | |
| run: | | |
| TITLE_RE='^(\[(BACKPORT )?([0-9]+(\.[0-9]+)+)\])?' | |
| TITLE_RE+='\[((#[0-9]+(,#[0-9]+)*)|([A-Z]+-[0-9]+(,[A-Z]+-[0-9]+)*))\]' | |
| TITLE_RE+=' [a-zA-Z0-9_-]+(,[[a-zA-Z0-9_]-]+)*:' | |
| TITLE_RE+=' \S.{8,98}\S$' | |
| if [[ ! "${{ github.event.pull_request.title }}" =~ $TITLE_RE ]]; then | |
| echo "::error ::PR title must include issue ID, code area (no extra whitespace)," | |
| echo "::error :: and a short description." | |
| echo "::error ::Issue referenced must be a github issue or YB-internal Jira ID" | |
| echo "::error ::Short description must be less than 100 characters." | |
| echo "::error ::Backport branch should be used only for non-master release branches." | |
| echo "::error ::Examples:" | |
| echo "::error :: [#12345,#12367] area: Cool feature xyz" | |
| echo "::error :: [BACKPORT 2045.1][#12345] area1,area2: Must have fix" | |
| exit 1 | |
| fi | |
| - name: Check Backport title | |
| run: | | |
| BACKPORT_RE='^\[(BACKPORT )?([0-9]+(\.[0-9]+)+)\]' | |
| if [[ "${{ github.base_ref }}" == "master" ]]; then | |
| if [[ "${{ github.event.pull_request.title }}" =~ $BACKPORT_RE ]]; then | |
| echo "::error ::PR title should not specify target branch if targeting master." | |
| exit 1 | |
| fi | |
| else | |
| if [[ "${{ github.event.pull_request.title }}" =~ $BACKPORT_RE ]]; then | |
| BACKPORT_BRANCH="${BASH_REMATCH[2]}" | |
| if [[ "${BACKPORT_BRANCH}" != "${{ github.base_ref }}" ]]; then | |
| echo "::error ::Backport branch in title (${BACKPORT_BRANCH}) does not match" | |
| echo "::error :: PR base ref (${{ github.base_ref }})." | |
| exit 1 | |
| fi | |
| else | |
| echo "::error ::PR title must begin with target release branch in square brackets." | |
| echo "::error ::Examples:" | |
| echo "::error :: [BACKPORT 2045.1][#12345] area1,area2: Must have fix from master" | |
| echo "::error :: [2045.2][#12345] area: release-specific change" | |
| exit 1 | |
| fi | |
| fi | |
| - name: Check Backport refernces | |
| run: | | |
| BACKPORT_RE='^\[BACKPORT ([0-9]+(\.[0-9]+)+)\]' | |
| # Check for true backport, not just target branch in title. | |
| if [[ "${{ github.event.pull_request.title }}" =~ $BACKPORT_RE ]]; then | |
| COMMIT_RE='^Original commit: ([0-9a-f]+) / ([#D][0-9]+)' | |
| body="${{ github.event.pull_request.body }}" | |
| if ! echo "$body" | grep -qE "$COMMIT_RE"; then | |
| echo "::error ::Backport PR must include original commit SHA and issue reference" | |
| echo "::error ::in the PR description. Examples:" | |
| echo "::error ::Original commit: 123abc / #12345" | |
| echo "::error ::Original commits:" | |
| echo "::error ::- 123abc / #12345" | |
| echo "::error ::- 345def / #43555" | |
| exit 1 | |
| fi | |
| # original_commit_re = Regexp.new('^Original commit(s)?:') | |
| # commit_sha_revision_re = Regexp.new('(^- )?([0-9a-f]+) / ([#D][0-9]+)') | |
| fi |