From 494f23db3309bce6f9101b72b418e547d0d0f75b Mon Sep 17 00:00:00 2001 From: luzzyzhang Date: Wed, 21 Jul 2021 12:09:29 +0800 Subject: [PATCH] ci(lint): add commit lint and format check --- .github/workflows/ci.yml | 39 +++++++++++++++++++++++++++++++++++++++ ci/run_format_check.sh | 10 ++++++++++ 2 files changed, 49 insertions(+) create mode 100755 ci/run_format_check.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08822a7a..590fc15a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,8 +6,46 @@ on: pull_request: jobs: + check-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.1 + with: + fetch-depth: 0 + - uses: actions/setup-node@v2.1.0 + - run: yarn add @commitlint/config-conventional @commitlint/cli + - run: yarn commitlint --from ${{ github.event.pull_request.base.sha }} --to HEAD + + check-format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.1 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.6 + - name: Cache pip + uses: actions/cache@v2 + with: + # This path is specific to Ubuntu + path: ~/.cache/pip + # Look to see if there is a cache hit for the corresponding requirements file + key: ${{ runner.os }}-pip-${{ hashFiles('requires.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + - name: Install dependencies + run: | + python -m pip install --upgrade pip + - name: Check format + run: | + ./ci/run_format_check.sh + cpu-test: runs-on: self-hosted + needs: [check-commit, check-format] container: image: localhost:5000/megengine-ci:latest steps: @@ -25,6 +63,7 @@ jobs: run: ./ci/run_cpp_test.sh cpu gpu-test: runs-on: self-hosted + needs: [check-commit, check-format] container: image: localhost:5000/megengine-ci:latest volumes: diff --git a/ci/run_format_check.sh b/ci/run_format_check.sh new file mode 100755 index 00000000..97d51c58 --- /dev/null +++ b/ci/run_format_check.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +pushd imperative/python >/dev/null + pip install -q -r requires.txt + pip install -q -r requires-style.txt + pip install -q -r requires-test.txt + ./scripts/format.sh -d +popd >/dev/null