Skip to content
Snippets Groups Projects
Verified Commit a4ddf570 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: move from devenv to nix flake

parent 3d2ada5c
No related branches found
No related tags found
No related merge requests found
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "run-extended-tests" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_header "Running extended tests"
echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir
setup_go_env
echo_step "Running tests"
if ! ${pkgs'.go}/bin/go test -tags "runOnTask" -cover ./...
then
echo_fail "Failed to run tests"
exit 1
fi
echo_ok "All tests passed"
echo_step "Running benchmarks"
if ! ${pkgs'.go}/bin/go test -tags "runOnTask,bench" -bench ./...
then
echo_fail "Failed to run benchmarks"
exit 1
fi
echo_ok "Benchmarks passed"
echo_step "Running race tests"
if ! ${pkgs'.go}/bin/go test -tags "runOnTask,race" -race ./...
then
echo_fail "Failed to run race tests"
exit 1
fi
echo_ok "race tests passed"
echo_step "Running fuzz tests"
if ! ${pkgs'.go}/bin/go test -tags "runOnTask,fuzz" -fuzz ./...
then
echo_fail "Failed to run fuzz tests"
exit 1
fi
echo_ok "Fuzz tests passed"
echo_ok "All tests passed"
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "run-tests" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_header "Running tests"
echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir
setup_go_env
echo_section "Select test to run"
selection=$(${pkgs'.gum}/bin/gum choose "run all tests" "run specific test" "Cancel")
if [[ "$selection" == "Cancel" ]]; then
echo_ok "Exiting."
exit 0
fi
if [[ -f "assets/test.env" ]]; then
echo_hint "Loading test environment variables"
set -a
source "assets/test.env"
set +a
fi
if [[ "$selection" == "run all tests" ]]; then
echo_ok "Running all tests"
if ! CGO_CFLAGS="-Wno-format-security" ${pkgs'.go}/bin/go test -tags runOnTask -v -failfast ./...
then
echo_fail "ERROR: Tests failed, check your Go!"
exit 1
fi
echo_ok "All tests passed!"
exit 0
fi
test_files=$(${pkgs'.findutils}/bin/find . -name "*_test.go")
test_names=""
for file in $test_files; do
names=$(${pkgs'.gnugrep}/bin/grep -oP 'func (Test\w+)' $file | ${pkgs'.gawk}/bin/gawk '{print $2}')
test_names+="$names "
done
if [[ -z "$test_names" ]]; then
echo_fail "No tests found!"
exit 1
fi
selected_tests=$(echo "$test_names" | ${pkgs'.coreutils}/bin/tr ' ' '\n' | ${pkgs'.gum}/bin/gum filter --no-limit )
if [[ -z "$selected_tests" ]]; then
echo_ok "No tests selected, exiting."
exit 0
fi
if ! CGO_CFLAGS="-Wno-format-security" ${pkgs'.go}/bin/go test -tags runOnTask -run "$(echo $selected_tests)"
then
echo_fail "ERROR: Tests failed, check your Go!"
exit 1
fi
echo_ok "All tests passed!"
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "update-changelog" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_section "Update Changelog"
echo_hint "This script will update the changelog."
echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir
echo_step "Updating changelog"
CHANGELOG_PATH="./CHANGELOG.md"
latestDocumentedVersion=$(${pkgs'.gnugrep}/bin/grep '## \[' $CHANGELOG_PATH | sed -E 's/## \[([0-9]+\.[0-9]+\.[0-9]+).*/\1/' | head -1)
if [ -z "$latestDocumentedVersion" ]; then
echo_fail "Could not find latest documented version in changelog"
echo_hint "Please add a version entry in the file $CHANGELOG_PATH"
exit 1
fi
currentVersion=$(${pkgs'.version}/bin/version print -g)
if [ "$latestDocumentedVersion" = "$currentVersion" ]; then
echo_ok "changelog already up to date"
else
tags=$(${pkgs'.git}/bin/git tag --sort=creatordate)
tags_array=($tags)
position=$(${pkgs'.coreutils}/bin/printf "%s\n" "''${tags_array[@]}" | ${pkgs'.gnugrep}/bin/grep -n "^$latestDocumentedVersion$" | ${pkgs'.coreutils}/bin/cut -d: -f1)
if [ -z "$position" ]; then
echo_fail "Could not find latest documented version in git tags"
echo_hint "Please check the git tags"
exit 1
fi
next_position=$((position + 1))
if [ $next_position -le ''${#tags_array[@]} ]; then
next_tag=''${tags_array[''$next_position - 1]}
else
echo_fail "Could not find next tag"
echo_hint "Please check the git tags"
exit 1
fi
echo_step "Generating changelog"
tmpChangelog=$(${pkgs'.mktemp}/bin/mktemp)
if ! ${pkgs'.git-chglog}/bin/git-chglog --config ./.config/chglog/config.yml -o $tmpChangelog $next_tag..
then
echo_fail "git-chglog failed"
${pkgs'.coreutils}/bin/rm $tmpChangelog
exit 1
fi
newChanges=$(${pkgs'.coreutils}/bin/cat $tmpChangelog)
${pkgs'.coreutils}/bin/rm $tmpChangelog
if [ -n "$newChanges" ]; then
${pkgs'.gnused}/bin/sed -i '/^# Changelog/d' $CHANGELOG_PATH
${pkgs'.coreutils}/bin/mv $CHANGELOG_PATH ''${CHANGELOG_PATH}.old
echo -e "# Changelog\n\n" > $CHANGELOG_PATH
echo "$newChanges" >> $CHANGELOG_PATH
${pkgs'.coreutils}/bin/cat "''${CHANGELOG_PATH}.old" >> $CHANGELOG_PATH
${pkgs'.coreutils}/bin/rm ''${CHANGELOG_PATH}.old
echo_ok "changelog updated"
fi
fi
echo_ok "Change log updated"
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "update-inputs" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_header "Update inputs"
echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir
echo_section "Updating inputs for the following packages:"
selection=$(${pkgs'.gum}/bin/gum choose --no-limit "Version")
exitCode=$?
if [[ $exitCode -ne 0 ]]; then
echo_ok "Exiting."
exit 0
fi
packages=($selection)
echo "Updating inputs for the following packages: ''${packages[@]}"
if [[ "''${packages[@]}" == "" || $exitCode -ne 0 ]]; then
echo_ok "Exiting."
exit 0
fi
for package in "''${packages[@]}"; do
echo_step "$package updating"
## pck is the package name (to lower with flake suffix
pck=$(echo "$package" | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')
if ! ${pkgs'.nix}/bin/nix flake lock --update-input "$pck"Flake; then
echo_fail "$package failed to update"
else
echo_ok "$package updated"
fi
done
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "update-manual-summary" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_section "Update manual summary"
echo_hint "This script will update the SUMMARY.md file with the files in the manual directory."
echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir
echo_step "Updating summary file..."
doc_dir="documentation/manual/de/source/"
summary_file="''${doc_dir}SUMMARY.md"
echo "# Summary" > "$summary_file"
echo "" >> "$summary_file"
extract_first_h1() {
local file_path="$1"
${pkgs'.gnused}/bin/sed -n '/^# /{
s/^# //;
s/[()]//g;
s/\\n//g;
s/\\r//g;
s/\\t//g;
p;
q;
}' "$file_path"
}
generate_summary() {
local path="$1"
local indent="$2"
local rel_path="''${path#$doc_dir}"
for item in "$path"/*; do
if [ -d "$item" ]; then
# Es ist ein Verzeichnis#
dirname=$(${pkgs'.coreutils}/bin/basename "$item")
md_files=$(${pkgs'.findutils}/bin/find "$item" -maxdepth 1 -type f -name '*.md')
subdir_count=$(${pkgs'.findutils}/bin/find "$item" -mindepth 1 -maxdepth 1 -type d | wc -l)
if [ ! -z "$md_files" ] || [ $subdir_count -gt 0 ]; then
main_doc=$(${pkgs'.findutils}/bin/find "$item" -maxdepth 1 -type f \( -name 'index.md' -o -name 'README.md' \) | ${pkgs'.coreutils}/bin/head -n 1)
if [ -n "$main_doc" ]; then
main_doc_filename=$(${pkgs'.coreutils}/bin/basename "$main_doc")
echo "''${indent}* [''${dirname^}](''${rel_path#/}/''${dirname}/''${main_doc_filename})" >> "$summary_file"
else
echo "''${indent}* [''${dirname^}]()" >> "$summary_file"
fi
generate_summary "$item" "''${indent} "
fi
elif [[ "$item" == *.md ]]; then
filename=$(${pkgs'.coreutils}/bin/basename "$item")
title="''${filename%.*}"
h1=$(extract_first_h1 "$item")
if [ -n "$h1" ]; then
title="$h1"
fi
echo "''${indent}* [''${title}](''${rel_path#/}/''${filename})" >> "$summary_file"
fi
done
}
generate_summary "$doc_dir" ""
## remopve all lines with imprint.md and privacy.md and 404.md
${pkgs'.gnused}/bin/sed -i '/\(imprint\.md\|privacy\.md\|404\.md\|SUMMARY.md\)/d' "$summary_file"
echo "---" >> "$summary_file"
echo "* [imprint](imprint.md)" >> "$summary_file"
echo_ok "SUMMARY.md updated successfully."
echo_hint "Use task watch-manual to check the manual for errors."
echo_hint "Please check the file for correctness and commit the changes."
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "update-project" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_header "Update project"
echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir
currentVersion=$(${pkgs'.version}/bin/version print -e -g)
currentHash=$(${pkgs'.git}/bin/git rev-parse HEAD)
echo_step "Write project version"
export VERSION=$currentVersion
export COMMIT=$currentHash
export NAME=$(basename $(pwd) | sed 's/./\U&/' | sed 's/-//g')
export MNEMONIC=$(echo $NAME | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]//g')
${pkgs'.envsubst}/bin/envsubst < ./nix/config/release.nix.template > ./nix/config/release.nix
echo_step "Formatting Nix code"
if ! ${pkgs'.alejandra}/bin/alejandra flake.nix ./nix/scripts/*.nix ./nix/config/*.nix ./nix/packages/*nix
then
echo_fail "alejandra formatting failed"
exit 1
fi
echo_step "change working directory to source"
setup_go_env
echo_step "Formatting Go code"
if ! ${pkgs'.findutils}/bin/find . -type f -name '*.go' ! -path './vendor/*' -print0 | xargs -0 gofmt -s -w
then
echo_fail "go fmt failed"
exit 1
fi
echo_step "Add license headers"
if ! ${pkgs'.addlicense}/bin/addlicense -c "schukai GmbH" -s -l "proprietary" $(${pkgs'.fd}/bin/fd --extension go --exclude models/ --exclude vendor --exclude embedded/)
then
echo_fail "addlicense failed"
exit 1
fi
export NIX_CFLAGS_COMPILE=" -Wno-error=format-security"
echo_step "Running go-licenses"
readonly defaultPacke=$(awk -F ' ' '/^module / { print $2 }' ./go.mod)
${pkgs'.go-licenses}/bin/go-licenses save "$defaultPacke" -v2 --ignore "gitlab.schukai.com" --force --save_path ./documentation/licenses/
echo_step "Running go vet"
if ! ${pkgs'.go}/bin/go vet .
then
echo_fail "go vet failed"
exit 1
fi
echo_step "Running go mod tidy"
if ! ${pkgs'.go}/bin/go mod tidy
then
echo_fail "go mod tidy failed"
exit 1
fi
echo_step "Running lint"
if ! ${pkgs'.golangci-lint}/bin/golangci-lint run .
then
echo_fail "lint failed"
exit 1
fi
echo_step "Running gosec"
if ! ${pkgs'.gosec}/bin/gosec -quiet .
then
echo_fail "gosec failed"
exit 1
fi
''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment