Style Checker and Pre-commit hook CI #187
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pre-commit check | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize, labeled] | |
concurrency: | |
group: pre-commit-${{github.event.pull_request.number || github.ref}} | |
cancel-in-progress: true | |
jobs: | |
lint: | |
#if: ${{ contains(github.event.pull_request.labels.*.name, 'Status: Pending Merge') }} | |
name: Run pre-commit hooks | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout latest commit | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 2 | |
- name: Set up Python 3 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
- name: Set up Homebrew | |
id: set-up-homebrew | |
uses: Homebrew/actions/setup-homebrew@master | |
- name: Get Python version hash | |
run: | | |
echo "Using $(python -VV)" | |
echo "PY_HASH=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV | |
- name: Restore pre-commit cache | |
uses: actions/cache/restore@v4 | |
id: restore-cache | |
with: | |
path: | | |
~/.cache/pre-commit | |
~/.cache/pip | |
key: pre-commit|${{ env.PY_HASH }}|${{ hashFiles('.pre-commit-config.yaml', '.github/workflows/pre-commit.yml') }} | |
- name: Install dependencies | |
run: | | |
sudo apt update | |
sudo apt-get install -y cppcheck | |
brew tap oclint/formulae | |
brew install oclint | |
python -m pip install pre-commit docutils | |
echo "source .github/scripts/install-arduino-cli.sh" >> ~/install.sh | |
echo "source .github/scripts/install-arduino-core-esp32.sh" >> ~/install.sh | |
bash ~/install.sh | |
- name: Wait on other jobs to finish | |
uses: lucasssvaz/wait-on-workflow@v1 | |
id: wait-on-jobs | |
continue-on-error: true | |
with: | |
workflow: push.yml | |
max-wait: 5 | |
interval: 30 | |
timeout: 120 | |
sha: ${{ github.event.pull_request.head.sha || github.sha }} | |
- name: Download compilation artifacts | |
uses: actions/download-artifact@v4 | |
if: ${{ steps.wait-on-jobs.outputs.run-id != '' }} | |
with: | |
pattern: build-job-* | |
merge-multiple: true | |
path: ~/.arduino/tests/ | |
run-id: ${{ steps.wait-on-jobs.outputs.run-id }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Merge compile commands | |
if: ${{ steps.wait-on-jobs.outputs.run-id != '' }} | |
run: | | |
find ~/.arduino/tests/ -iname "compile_commands.json" | xargs jq -s 'map(.[])' > ~/compile_commands.json | |
- name: Upload compile commands | |
if: ${{ steps.wait-on-jobs.outputs.run-id != '' }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: compile_commands | |
path: ~/compile_commands.json | |
- name: Get changed files | |
id: changed-files | |
uses: tj-actions/[email protected] | |
- name: Run pre-commit hooks in changed files | |
run: pre-commit run --color=always --show-diff-on-failure --files ${{ steps.changed-files.outputs.all_changed_files }} | |
- name: Run oclint | |
run: oclint-json-compilation-database -p ~/compile_commands.json oclint_args ${{ steps.changed-files.outputs.all_changed_files }} | |
- name: Save pre-commit cache | |
uses: actions/cache/save@v4 | |
if: ${{ always() && steps.restore-cache.outputs.cache-hit != 'true' }} | |
continue-on-error: true | |
with: | |
path: | | |
~/.cache/pre-commit | |
~/.cache/pip | |
key: ${{ steps.restore-cache.outputs.cache-primary-key }} | |
- name: Push changes using pre-commit-ci-lite | |
uses: pre-commit-ci/[email protected] | |
if: always() |