Skip to content

Commit 13674c6

Browse files
authored
Feat ci (#6)
* 👷(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 * 👷(lint) add lint jobs in github actions workflows * 👷(lint-and-format) apply pre-commit rules to check files linting and format * 👷(lint) test lint files * 🚧(ci) debug lint-and-format * 🚧(ci) debug lint-and-format * 🐛(ci) fix lint-and-format pre-commit hooks Now they run on all files * 🐛(ci) replace scripts shebang with bash run on all files now * 👷(ci) test push-on-main
1 parent 7249b36 commit 13674c6

File tree

6 files changed

+132
-4
lines changed

6 files changed

+132
-4
lines changed

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
lint-and-format:
49+
name: Lint and Format Check
50+
runs-on: ubuntu-latest
51+
steps:
52+
- uses: actions/checkout@v4
53+
- name: Build dev image
54+
run: make build-dev
55+
- name: Run pre-commit hooks
56+
run: ./bin/git-pre-commit-hook
57+
build:
58+
name: Build All Services
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v4
62+
- name: Build all services
63+
run: make build

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Post-merge validation
2+
#todo: delete test-main
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+
lint-and-format:
50+
name: Lint and Format Check
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- name: Build dev image
55+
run: make build-dev
56+
- name: Run pre-commit hooks
57+
run: ./bin/git-pre-commit-hook
58+
build:
59+
name: Build All Services
60+
runs-on: ubuntu-latest
61+
steps:
62+
- uses: actions/checkout@v4
63+
- name: Build all services
64+
run: make build

bin/cz

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
cz --config dev/pyproject.toml "$@"

bin/git-commit-msg-hook

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
# read commit message
44
MESSAGE=$(cat "$1")

bin/git-pre-commit-hook

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
declare DOCKER_USER
44
DOCKER_USER="$(id -u):$(id -g)"
@@ -8,4 +8,4 @@ DOCKER_USER=${DOCKER_USER} docker compose \
88
--no-TTY \
99
--rm \
1010
dev \
11-
bash -c "cd dev && uv run pre-commit run"
11+
bash -c "cd dev && uv run pre-commit run --all-files"

src/notebook/hello_csp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, CSP!")

0 commit comments

Comments
 (0)