Skip to content

Commit a1320b2

Browse files
committed
PSMDB-1786: add github workflow for format check
1 parent 511b209 commit a1320b2

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "Common setup"
2+
description: "Shared setup steps for the workflows"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Export env
8+
shell: bash
9+
run: |
10+
ARCH=$(echo $(uname -m) | sed -e 's:i686:i386:g')
11+
OS_CODE_NAME="$(lsb_release -sc)"
12+
echo "ARCH=${ARCH}" >> $GITHUB_ENV
13+
echo "OS_CODE_NAME=${OS_CODE_NAME}" >> $GITHUB_ENV
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
id: setup-python
18+
with:
19+
python-version: "3.11"
20+
cache: "pip"
21+
cache-dependency-path: etc/pip/dev-requirements.txt
22+
23+
- name: Install Python deps
24+
shell: bash
25+
if: steps.venv.outputs.cache-hit != 'true'
26+
run: |
27+
python3 -m pip install -r etc/pip/dev-requirements.txt
28+
29+
- name: Toolchain cache
30+
uses: actions/cache@v4
31+
id: toolchain
32+
with:
33+
path: /opt/mongodbtoolchain/v4
34+
key: toolchain-${{ env.OS_CODE_NAME }}-${{ env.ARCH }}
35+
36+
- name: Install toolchain
37+
shell: bash
38+
if: steps.toolchain.outputs.cache-hit != 'true'
39+
run: |
40+
curl -O https://downloads.percona.com/downloads/packaging/toolchain_installer.tar.gz
41+
tar -zxvf toolchain_installer.tar.gz
42+
bash -x ./installer.sh -k --download-url https://downloads.percona.com/downloads/packaging/${OS_CODE_NAME}_mongodbtoolchain_${ARCH}.tar.gz
43+
curl -O https://s3.amazonaws.com/boxes.10gen.com/build/eslint-8.28.0-linux-x86_64.tar.gz
44+

.github/workflows/format.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: format
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, labeled, unlabeled]
6+
7+
permissions:
8+
contents: read
9+
security-events: write
10+
11+
jobs:
12+
analyze:
13+
name: Check code formatting
14+
runs-on: ubuntu-latest
15+
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci-skip-format') }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup environment
21+
uses: ./.github/actions/setup-env
22+
23+
- name: Run linters
24+
run: |
25+
echo "Running clang-format"
26+
buildscripts/clang_format.py format
27+
echo "Running python formatters"
28+
buildscripts/pylinters.py fix
29+
echo "Running python scons formatter"
30+
buildscripts/pylinters.py fix-scons
31+
echo "Running javascript formatters"
32+
buildscripts/eslint.py fix
33+
34+
- name: Verify formatting
35+
run: |
36+
if ! git diff --quiet; then
37+
echo "::error::Formatting issues detected."
38+
echo ""
39+
echo "Your PR is not properly formatted."
40+
echo ""
41+
echo "To fix the problem locally, run:"
42+
echo ""
43+
echo " bazel run format"
44+
echo ""
45+
echo "and commit the resulting changes."
46+
echo ""
47+
echo "Affected files:"
48+
git diff --stat
49+
echo "Diff:"
50+
git diff | head -n 1000
51+
exit 1
52+
fi

0 commit comments

Comments
 (0)