Skip to content

Hooks fixes and improvements from feedback #2990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* text=auto
* text=auto eol=lf

# Unity assets are always serialized using lf endings
LightingData.asset binary
Expand Down
2 changes: 1 addition & 1 deletion Tools/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
default_stages: [commit]
repos:
- repo: git@github.cds.internal.unity3d.com:theo-penavaire/gfx-automation-tools.git
rev: 3b07dd9872a652b6170b9031d42e997714733314
rev: 892e7fb
hooks:
- id: file-extension-to-lowercase
- id: check-shader-includes
Expand Down
39 changes: 31 additions & 8 deletions Tools/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [Tools](#tools)
- [Git-hooks](#git-hooks)
- [Installation](#installation)
- [Available hooks](#available-hooks)
- [FAQ and Troubleshooting steps](#faq-and-troubleshooting-steps)
- [Formatting](#formatting)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Tools

_Questions: #devs-graphics-automation_
Expand All @@ -12,17 +25,15 @@ For example, compliance with Unity's code convention is mandatory in order to me

Follow these steps to install the git hooks before working on the Graphics repository:

1. Requirement A: Install [Python >= 3.5](https://www.python.org/downloads/) and make sure it is accessible in your PATH.
2. Requirement B: Install [pip3](https://pip.pypa.io/en/stable/installing/).
3. Requirement C: Make sure [unity-meta](https://internaldocs.hq.unity3d.com/unity-meta/setup/) is installed and its requirements are fulfilled. It will be used by the format code hook to ensure your code complies with the convention. _Sidenote: it is the same tool used to format C++/trunk code._
4. Requirement D: Make sure you have access to the cds.github.com repositories. Usually this means following [these steps](https://docs.github.com/en/enterprise-server@2.21/github/authenticating-to-github/connecting-to-github-with-ssh) to create and upload an ssh key to [cds.github.com](https://github.cds.internal.unity3d.com/settings/keys).
1. Install [Python >= 3.6](https://www.python.org/downloads/) and make sure it is accessible in your PATH.
2. Install [pip3](https://pip.pypa.io/en/stable/installing/).
3. Make sure [unity-meta](https://internaldocs.hq.unity3d.com/unity-meta/setup/) is installed and its requirements are fulfilled. It will be used by the format code hook to ensure your code complies with the convention. _Sidenote: it is the same tool used to format C++/trunk code._
4. Make sure you have access to the cds.github.com repositories. Usually this means following [these steps](https://docs.github.com/en/enterprise-server@2.21/github/authenticating-to-github/connecting-to-github-with-ssh) to create and upload an ssh key to [cds.github.com](https://github.cds.internal.unity3d.com/settings/keys).
5. From the root of the repository, run `cd Tools` and `python3 ./hooks_setup.py`.

Note: If you already installed the git hooks (before November 2020), you need to follow the steps above to re-install them. This is required in order to move towards a more scalable and flexible system. _Sidenote: NodeJS and the node_modules folder are no longer required._

### Available hooks

A description of the hooks we currently have is available in the [hooks' library repository](https://github.cds.internal.unity3d.com/theo-penavaire/gfx-automation-tools#available-git-hooks).
A description of the hooks we currently have is available in the [hooks library repository](https://github.cds.internal.unity3d.com/theo-penavaire/gfx-automation-tools#available-git-hooks).

For this repository we have enabled:

Expand Down Expand Up @@ -76,7 +87,7 @@ Last resort: [Troubleshooting SSH section in Github docs](https://docs.github.co

**Python or pre-commit not found, even if python is installed, "/usr/bin/env: ‘python’: Permission denied"**

Make sure Python (>=3.5) is in your PATH. Commands that can help:
Make sure Python (>=3.6) is in your PATH. Commands that can help:
- On windows: `where python3`
- On Unix: `which python3`
- [How to add to the path on Windows10?](https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/)
Expand All @@ -102,3 +113,15 @@ Follow the suggestions of [this StackOverflow answer](https://stackoverflow.com/
**Can't locate Win32/Process.pm in @INC...**

On Windows, Active perl is not supported by the formatting tool. Use Strawberry perl.

## Formatting

Provided you installed [unity-meta](https://internaldocs.hq.unity3d.com/unity-meta/setup/), you can manually run the formatting tool with the following command (use powershell on windows):
```
perl ~/unity-meta/Tools/Format/format.pl --hgroot $(pwd) --dry-run <folder to format>
```
To actually apply the changes:
```
perl ~/unity-meta/Tools/Format/format.pl --hgroot $(pwd) --nobackups <folder to format>
```
Use `--help` to discover more useful options (`--preview` will generate a diff file for instance)