build: Makefile, pre-commit hook

This commit is contained in:
2024-08-19 16:00:16 +03:00
committed by Chen Asraf
parent 6a5b16aad5
commit ea98b042e6
7 changed files with 88 additions and 11 deletions

View File

@@ -7,3 +7,8 @@ trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[Makefile]
tab_width = 8
indent_size = 8
indent_style = tab

View File

@@ -21,7 +21,7 @@ jobs:
sudo apt install zsh -y
- name: Run Tests
run: ./test
run: make test
release:
needs:
- test

View File

@@ -20,4 +20,4 @@ jobs:
sudo apt install zsh -y
- name: Run Tests
run: ./test
run: make test

44
Makefile Normal file
View File

@@ -0,0 +1,44 @@
# Makefile for running common project tasks
# The default target to run when no arguments are given
.PHONY: all
all: help
# Run the test script
.PHONY: test
test:
./test
# Update snapshots by running the update_snapshot.zsh script
.PHONY: update-snapshots
update-snapshots:
./tests/update_snapshot.zsh
# Update the README by running the update_readme_help.zsh script
.PHONY: update-readme
update-readme:
./tools/update_readme_help.zsh
# Install the pre-commit hook
.PHONY: install-pre-commit
install-pre-commit:
@echo "Installing pre-commit hook..."
@echo "#!/usr/bin/env zsh\nmake test" > .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "Pre-commit hook installed"
# Clean
.PHONY: clean
clean:
rm -f .git/hooks/pre-commit
# Display help
.PHONY: help
help:
@echo "Usage:"
@echo " make test # Run the test script"
@echo " make update-snapshots # Run the update_snapshot.zsh script"
@echo " make update-readme # Run the update_readme_help.zsh script"
@echo " make install-pre-commit # Install the pre-commit hook"
@echo " make clean # Clean"

View File

@@ -17,19 +17,23 @@ git open file .gitignore # open specific file URL
You can always use `git open` without arguments to see the list of possible options:
<!--HELP_OUTPUT_START-->
```sh
git open
Usage: git open [-s] <command>
Usage: git open <command>
Commands:
project|repo|open|. Open the project
branch Open the project at given (or current) branch
commit Open the project at given (or current) commit
file Open the project at given file. Can also append ref hash
prs Open the PR list
pr Open a new PR
actions|pipelines|ci Open the CI/CD pipelines
project|repo|repository|open|. Open the project
branch Open the project at given (or current) branch
commit Open the project at given (or current) commit
file Open the project at given file. Can also append ref hash
prs|mrs Open the PR list
pr|mr Open a new PR
actions|pipelines|ci Open the CI/CD pipelines
Flags:
-s, --silent Silent mode (no output)
```
<!--HELP_OUTPUT_END-->
## Installation

View File

@@ -1,4 +1,6 @@
#!/usr/bin/env zsh
snap="${0:A:h}/snapshot.txt"
echo "Updating snapshot $snap"
. "${0:A:h}/../git-open.zsh" > $snap
echo "Snapshot updated"

22
tools/update_readme_help.zsh Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/zsh
file="README.md"
helpfile="${0:A:h}/../tests/snapshot.txt"
tmpfile=$(mktemp)
help="$(cat $helpfile)"
echo "Updating help in $file"
# Write content up to and including the <!--HELP_OUTPUT_START--> tag
sed -n '/<!--HELP_OUTPUT_START-->/q;p' "$file" >> "$tmpfile"
echo "<!--HELP_OUTPUT_START-->" >> "$tmpfile"
# Append the content of the $help variable
echo "\`\`\`sh\n$help\n\`\`\`" >> "$tmpfile"
# Append content from the <!--HELP_OUTPUT_END--> tag onwards
sed -n '/<!--HELP_OUTPUT_END-->/,$p' "$file" >> "$tmpfile"
mv "$tmpfile" "$file"
echo "Help updated"