Repository navigation
Expand file tree
/
Copy pathgithub-actions-on-master-push.yml
More file actions
95 lines (81 loc) · 3.29 KB
/
Copy pathgithub-actions-on-master-push.yml
File metadata and controls
95 lines (81 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Fix linting, formatting, and Bazel module lock file
on:
push:
branches:
- 'master'
permissions:
contents: write
jobs:
auto-format:
name: Auto-format on push
runs-on: ubuntu-26.04
if: github.repository_owner == 'The-OpenROAD-Project'
env:
BUILDIFIER_VERSION: v8.2.1
CLANG_FORMAT_VERSION: "23.1.2"
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Install Python tools
run: |
# Separate venvs: tclint pins pathspec==0.11.2 and black >= 26
# requires pathspec >= 1.0.0, so they cannot resolve together.
python3 -m venv venv-tclint
venv-tclint/bin/pip install tclint==0.7.0
python3 -m venv venv-black
venv-black/bin/pip install black==26.10.1
python3 -m venv "$RUNNER_TEMP/clang-format"
"$RUNNER_TEMP/clang-format/bin/pip" install --quiet "clang-format==${CLANG_FORMAT_VERSION}"
- name: Cache buildifier
id: cache-buildifier
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ./buildifier
key: ${{ runner.os }}-buildifier-${{ env.BUILDIFIER_VERSION }}
- name: Download buildifier
if: steps.cache-buildifier.outputs.cache-hit != 'true'
run: |
wget https://github.com/bazelbuild/buildtools/releases/download/${BUILDIFIER_VERSION}/buildifier-linux-amd64 -O buildifier
chmod +x buildifier
- name: Auto-format
run: |
# Skip if the last commit was already an auto-format
if git log -1 --format='%s' | grep -qF 'ci: auto-format'; then
exit 0
fi
# Get files changed in the full pushed range.
changed=$(git diff --name-only "${{ github.event.before }}..${{ github.sha }}")
# Run clang-format, excluding upstream-managed directories
echo "$changed" \
| grep -E '\.(h|hh|hpp|hxx|c|cc|cpp|cxx)$' \
| grep -v '^src/sta/' \
| grep -v '^src/odb/src/codeGenerator/' \
| xargs --no-run-if-empty "$RUNNER_TEMP/clang-format/bin/clang-format" -i
# Run black on changed Python files
source venv-black/bin/activate
echo "$changed" \
| grep -E '\.py$' \
| xargs --no-run-if-empty black
deactivate
# Run buildifier on changed Bazel files
echo "$changed" \
| grep -E '(BUILD|WORKSPACE|\.bzl|\.bazel)$' \
| xargs --no-run-if-empty ./buildifier -lint=fix
# Run tclfmt on changed Tcl files
source venv-tclint/bin/activate
echo "$changed" \
| grep -E '\.tcl$' \
| grep -v '^src/sta/' \
| xargs --no-run-if-empty tclfmt --in-place
deactivate
# Commit if any diffs were created
if [ -n "$(git diff --name-only)" ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git diff --name-only | xargs git add --
git commit -m "ci: auto-format [skip ci]"
git push
echo "Auto-format committed fixes and pushed."
fi