Skip to content

Commit 62553b1

Browse files
authored
Merge pull request #353 from riscv-software-src/precommit
Install pre-commit with setup, add GitHub action for pre-commit
2 parents 33b5934 + 52624f7 commit 62553b1

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

.github/workflows/regress.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ on:
55
- main
66
workflow_dispatch:
77
jobs:
8+
regress-pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v3
13+
- uses: pre-commit/[email protected]
814
regress-smoke:
915
runs-on: ubuntu-latest
1016
steps:

bin/python

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22

33
ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
4-
source $ROOT/setup
4+
if [ ! -v NO_SOURCE ]; then
5+
source $ROOT/setup
6+
fi
57

68
$PYTHON "$@"

bin/setup

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if [ -v DEVCONTAINER_ENV ]; then
9191
NPM="npm"
9292
NPX="npx"
9393
NODE="node"
94-
PYTHON="python3"
94+
PYTHON="${ROOT}/.home/.venv/bin/python3"
9595
PIP="${ROOT}/.home/.venv/bin/pip"
9696
BASH="bash"
9797
else
@@ -101,7 +101,33 @@ else
101101
NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm"
102102
NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx"
103103
NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node"
104-
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} python3"
104+
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/python3"
105105
PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/pip"
106106
BASH="singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
107107
fi
108+
109+
if [ ! -f $ROOT/.git/hooks/pre-commit ]; then
110+
cat << HOOK > $ROOT/.git/hooks/pre-commit
111+
#!/usr/bin/env bash
112+
# File generated by pre-commit: https://pre-commit.com
113+
# ID: 138fd403232d2ddd5efb44317e38bf03
114+
115+
# start templated
116+
INSTALL_PYTHON=$ROOT/bin/python
117+
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
118+
# end templated
119+
120+
HERE="$(cd "$(dirname "\$0")" && pwd)"
121+
ARGS+=(--hook-dir "\$HERE" -- "\$@")
122+
123+
if [ -x "\$INSTALL_PYTHON" ]; then
124+
exec "\$INSTALL_PYTHON" -mpre_commit "\${ARGS[@]}"
125+
elif command -v pre-commit > /dev/null; then
126+
exec pre-commit "\${ARGS[@]}"
127+
else
128+
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
129+
exit 1
130+
fi
131+
HOOK
132+
chmod +x $ROOT/.git/hooks/pre-commit
133+
fi

0 commit comments

Comments
 (0)