forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (114 loc) · 5.32 KB
/
test_branch_conventions.yml
File metadata and controls
134 lines (114 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Fail on Malformed Commits in PR Branch
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ci-${{github.workflow}}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-merge-commits:
runs-on: ubuntu-latest
container: ardupilot/ardupilot-dev-chibios:v0.1.3
steps:
- name: Checkout PR branch
uses: actions/checkout@v6
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
submodules: 'recursive'
fetch-depth: 0
- name: Fetch base branch
run: |
git remote -v
git remote add upstream ${{ github.event.pull_request.base.repo.clone_url }}
git fetch upstream ${{ github.event.pull_request.base.ref }}
git show upstream/${{ github.event.pull_request.base.ref }}
- name: Update submodules
run: |
git submodule update --init --recursive
- name: Install aarch64 cross toolchain for Linux board checks
shell: bash
run: |
apt-get update
apt-get install -y g++-aarch64-linux-gnu
- name: Test new boards compile
shell: bash
run: |
Tools/scripts/test_new_boards.py --master-branch "upstream/${{ github.event.pull_request.base.ref }}"
- name: Check for merge commits in PR branch
shell: bash
run: |
# Find merge-base between base branch and (rebased) PR branch
echo "Merge target is origin/${{ github.event.pull_request.base.ref }}"
echo "github.event.pull_request.base.ref=${{ github.event.pull_request.base.ref }} "
# Look for merge commits in PR branch only
MERGE_COMMITS=$(git log upstream/${{ github.event.pull_request.base.ref }}..HEAD --merges --oneline)
echo "Merge commits:"
echo "$MERGE_COMMITS"
if [[ -n "$MERGE_COMMITS" ]]; then
echo "❌ Merge commits detected in the PR branch (not allowed):"
echo "Please see https://ardupilot.org/dev/docs/submitting-patches-back-to-master.html"
exit 1
else
echo "✅ No merge commits found in the PR branch."
fi
# Look for fixup! commits in PR branch only
COMMITS=$(git log upstream/${{ github.event.pull_request.base.ref }}..HEAD --oneline)
echo "Commits:"
echo "$COMMITS"
if [[ "$COMMITS" == *"fixup!"* ]]; then
echo "❌ fixup commits detected in the PR branch (not allowed):"
echo "$COMMITS"
echo "Please see https://ardupilot.org/dev/docs/submitting-patches-back-to-master.html"
exit 1
else
echo "✅ No fixup commits found in the PR branch."
fi
# require a well-formed subsystem tag before ":" in each commit message:
while IFS= read x; do
# strip leading hash from oneline format
subject="${x#* }"
# extract everything before the first colon
prefix="${subject%%:*}"
if [[ "$prefix" == "$subject" ]]; then
echo "❌ Commit message ($x) missing subsystem tag on front. Re-word your commit to reflect what subsystem it changes. E.g. 'AP_Compass: Added driver for XYZZY' (https://ardupilot.org/dev/docs/submitting-patches-back-to-master.html)"
exit 1
fi
# spaces and quotes are allowed to support Revert commits e.g. 'Revert "AP_Periph: ...'
if ! [[ "$prefix" =~ ^[A-Za-z0-9._/\ \"-]+$ ]]; then
echo "❌ Commit message ($x) has malformed subsystem tag '$prefix'. The subsystem prefix must contain only letters, digits, dots, underscores, slashes, hyphens, spaces, and quotes. E.g. 'AP_Compass: Added driver for XYZZY' (https://ardupilot.org/dev/docs/submitting-patches-back-to-master.html)"
exit 1
fi
done <<< $COMMITS
echo "✅ Commit messages have well-formed subsystem tags."
- name: Lint changed markdown files
shell: bash
run: |
# Get list of added or modified markdown files in the PR
CHANGED_MD=$(git diff --name-only --diff-filter=AM upstream/${{ github.event.pull_request.base.ref }}...HEAD -- '*.md')
if [[ -z "$CHANGED_MD" ]]; then
echo "✅ No markdown files changed."
exit 0
fi
echo "Changed markdown files:"
echo "$CHANGED_MD"
# Install markdownlint-cli2 (older version compatible with container's Node.js)
apt-get update && apt-get install -y npm
npm install -g markdownlint-cli2@0.4.0
# Lint the changed files
if markdownlint-cli2 $CHANGED_MD; then
echo "✅ Markdown files pass linting."
else
echo "❌ Markdown linting errors found."
exit 1
fi
# check that no commit subject line exceeds 160 characters:
while IFS= read -r line; do
if [[ ${#line} -gt 160 ]]; then
echo "❌ Commit subject line exceeds 160 characters:"
echo "$line"
echo "Please keep the commit subject line to 160 characters or fewer."
exit 1
fi
done <<< "$COMMITS"
echo "✅ All commit subject lines are within 160 characters."