Skip to content

Commit ee731f4

Browse files
authored
Merge pull request #37 from tangkong/tst_tests
TST: add a simple gha workflow for running pre-commit
2 parents 289f8b4 + 8ed1870 commit ee731f4

File tree

3 files changed

+89
-9
lines changed

3 files changed

+89
-9
lines changed

.github/workflows/standard.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: PCDS pre-commit Testing
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types:
8+
- created
9+
10+
jobs:
11+
pre_commit:
12+
uses: pcdshub/pcds-ci-helpers/.github/workflows/pre-commit.yml@master
13+
with:
14+
args: "--all-files"
15+
16+
test:
17+
name: "Python 3.12: pip"
18+
runs-on: ubuntu-latest
19+
20+
defaults:
21+
run:
22+
# The following allows for each run step to utilize ~/.bash_profile
23+
# for setting up the per-step initial state.
24+
# --login: a login shell. Source ~/.bash_profile
25+
# -e: exit on first error
26+
# -o pipefail: piped processes are important; fail if they fail
27+
shell: bash --login -eo pipefail {0}
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
submodules: 'recursive'
34+
35+
- name: Check version to be built
36+
run: |
37+
# NOTE: If you run CI on your own fork, you may not have the right version
38+
# number for the package. Synchronize your tags with the upstream,
39+
# otherwise cross-dependencies may result in confusing build failure.
40+
(echo "Package version: $(git describe --tags)" | tee "$GITHUB_STEP_SUMMARY") || \
41+
echo "::warning::Git tags not found in repository. Build may fail!"
42+
43+
- name: Check environment variables for issues
44+
run: |
45+
echo "* Package to be built: pre-commit"
46+
47+
- name: Prepare for log files
48+
run: |
49+
mkdir $HOME/logs
50+
51+
- uses: actions/setup-python@v5
52+
with:
53+
python-version: "3.12"
54+
55+
- name: Upgrade pip
56+
run: |
57+
pip install --upgrade pip
58+
59+
- name: Install package
60+
run: |
61+
python -m pip install .
62+
63+
- name: Check the pip packages in the test env
64+
run: |
65+
pip list
66+
67+
- name: Run tests
68+
run: |
69+
pytest -v \
70+
--log-file="$HOME/logs/debug_log.txt" \
71+
--log-format='%(asctime)s.%(msecs)03d %(module)-15s %(levelname)-8s %(threadName)-10s %(message)s' \
72+
--log-file-date-format='%H:%M:%S' \
73+
--log-level=DEBUG \
74+
2>&1 | tee "$HOME/logs/pytest_log.txt"

pre_commit_hooks/check_fixed_library_versions.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ def check_file(filename):
2424
non_fixed_library_versions = added_libraries - fixed_version_libraries
2525

2626
if len(non_fixed_library_versions) == 1:
27-
raise PreCommitException((
28-
f"Library version of {list(non_fixed_library_versions)[0]} is "
29-
f"not fixed! File parsed: {filename}"
30-
))
27+
raise PreCommitException(
28+
(
29+
f"Library version of {list(non_fixed_library_versions)[0]} is "
30+
f"not fixed! File parsed: {filename}"
31+
)
32+
)
3133
elif len(non_fixed_library_versions) > 1:
32-
raise PreCommitException((
33-
f"Library version of {', '.join(non_fixed_library_versions)} "
34-
f"are not fixed! File parsed: {filename}"
35-
))
34+
raise PreCommitException(
35+
(
36+
f"Library version of {', '.join(non_fixed_library_versions)} "
37+
f"are not fixed! File parsed: {filename}"
38+
)
39+
)
3640

3741

3842
def main(args=None):

pre_commit_hooks/check_twincat_versions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def main(args=None):
4646
if args is None:
4747
parser = argparse.ArgumentParser()
4848
parser.add_argument(
49-
"filenames", nargs="+", help="List of tsproj and tspproj filenames to process."
49+
"filenames",
50+
nargs="+",
51+
help="List of tsproj and tspproj filenames to process.",
5052
)
5153
parser.add_argument(
5254
"--target-version", type=str, help="Target TwinCAT version to enforce."

0 commit comments

Comments
 (0)