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

fix: move to flake.nix

parent 9dc4020f
Branches
Tags
No related merge requests found
Showing
with 903 additions and 63 deletions
This project is covered by two different licenses: MIT and Apache.
#### MIT License ####
The following files were ported to Go from C files of libyaml, and thus
are still covered by their original MIT license, with the additional
copyright staring in 2011 when the project was ported over:
apic.go emitterc.go parserc.go readerc.go scannerc.go
writerc.go yamlh.go yamlprivateh.go
Copyright (c) 2006-2010 Kirill Simonov
Copyright (c) 2006-2011 Kirill Simonov
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
### Apache License ###
All the remaining project files are covered by the Apache license:
Copyright (c) 2011-2019 Canonical Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Copyright 2011-2016 Canonical Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
{pkgs'}:
with pkgs'; let
php = pkgs.php83.buildEnv {
extensions = {
enabled,
all,
}:
enabled ++ (with all; [memcached xdebug]);
};
in [
alejandra
blackbox
coreutils-full
curl
d2
dbeaver-bin
delve
dialog
dive
drill
eza
fd
feh
gcc12
gdlv
git
gitty
glab
gnugrep
gnumake
gnused
go
go-licenses
go-migrate
golangci-lint
google-fonts
gosec
graphviz
grpc
gum
httpie
hurl
jq
libffi
logrotate
mdbook
mdbook-admonish
mdbook-cmdrun
mdbook-d2
mdbook-emojicodes
mdbook-graphviz
mdbook-linkcheck
mdbook-mermaid
mdbook-pdf
mdbook-plantuml
meld
memcached
netcat
nghttp2
nodePackages.mermaid-cli
openssh
pandoc-katex
plantuml
procps
ranger
roboto
unixtools.xxd
unzip
util-linux
vhs
wget
zlib
]
{
}
{
# this file is generated by nix/scripts/init-project.nix
# please don't edit it manually
version = "1.16.2";
commit = "9dc4020fe6d8ef683ab3c6c82588e64db901ecb0";
projectURL = "https://gitlab.schukai.com/oss/configuration";
name = "xflags";
mnemonic = "xflags";
projectID = "418";
# this file is generated by nix/scripts/init-project.nix
# please don't edit it manually
}
{
# this file is generated by nix/scripts/init-project.nix
# please don't edit it manually
version = "$VERSION";
commit = "$COMMIT";
projectURL = "https://gitlab.schukai.com/oss/configuration";
name = "xflags";
mnemonic = "xflags";
projectID = "418";
# this file is generated by nix/scripts/init-project.nix
# please don't edit it manually
}
{
pkgs',
system,
self,
...
}: let
releaseInfo = import ../config/release.nix;
in
derivation {
name = "manual";
version = releaseInfo.version;
builder = "${pkgs'.bash}/bin/bash";
args = let
script = pkgs'.callPackage ../scripts/build-manual.nix {inherit pkgs' system;};
in ["${script}/bin/build-manual"];
buildInputs = with pkgs'; [];
system = system;
}
{pkgs', ...}: ''
convert_multiline_for_nix() {
printf "%s" "
}$1" | ${pkgs'.gnused}/bin/sed 's/\\/\\\\/g; s/"/\\"/g; s/$/\\n/g' | tr -d '\n'
}
download_test_images() {
echo_step "Downloading docker images"
if ! ${pkgs'.docker}/bin/docker images | grep atmoz/sftp | grep alpine
then
echo_step "Downloading atmoz/sftp:alpine"
if ! ${pkgs'.docker}/bin/docker pull atmoz/sftp:alpine
then
echo_fail "Failed to download atmoz/sftp:alpine"
exit 1
fi
fi
if ! ${pkgs'.docker}/bin/docker images | grep axllent/mailpit
then
echo_step "Downloading atmoz/sftp:alpine"
if ! ${pkgs'.docker}/bin/docker pull axllent/mailpit
then
echo_fail "Failed to download axllent/mailpit"
exit 1
fi
fi
}
setup_go_env() {
echo_step "Setting GO111MODULE=auto"
if ! ${pkgs'.go}/bin/go env -w GO111MODULE=auto
then
echo_fail "Failed to set GO111MODULE=auto"
exit 1
fi
}
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "build-cover-report" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_header "Building cover report"
echo_hint "The command is executed in the current working directory and not in a nix derivation."
cd_working_dir
setup_go_env
download_test_images
if [ -z "''${out}" ];
then
echo_fail "No out directory specified"
exit 1
fi
writableDir="''${out}/coverage"
if ! ${pkgs'.coreutils}/bin/mkdir -p ''${writableDir} > /dev/null 2>&1
then
write_fail "Failed to create directory ''${writableDir}"
exit 1
fi
echo_step "Running tests"
echo_section "Building"
${pkgs'.go}/bin/go test -v -coverprofile=''${writableDir}/coverage.out ./...
if [ $? -ne 0 ];
then
echo_fail "Failed to run tests"
exit 1
fi
if ! ${pkgs'.go}/bin/go tool cover -html=''${writableDir}/coverage.out -o ''${writableDir}/coverage.html
then
echo_fail "Failed to generate coverage report"
exit 1
fi
echo_ok "Coverage report stored at ''${writableDir}"
if [ -f ''${writableDir}/coverage.html ];
then
echo_fail "Coverage report not found"
exit 1
fi
echo_step "Opening coverage report in browser"
if ! ${pkgs'.xdg-utils}/bin/xdg-open ''${writableDir}/coverage.html > /dev/null 2>&1
then
echo_fail "Failed to open coverage report in browser"
exit 1
fi
echo_ok "Report opened in browser"
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
updateSummary = pkgs'.callPackage ./update-manual-summary.nix {inherit pkgs';};
in
pkgs'.writeShellScriptBin "build-manual" ''
source ${pkgs'.common}/bin/common
source ${bashFktScript}
${updateSummary}
${pkgs'.coreutils}/bin/mkdir -p $out/manual/de
cd ${../../documentation/manual/de}
${pkgs'.mdbook}/bin/mdbook build --dest-dir $out/manual .
''
{pkgs, ...}:
pkgs.writeShellScriptBin "clean-up" ''
echo "Cleaning up"
echo "Removing credentials"
${pkgs.git}/bin/git config --global --unset credential.helper
if [ -f /root/.docker/config.json ]; then ${pkgs.coreutils}/bin/rm /root/.docker/config.json; fi
if [ -f .env-gitlab-ci ]; then ${pkgs.coreutils}/bin/rm .env-gitlab-ci; fi
echo "Cleaned up"
''
{
pkgs',
system,
self,
...
}: let
scriptBuildCoverReport = pkgs'.callPackage ./build-cover-report.nix {pkgs' = pkgs';};
scriptRunTests = pkgs'.callPackage ./run-tests.nix {pkgs' = pkgs';};
scriptRunExtendedTests = pkgs'.callPackage ./run-extended-tests.nix {pkgs' = pkgs';};
scriptUpdateProject = pkgs'.callPackage ./update-project.nix {pkgs' = pkgs';};
scriptUpdateChangelog = pkgs'.callPackage ./update-changelog.nix {pkgs' = pkgs';};
taskfile = pkgs'.writeTextFile {
name = "taskfile.yml";
text = ''
version: '3'
tasks:
default:
cmds:
- task --list
silent: true
run-tests:
desc: Execute all tests.
aliases:
- a
env:
TEST_BY_TASK: true
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
cmds:
- ${scriptRunTests}/bin/run-tests
silent: true
run-extended-tests:
desc: Execute all tests including cover, bench and race tests.
aliases:
- s
env:
TEST_BY_TASK: true
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
cmds:
- ${scriptRunExtendedTests}/bin/run-extended-tests
silent: true
build-cover-report:
desc: Build coverage report.
aliases:
- d
env:
TEST_BY_TASK: true
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
cmds:
- ${scriptBuildCoverReport}/bin/build-cover-report
silent: true
update-project:
desc: Check code style, linting, and formatting.
aliases:
- e
env:
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
cmds:
- ${scriptUpdateProject}/bin/update-project
silent: true
git-commit:
desc: Commit changes.
aliases:
- f
cmds:
- ${scriptUpdateProject}/bin/update-project
- cd "{{.USER_WORKING_DIR}}" && cd $(${pkgs'.git}/bin/git rev-parse --show-toplevel) && nix run git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes#git-commit --no-write-lock-file
silent: true
env:
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
build-manual:
aliases:
- g
desc: Build the manual
cmds:
- cd "{{.USER_WORKING_DIR}}" && cd $(${pkgs'.git}/bin/git rev-parse --show-toplevel) && ${pkgs'.nix}/bin/nix build .#manual --no-write-lock-file
silent: true
watch-doc:
aliases:
- l
desc: Build and watch the documentation (http://localhost:3000)
cmds:
- cd "{{.USER_WORKING_DIR}}" && cd $(${pkgs'.git}/bin/git rev-parse --show-toplevel) && ${pkgs'.mdbook}/bin/mdbook serve documentation/manual/de
silent: true
update-changelog:
aliases:
- j
desc: Update the changelog
cmds:
- ${scriptUpdateChangelog}/bin/update-changelog
silent: true
env:
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
tool-dbeaver:
aliases:
- k
- dbeaver
desc: Open DBeaver
cmds:
- cd "{{.USER_WORKING_DIR}}" && cd $(${pkgs'.git}/bin/git rev-parse --show-toplevel) && ${pkgs'.dbeaver-bin}/bin/dbeaver -data .temp/dbeaver -con "driver=mysql|host=localhost|port=3306|user=root|password=secret" 2>&1 > /dev/null
silent: true
env:
USER_WORKING_DIR: "{{.USER_WORKING_DIR}}"
'';
};
in
pkgs'.writeShellScriptBin "task" ''
${pkgs'.go-task}/bin/task -t "${taskfile}" "$@"
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
updateChangelogScript = import ./update-changelog.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "release" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_header "Release "
if [ -z "$CI_REPOSITORY_URL" ]; then
echo_fail "Error: CI_REPOSITORY_URL environment variable is not set."
exit 1
fi
if [ -z "$CI_PROJECT_DIR" ]; then
echo_fail "Error: CI_PROJECT_DIR environment variable is not set."
exit 1
fi
cd $CI_PROJECT_DIR || exit 1
${pkgs'.git}/bin/git remote set-url origin https://''${CI_REPOSITORY_URL#*@}
${pkgs'.git}/bin/git fetch --all --tags --unshallow
${pkgs'.git}/bin/git reset --hard origin/master
${pkgs'.git}/bin/git clean -fd
${pkgs'.git}/bin/git checkout $CI_COMMIT_REF_NAME
${pkgs'.git}/bin/git pull origin $CI_COMMIT_REF_NAME
if ! ${pkgs'.git}/bin/git --no-pager log --decorate=short --pretty=oneline -n 30
then
echo_fail "Error: Could not get git log."
exit 1
fi
${pkgs'.git}/bin/git fetch --prune --prune-tags
echo_step "Bumping version"
gitVersion=$(${pkgs'.version}/bin/version predict --exit-code-if-no-bump)
if [ -z "$gitVersion" ]; then
echo_ok "There is no version bump."
echo_ok "done"
exit 0
fi
gitVersion=v$gitVersion
echo_step "Write project version"
export VERSION=$gitVersion
export COMMIT="$CI_COMMIT_SHA"
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
${pkgs'.git}/bin/git tag -a $gitVersion -m"chore: bump version to $gitVersion"
${updateChangelogScript}/bin/update-changelog
cd $CI_PROJECT_DIR || exit 1
${pkgs'.git}/bin/git tag -d "$gitVersion"
${pkgs'.git}/bin/git commit -m "chore: release $gitVersion" CHANGELOG.md ./nix/config/release.nix
${pkgs'.git}/bin/git tag -a $gitVersion -m"chore: bump version to $gitVersion"
${pkgs'.git}/bin/git --no-pager log --decorate=short --pretty=oneline -n 5
${pkgs'.git}/bin/git remote set-url origin https://pad:''${GITLAB_TOKEN}@''${CI_REPOSITORY_URL#*@}
${pkgs'.git}/bin/git push -o ci.skip origin "$CI_COMMIT_REF_NAME" --tags
echo_ok "done"
''
{pkgs', ...}: let
bashFktScript = import ./bash-fkt.nix {
inherit pkgs';
};
in
pkgs'.writeShellScriptBin "run-ci-tests" ''
source ${pkgs'.common}/bin/common
${bashFktScript}
echo_header "Running CI tests"
setup_go_env
if [[ -f "assets/test.env" ]]; then
echo_hint "Loading test environment variables"
set -a
source "assets/test.env"
set +a
fi
echo_section "Running tests"
cd ${./../..} || (echo_fail "Failed to cd to application source" && exit 1)
if ! CGO_CFLAGS="-Wno-format-security" ${pkgs'.go}/bin/go test -tags "runOnTask" ./...
then
echo_fail "Failed to run tests"
exit 1
fi
''
{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