Skip to content

Commit 9890e12

Browse files
authored
Running Github Actions CI pipeline including tests also under Windows (#85)
1 parent 95e7da0 commit 9890e12

6 files changed

Lines changed: 32 additions & 19 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ on: # cf. https://github.community/t/how-to-trigger-an-action-on-push-or-pull-r
1212
jobs:
1313
check:
1414
name: Run check
15-
runs-on: ubuntu-latest
1615
strategy:
1716
fail-fast: false
1817
max-parallel: 5
1918
matrix:
2019
python-version: [3.8, 3.9, '3.10', '3.11']
21-
20+
platform: [ubuntu-latest, windows-latest]
21+
runs-on: ${{ matrix.platform }}
2222
steps:
2323
- name: Checkout code 🛎️
2424
uses: actions/checkout@v3

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
additional_dependencies:
1616
- mdformat-toc
1717
- repo: https://github.com/Lucas-C/pre-commit-hooks
18-
rev: v1.5.3
18+
rev: master
1919
hooks:
2020
- id: forbid-crlf
2121
- id: remove-crlf

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ A few useful git hooks to integrate with
44
[pre-commit](http://pre-commit.com).
55

66
⚠️ ⚠️ **This hook, since v1.5.2, requires `pre-commit` 3.2.0 or superior.**
7-
If you get an error like `Expected one of ... but got: 'pre-commit'`, check this issue: [#83](https://github.com/Lucas-C/pre-commit-hooks/issues/83)
7+
If you get an error like `Expected one of ... but got: 'pre-commit'`, check
8+
this issue: [#83](https://github.com/Lucas-C/pre-commit-hooks/issues/83)
89

910
⚠️ **The last version of this hook to support Python 2.7 & 3.6 is v1.1.15**
1011

pre_commit_hooks/chmod.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,20 @@ def main(argv=None):
3939
print(f"Incorrect octal permissions provided in configuration: {error}")
4040
return 2
4141
result = 0
42-
for filename in args.filenames:
43-
current_mode = os.stat(filename).st_mode
44-
# We ignore S_IFREG and other similar unsupported bits:
45-
current_mode &= SUPPORTED_BITS
46-
if current_mode != new_mode:
47-
print(
48-
f"Fixing file permissions on {filename}:"
49-
f" 0o{current_mode:o} -> 0o{new_mode:o}"
50-
)
51-
os.chmod(filename, new_mode)
52-
result = 1
42+
if sys.platform == "win32":
43+
print("This hook does nothing when executed on Windows")
44+
else:
45+
for filename in args.filenames:
46+
current_mode = os.stat(filename).st_mode
47+
# We ignore S_IFREG and other similar unsupported bits:
48+
current_mode &= SUPPORTED_BITS
49+
if current_mode != new_mode:
50+
print(
51+
f"Fixing file permissions on {filename}:"
52+
f" 0o{current_mode:o} -> 0o{new_mode:o}"
53+
)
54+
os.chmod(filename, new_mode)
55+
result = 1
5356
return result
5457

5558

tests/chmod_test.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
import sys
12
from pre_commit_hooks.chmod import main as chmod
23

3-
from .utils import chdir_to_test_resources
4+
from .utils import chdir_to_test_resources, capture_stdout
45

56

67
def test_chmod_ok():
78
with chdir_to_test_resources():
8-
assert chmod(["755", "module_with_license.py"]) == 1
9-
assert chmod(["644", "module_with_license.py"]) == 1
10-
assert chmod(["644", "module_with_license.py"]) == 0
9+
if sys.platform == "win32":
10+
with capture_stdout() as stdout:
11+
assert chmod(["755", "module_with_license.py"]) == 0
12+
assert (
13+
"This hook does nothing when executed on Windows" in stdout.getvalue()
14+
)
15+
else:
16+
assert chmod(["755", "module_with_license.py"]) == 1
17+
assert chmod(["644", "module_with_license.py"]) == 1
18+
assert chmod(["644", "module_with_license.py"]) == 0
1119

1220

1321
def test_invalid_perms():

0 commit comments

Comments
 (0)