Skip to content

Style Checker and Pre-commit hook CI #146

Style Checker and Pre-commit hook CI

Style Checker and Pre-commit hook CI #146

Workflow file for this run

name: Pre-commit check
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
concurrency:
group: pre-commit-${{ github.head_ref || github.ref_name }}
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: Wait for jobs to be created
run: sleep 120
- name: Wait for other jobs to finish
uses: lewagon/[email protected]
with:
ref: ${{ github.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
running-workflow-name: Run pre-commit hooks
check-regexp: Arduino [0-9]+ on ubuntu-latest
wait-interval: 30
- 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: 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: Get workflow id
run: |
RUNID=$(gh api repos/${{github.event.pull_request.head.repo.full_name}}/commits/${{github.event.pull_request.head.sha}}/check-runs | \
jq -r '.check_runs[] | \
select(.name == "Arduino 0 on ubuntu-latest") | \
.html_url | \
capture("/runs/(?<number>[0-9]+)/jobs") | \
.number' | \
sed 's/"//g' | \
head -n 1)
echo "WORKFLOW_ID = $RUNID"
- name: Download compilation artifacts
uses: actions/download-artifact@v4
if: ${{ env.WORKFLOW_ID != null }}
with:
pattern: build-job-*
merge-multiple: true
path: ~/.arduino/tests/
run-id: ${{ env.WORKFLOW_ID }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Merge compile commands
if: ${{ steps.check-artifact.outputs.exists == 'true' }}
run: |
find ~/.arduino/tests/ -iname "compile_commands.json" | xargs jq -s 'map(.[])' > ~/compile_commands.json
- name: Upload compile commands
if: ${{ steps.check-artifact.outputs.exists == 'true' }}
uses: actions/upload-artifact@v4
with:
name: compile_commands
path: ~/compile_commands.json
- name: Install python dependencies
run: python -m pip install pre-commit docutils
- 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: 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()