Skip to content
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
29 changes: 29 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

# This scripts checks if the generated file is commited together with files that it is generated from.

if git diff-index --cached --name-only HEAD | grep -i "^templates/.*$" >/dev/null; then
if ! git diff-index --cached --name-only HEAD | grep -i "^generate/zz_filesystem_generated.go$" >/dev/null; then
echo "WARNING: You are about to commit changes to the templates directory," \
"but the generated generate/zz_filesystem_generated.go file is not staged."
echo "If this is intentional use '--no-verify' flag."
exit 1
fi
fi

if git diff-index --cached --name-only HEAD | grep -i "^generate/zz_filesystem_generated.go$" >/dev/null; then
UNVERSIONED=$(git ls-files --others --exclude-standard --ignored -- templates/ 2>/dev/null)
if [ -n "$UNVERSIONED" ]; then
echo "WARNING: You are about to commit generate/zz_filesystem_generated.go," \
"but the templates directory contains some unversioned files" \
"that may be unintentionally included in generate/zz_filesystem_generated.go"
for f in $UNVERSIONED; do
echo " $f"
done
echo "If this is intentional use '--no-verify' flag."
exit 1
fi
fi

exit 0

40 changes: 7 additions & 33 deletions docs/CONTRIBUTING.md → CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

This document details how to get started contributing to the project. This includes building and testing the core, templates and how to update them, and usage of the optional integration testing tooling.

**Tip**:
Install git hooks that do basic pre-commit checks.

```sh
make setup-githooks
```

## Building

To build the core project, run `make` from the repository root. This will result in a `func` binary being generated. Run `make help` for additional targets and `./func help` for usage-centric documentation.
Expand Down Expand Up @@ -33,39 +40,6 @@ It is also important to run the unit tests of the template modified.
For example, to run the unit tests of the Go templates, use `make test-go`.
For a list of available make targets, use `make help`.

**Tip**:
Put the following script in your `.git/hooks/pre-commit` file.

```sh
#!/bin/sh

if git diff-index --cached --name-only HEAD | grep -i "^templates/.*$" >/dev/null; then
if ! git diff-index --cached --name-only HEAD | grep -i "^generate/zz_filesystem_generated.go$" >/dev/null; then
echo "WARNING: You are about to commit changes to the templates directory," \
"but the generated generate/zz_filesystem_generated.go file is not staged."
echo "If this is intentional use '--no-verify' flag."
exit 1
fi
fi

if git diff-index --cached --name-only HEAD | grep -i "^generate/zz_filesystem_generated.go$" >/dev/null; then
UNVERSIONED=$(git ls-files --others --exclude-standard --ignored -- templates/ 2>/dev/null)
if [ -n "$UNVERSIONED" ]; then
echo "WARNING: You are about to commit generate/zz_filesystem_generated.go," \
"but the templates directory contains some unversioned files" \
"that may be unintentionally included in generate/zz_filesystem_generated.go"
for f in $UNVERSIONED; do
echo " $f"
done
echo "If this is intentional use '--no-verify' flag."
exit 1
fi
fi

exit 0

```

## Integration Testing

*Integration tests are run automatically* for all pull requests from within the GitHub Pull Request. This process includes creating and configuring a lightweight cluster.
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,7 @@ test-hack:
.PHONY: update-builder
__update-builder: # Used in automation
cd hack && go run ./cmd/update-builder

.PHONY: setup-githooks
setup-githooks:
git config --local core.hooksPath .githooks/
Loading