Skip to content

Commit

Permalink
Running Github Actions CI pipeline including tests also under Windows (
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-C authored Aug 13, 2023
1 parent 95e7da0 commit 9890e12
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ on: # cf. https://github.community/t/how-to-trigger-an-action-on-push-or-pull-r
jobs:
check:
name: Run check
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 5
matrix:
python-version: [3.8, 3.9, '3.10', '3.11']

platform: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code 🛎️
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
additional_dependencies:
- mdformat-toc
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.3
rev: master
hooks:
- id: forbid-crlf
- id: remove-crlf
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ A few useful git hooks to integrate with
[pre-commit](http://pre-commit.com).

⚠️ ⚠️ **This hook, since v1.5.2, requires `pre-commit` 3.2.0 or superior.**
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)
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)

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

Expand Down
25 changes: 14 additions & 11 deletions pre_commit_hooks/chmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ def main(argv=None):
print(f"Incorrect octal permissions provided in configuration: {error}")
return 2
result = 0
for filename in args.filenames:
current_mode = os.stat(filename).st_mode
# We ignore S_IFREG and other similar unsupported bits:
current_mode &= SUPPORTED_BITS
if current_mode != new_mode:
print(
f"Fixing file permissions on {filename}:"
f" 0o{current_mode:o} -> 0o{new_mode:o}"
)
os.chmod(filename, new_mode)
result = 1
if sys.platform == "win32":
print("This hook does nothing when executed on Windows")
else:
for filename in args.filenames:
current_mode = os.stat(filename).st_mode
# We ignore S_IFREG and other similar unsupported bits:
current_mode &= SUPPORTED_BITS
if current_mode != new_mode:
print(
f"Fixing file permissions on {filename}:"
f" 0o{current_mode:o} -> 0o{new_mode:o}"
)
os.chmod(filename, new_mode)
result = 1
return result


Expand Down
16 changes: 12 additions & 4 deletions tests/chmod_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import sys
from pre_commit_hooks.chmod import main as chmod

from .utils import chdir_to_test_resources
from .utils import chdir_to_test_resources, capture_stdout


def test_chmod_ok():
with chdir_to_test_resources():
assert chmod(["755", "module_with_license.py"]) == 1
assert chmod(["644", "module_with_license.py"]) == 1
assert chmod(["644", "module_with_license.py"]) == 0
if sys.platform == "win32":
with capture_stdout() as stdout:
assert chmod(["755", "module_with_license.py"]) == 0
assert (
"This hook does nothing when executed on Windows" in stdout.getvalue()
)
else:
assert chmod(["755", "module_with_license.py"]) == 1
assert chmod(["644", "module_with_license.py"]) == 1
assert chmod(["644", "module_with_license.py"]) == 0


def test_invalid_perms():
Expand Down

0 comments on commit 9890e12

Please sign in to comment.