|
| 1 | +name: Code Lint and Format Check |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main # Trigger on push to 'main' |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main # Trigger on PR to 'main' |
| 10 | + - 8.0-dev |
| 11 | + |
| 12 | +# Workflow permissions |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + lint-format: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout Code |
| 23 | + uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Read Bazel version from .bazelversion |
| 28 | + id: bazel-version |
| 29 | + run: echo "version=$(cat .bazelversion)" >> $GITHUB_OUTPUT |
| 30 | + |
| 31 | + - name: Set up Python |
| 32 | + uses: actions/setup-python@v5 |
| 33 | + with: |
| 34 | + python-version: '3.10' |
| 35 | + |
| 36 | + - name: Install Python dependencies |
| 37 | + run: | |
| 38 | + python -m pip install --upgrade pip |
| 39 | + pip install black==24.4.2 flake8==7.0.0 isort==5.13.2 |
| 40 | +
|
| 41 | + - name: Set up Bazel |
| 42 | + uses: bazel-contrib/setup-bazel@0.15.0 |
| 43 | + with: |
| 44 | + bazelisk-cache: true |
| 45 | + disk-cache: ${{ github.workflow }} |
| 46 | + bazel-version: ${{ steps.bazel-version.outputs.version }} |
| 47 | + |
| 48 | + - name: Install C++ (Clang-Format), Shell (Shellcheck) and Buildifier |
| 49 | + run: | |
| 50 | + sudo apt-get update |
| 51 | + # Install clang-format version from .pre-commit-config.yaml |
| 52 | + sudo apt-get install -y clang-format-18 shellcheck |
| 53 | +
|
| 54 | + # Install Buildifier using Go |
| 55 | + # Todo(zero): different from ".pre-commit-config.yaml" |
| 56 | + go install github.com/bazelbuild/buildtools/buildifier@latest |
| 57 | + echo "$HOME/go/bin" >> $GITHUB_PATH |
| 58 | +
|
| 59 | + - name: Run Lint and Format Checks (PR Diff Mode) |
| 60 | + if: github.event_name == 'pull_request' |
| 61 | + run: | |
| 62 | + echo "Running apollo_lint.sh in diff mode for PR..." |
| 63 | + ${{ github.workspace }}/scripts/ci/apollo_lint.sh --all --diff origin/${{ github.base_ref }} |
| 64 | + env: |
| 65 | + GITHUB_BASE_REF: ${{ github.base_ref }} |
| 66 | + |
| 67 | + - name: Run Lint and Format Checks (Push Full Mode) |
| 68 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 69 | + run: | |
| 70 | + echo "Running apollo_lint.sh in full mode for push to main branch..." |
| 71 | + ${{ github.workspace }}/scripts/ci/apollo_lint.sh --all |
0 commit comments