Skip to content

Commit 6b3a1d6

Browse files
committed
Remove unwanted files from PR
1 parent 53fc122 commit 6b3a1d6

4 files changed

Lines changed: 220 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
# Run a given command in every directory that contains cargo workspace
3+
# Right now it just scans for `Cargo.lock`
4+
5+
set -euo pipefail
6+
7+
git ls-files | grep -E '(^|/)Cargo.lock' | while read -r path ; do
8+
(
9+
cd "$(dirname "$path")"
10+
"$@"
11+
)
12+
done

misc/git-hooks/commit-msg

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
# Sanitize file first, by removing leading lines that are empty or start with a hash,
3+
# as `convco` currently does not do it automatically (but git will)
4+
# TODO: next release of convco should be able to do it automatically
5+
MESSAGE="$(
6+
while read -r line ; do
7+
# skip any initial comments (possibly from previous run)
8+
if [ -z "${body_detected:-}" ] && { [[ "$line" =~ ^#.*$ ]] || [ "$line" == "" ]; }; then
9+
continue
10+
fi
11+
body_detected="true"
12+
13+
echo "$line"
14+
done < "$1"
15+
)"
16+
17+
# convco fails on fixup!, so remove fixup! prefix
18+
MESSAGE="${MESSAGE#fixup! }"
19+
if ! convco check --from-stdin <<<"$MESSAGE" ; then
20+
>&2 echo "Please follow conventional commits(https://www.conventionalcommits.org)"
21+
>&2 echo "Use git commit <args> to fix your commit"
22+
exit 1
23+
fi

misc/git-hooks/pre-commit

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#
2+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
3+
#
4+
#!/usr/bin/env bash
5+
6+
set -euo pipefail
7+
8+
set +e
9+
git diff-files --quiet
10+
is_unclean=$?
11+
set -e
12+
13+
# Revert `git stash` on exit
14+
function revert_git_stash {
15+
>&2 echo "Unstashing uncommitted changes..."
16+
git stash pop -q
17+
}
18+
19+
# Stash pending changes and revert them when script ends
20+
if [ -z "${NO_STASH:-}" ] && [ $is_unclean -ne 0 ]; then
21+
>&2 echo "Stashing uncommitted changes..."
22+
GIT_LITERAL_PATHSPECS=0 git stash -q --keep-index
23+
trap revert_git_stash EXIT
24+
fi
25+
26+
export FLAKEBOX_GIT_LS
27+
if [ -z "${FLAKEBOX_GIT_LS_IGNORE:-}" ]; then
28+
FLAKEBOX_GIT_LS="$(git ls-files | while read -r file; do [ ! -L "$file" ] && echo "$file"; done)"
29+
else
30+
FLAKEBOX_GIT_LS="$(git ls-files | grep -v -E "${FLAKEBOX_GIT_LS_IGNORE}" | while read -r file; do [ ! -L "$file" ] && echo "$file"; done)"
31+
fi
32+
33+
export FLAKEBOX_GIT_LS_TEXT
34+
if [ -z "${FLAKEBOX_GIT_LS_TEXT_IGNORE:-}" ]; then
35+
FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico|gif)\$")"
36+
else
37+
FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico|gif)\$" | grep -v -E "${FLAKEBOX_GIT_LS_TEXT_IGNORE}")"
38+
fi
39+
40+
41+
function check_nothing() {
42+
true
43+
}
44+
export -f check_nothing
45+
46+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
47+
function check_cargo_fmt() {
48+
set -euo pipefail
49+
50+
flakebox-in-each-cargo-workspace cargo fmt --all --check
51+
}
52+
export -f check_cargo_fmt
53+
54+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
55+
function check_cargo_lock() {
56+
set -euo pipefail
57+
58+
# https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5
59+
flakebox-in-each-cargo-workspace cargo update --workspace --locked -q
60+
}
61+
export -f check_cargo_lock
62+
63+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
64+
function check_leftover_dbg() {
65+
set -euo pipefail
66+
67+
errors=""
68+
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do
69+
if grep 'dbg!(' "$path" > /dev/null; then
70+
>&2 echo "$path contains dbg! macro"
71+
errors="true"
72+
fi
73+
done
74+
75+
if [ -n "$errors" ]; then
76+
>&2 echo "Fix the problems above or use --no-verify" 1>&2
77+
return 1
78+
fi
79+
}
80+
export -f check_leftover_dbg
81+
82+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
83+
function check_nixfmt() {
84+
set -euo pipefail
85+
86+
# we actually rely on word splitting here
87+
# shellcheck disable=SC2046
88+
nixfmt -c $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep "\.nix$")
89+
}
90+
export -f check_nixfmt
91+
92+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
93+
function check_shellcheck() {
94+
set -euo pipefail
95+
96+
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do
97+
shellcheck --severity=warning "$path"
98+
done
99+
}
100+
export -f check_shellcheck
101+
102+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
103+
function check_trailing_newline() {
104+
set -euo pipefail
105+
106+
errors=""
107+
for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do
108+
109+
# extra branches for clarity
110+
if [ ! -f "$path" ] || [ ! -s "$path" ]; then
111+
# echo "$path is not a file or is empty"
112+
true
113+
elif [ -z "$(tail -c 1 < "$path")" ]; then
114+
# echo "$path ends with a newline or with a null byte"
115+
true
116+
else
117+
>&2 echo "$path doesn't end with a newline" 1>&2
118+
errors="true"
119+
fi
120+
done
121+
122+
if [ -n "$errors" ]; then
123+
>&2 echo "Fix the problems above or use --no-verify" 1>&2
124+
return 1
125+
fi
126+
}
127+
export -f check_trailing_newline
128+
129+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
130+
function check_trailing_whitespace() {
131+
set -euo pipefail
132+
133+
rev="HEAD"
134+
if ! git rev-parse -q 1>/dev/null HEAD 2>/dev/null ; then
135+
>&2 echo "Warning: no commits yet, checking against --root"
136+
rev="--root"
137+
fi
138+
if ! git diff --check $rev ; then
139+
>&2 echo "Trailing whitespace detected. Please remove them before committing."
140+
return 1
141+
fi
142+
}
143+
export -f check_trailing_whitespace
144+
145+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
146+
function check_typos() {
147+
set -euo pipefail
148+
149+
if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude ; then
150+
>&2 echo "Typos found: Valid new words can be added to '.typos.toml'"
151+
return 1
152+
fi
153+
}
154+
export -f check_typos
155+
156+
parallel \
157+
--nonotice \
158+
::: \
159+
check_cargo_fmt \
160+
check_cargo_lock \
161+
check_leftover_dbg \
162+
check_nixfmt \
163+
check_shellcheck \
164+
check_trailing_newline \
165+
check_trailing_whitespace \
166+
check_typos \
167+
check_nothing
168+
#
169+
# NOTE: THIS FILE IS AUTO-GENERATED BY FLAKEBOX
170+
#

misc/update.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
# remove all build hashes from nix flake
4+
sed -i 's/\(^\ *hash = \)"\(sha256-.\+\)";$/\1"";/' flake.nix
5+
echo -e "\033[42;30m updating dependencies\033[0m"
6+
nix flake update
7+
cargo update
8+
pnpm update
9+
echo -e "\033[42;30mupdating package hashes, this might take a while ...\033[0m"
10+
NEW_HASH=$(nix build |& awk '/got/{print $NF}')
11+
sed -i "s/\(^\ *hash = \)\"\";\$/\1\"$NEW_HASH\";/" flake.nix
12+
echo -e "\033[42;30mvalidating build\033[0m"
13+
nix build
14+
echo -e "\033[42;30mstaging git changes\033[0m"
15+
git add Cargo.lock flake.lock flake.nix package.json pnpm-lock.yaml

0 commit comments

Comments
 (0)