Skip to content

Commit 0734887

Browse files
authored
Feat ci (#4)
* 👷(ci) add commit-format job * 👷(ci) separate squash check in post-merge workflow * 💚(pr-on-main) fix commit-format error on merge commit * 💄(ci) improve logs * 👷(ci) test workflow post-merge * 💚(ci) roll back to post merge only on main * 👷(build) check dev and notebook services build * 👷(build) separate squash and commit format in two jobs
1 parent 7249b36 commit 0734887

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

.github/workflows/pr-on-main.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Pull Request Validation
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
types: [ opened, synchronize, reopened ]
7+
8+
jobs:
9+
commit-format:
10+
name: Check Commit Format
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
with:
16+
fetch-depth: 0
17+
ref: ${{ github.head_ref }} # Checkout the PR branch without merging
18+
- name: Check single commit and format
19+
run: |
20+
# Get all PR commits
21+
BASE_SHA=$(git merge-base origin/main HEAD)
22+
COMMITS=$(git rev-list --reverse $BASE_SHA..HEAD)
23+
echo "Commits in this PR:"
24+
25+
# Commit message schema regex
26+
SCHEMA_REGEX="^(🎨|⚡️|🔥|🐛|🚑️|✨|📝|🚀|💄|🎉|✅|🔒️|🔐|🔖|🚨|🚧|💚|⬇️|⬆️|📌|👷|📈|♻️|➕|➖|🔧|🔨|🌐|✏️|💩|⏪️|🔀|📦️|👽️|🚚|📄|💥|🍱|♿️|💡|🍻|💬|🗃️|🔊|🔇|👥|🚸|🏗️|📱|🤡|🥚|🙈|📸|⚗️|🔍️|🏷️|🌱|🚩|🥅|💫|🗑️|🛂|🩹|🧐|⚰️|🧪|👔|🩺|🧱|🧑‍💻|💸|🧵|🦺|✈️)\\([a-z0-9:-]+\\) [a-z].{1,50}"
27+
28+
# Validate commit message schema
29+
INVALID_COMMITS=0
30+
for commit in $COMMITS; do
31+
MESSAGE=$(git log --format=%s -n 1 $commit)
32+
echo "$MESSAGE"
33+
34+
if ! echo "$MESSAGE" | grep -qE "$SCHEMA_REGEX"; then
35+
echo "❌ Invalid commit format: $MESSAGE"
36+
INVALID_COMMITS=$((INVALID_COMMITS + 1))
37+
fi
38+
done
39+
40+
if [ $INVALID_COMMITS -gt 0 ]; then
41+
echo "❌ $INVALID_COMMITS commit(s) with invalid format detected"
42+
echo "Required format: <emoji>(<scope>) <subject>"
43+
echo "Example: ✨(auth) add support for HTTP basic auth"
44+
exit 1
45+
fi
46+
47+
echo "✅ All commits have valid format"
48+
build:
49+
name: Build All Services
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Build all services
54+
run: make build

.github/workflows/push-on-main.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Post-merge validation
2+
3+
on:
4+
push:
5+
branches: [ main, test-main ]
6+
7+
jobs:
8+
commit-format:
9+
name: Check commits are squashed and well formatted
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: Check commits are squashed
17+
run: |
18+
# Check that only one commit was added to main
19+
PREVIOUS_COMMIT=$(git rev-parse HEAD~1)
20+
COMMITS_ADDED=$(git rev-list --count $PREVIOUS_COMMIT..HEAD)
21+
22+
echo "Previous commit: $(git rev-parse --short $PREVIOUS_COMMIT)"
23+
echo "Current commit: $(git rev-parse --short HEAD)"
24+
echo "Commits added: $COMMITS_ADDED"
25+
26+
if [ $COMMITS_ADDED -ne 1 ]; then
27+
echo "❌ Merge was not squashed! $COMMITS_ADDED commits were added to main"
28+
echo "Please use 'Squash and merge' when merging PRs"
29+
exit 1
30+
fi
31+
32+
echo "✅ Merge was properly squashed (1 commit added)"
33+
34+
- name: Check commit format
35+
run: |
36+
# Validate the commit message format
37+
MESSAGE=$(git log --format=%s -n 1 HEAD)
38+
echo "Merged commit message: $MESSAGE"
39+
40+
SCHEMA_REGEX="^(🎨|⚡️|🔥|🐛|🚑️|✨|📝|🚀|💄|🎉|✅|🔒️|🔐|🔖|🚨|🚧|💚|⬇️|⬆️|📌|👷|📈|♻️|➕|➖|🔧|🔨|🌐|✏️|💩|⏪️|🔀|📦️|👽️|🚚|📄|💥|🍱|♿️|💡|🍻|💬|🗃️|🔊|🔇|👥|🚸|🏗️|📱|🤡|🥚|🙈|📸|⚗️|🔍️|🏷️|🌱|🚩|🥅|💫|🗑️|🛂|🩹|🧐|⚰️|🧪|👔|🩺|🧱|🧑‍💻|💸|🧵|🦺|✈️)\\([a-z0-9:-]+\\) [a-z].{1,50}"
41+
42+
if ! echo "$MESSAGE" | grep -qE "$SCHEMA_REGEX"; then
43+
echo "❌ Merged commit has invalid format: $MESSAGE"
44+
echo "Required format: <emoji>(<scope>) <subject>"
45+
exit 1
46+
fi
47+
48+
echo "✅ Merged commit format is valid"
49+
build:
50+
name: Build All Services
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- name: Build all services
55+
run: make build

0 commit comments

Comments
 (0)