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
Showing with 845 additions and 828 deletions
source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0="
use devenv
\ No newline at end of file
watch_file ./flake.nix ./nix/scripts/*.nix ./nix/config/*.nix ./nix/packages/*.nix
use flake
\ No newline at end of file
# THIS FILE IS AUTOGENERATED BY THE DEVENVSHELL
# DO NOT EDIT THIS FILE MANUALLY
# INSTEAD EDIT THE DEVENVSHELL CONFIGURATION FILE devenv.nix
# AND OPEN A SHELL WITH THE COMMAND devenv shell
#
image: docker-registry.schukai.com:443/nixos-ci-devenv:latest
variables:
# The repo name as used in
# https://github.com/nix-community/NUR/blob/master/repos.json
NIXOS_VERSION: "23.05"
NIXPKGS_ALLOW_UNFREE: "1"
NIXPKGS_ALLOW_INSECURE: "1"
GIT_DEPTH: 10
GIT_SUBMODULE_STRATEGY: normal
GIT_SUBMODULE_DEPTH: 1
stages:
- test
- deploy
- release
before_script:
- echo > .env-gitlab-ci
- variables=("HOME=$HOME" "CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME" "CI_REPOSITORY_URL=$CI_REPOSITORY_URL" "GITLAB_TOKEN=$GITLAB_TOKEN" "CI_JOB_TOKEN=$CI_JOB_TOKEN" "GITLAB_USER_EMAIL=$GITLAB_USER_EMAIL" "GITLAB_USER_NAME=\"$GITLAB_USER_NAME\"" "CI_REGISTRY_USER=$CI_REGISTRY_USER" "CI_PROJECT_ID=$CI_PROJECT_ID" "CI_PROJECT_DIR=$CI_PROJECT_DIR" "CI_API_V4_URL=$CI_API_V4_URL" "CI_PROJECT_NAME=$CI_PROJECT_NAME" "CI_COMMIT_SHORT_SHA=$CI_COMMIT_SHORT_SHA"); for var in "${variables[@]}"; do echo "$var" >> .env-gitlab-ci; done
- cat .env-gitlab-ci
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME:-"Gitlab CI"}"
- git config --global credential.helper '!f() { echo "username=gitlab-ci-token"; echo "password=${CI_JOB_TOKEN}"; }; f'
- git config --global pull.rebase true
- git config --global http.sslVerify "false"
after_script:
- if [ -f .env-gitlab-ci ]; then rm .env-gitlab-ci; fi
- nix develop .#gitlab --command clean-up
test:
tests:
stage: test
tags:
- nixos
- nixos-gen3
script:
- devenv shell test-lib
cache:
- key: nixos
paths:
- /nix/store
- nix develop .#gitlab --command run-ci-tests
artifacts:
paths:
- dist
- last-phpunit-result.xml
deploy:
stage: deploy
release:
stage: release
tags:
- nixos
- nixos-gen3
script:
- devenv shell -c deploy-lib
- nix develop .#gitlab --command release
when: on_success
cache:
- key: nixos
paths:
- /nix/store
rules:
- if: $CI_COMMIT_BRANCH == "master"
\ No newline at end of file
# THIS FILE IS AUTOGENERATED BY THE DEVENVSHELL
# DO NOT EDIT THIS FILE MANUALLY
# INSTEAD EDIT THE DEVENVSHELL CONFIGURATION FILE devenv.nix
# AND OPEN A SHELL WITH THE COMMAND devenv shell
#
# Information about the task runner can be found here:
# https://taskfile.dev
version: '3'
tasks:
default:
cmds:
- task --list
silent: true
test:
desc: Execute unit tests in Go.
env:
TEST_BY_TASK: true
cmds:
- echo "Execute unit tests in Go."
- gosec .
- go test -tags=runOnTask -cover -v ./...
- go test -tags=runOnTask -bench -v ./...
- go test -tags=runOnTask -race -v ./...
test-fuzz:
desc: Conduct fuzzing tests.#
env:
TEST_BY_TASK: true
cmds:
- echo "Conduct fuzzing tests."
- go test -tags=runOnTask -v -fuzztime=30s -fuzz=Fuzz ./...
add-licenses:
desc: Attach license headers to Go files.
cmds:
- echo "Attach license headers to Go files."
- go install github.com/google/addlicense@latest
- addlicense -c "schukai GmbH" -s -l "AGPL-3.0" ./*.go
silent: true
check-licenses:
desc: Check license headers of Go files.
silent: true
cmds:
- go-licenses save "$(get-go-default-packages)" --ignore "gitlab.schukai.com" --force --save_path ${DEVENV_ROOT}/licenses/
check:
desc: Confirm repository status.
cmds:
- git diff-index --quiet HEAD || (echo "There are uncommitted changes after running make. Please commit or stash them before running make."; exit 1)
silent: true
commit:
desc: Commit changes to the repository.
aliases:
- c
- ci
- git-commit
cmds:
- do-git-commit
This diff is collapsed.
inputs:
nixpkgs:
url: github:nixos/nixpkgs/nixos-23.11
version:
url: git+https://gitlab.schukai.com/oss/utilities/version.git
flake: true
{
"nodes": {
"devenv": {
"commonFlake": {
"inputs": {
"nixpkgs": "nixpkgs"
},
"locked": {
"dir": "src/modules",
"lastModified": 1698243190,
"narHash": "sha256-n+SbyNQRhUcaZoU00d+7wi17HJpw/kAUrXOL4zRcqE8=",
"owner": "cachix",
"repo": "devenv",
"rev": "86f476f7edb86159fd20764489ab4e4df6edb4b6",
"type": "github"
"dir": "common",
"lastModified": 1718788884,
"narHash": "sha256-PefMbkGNMK9TN1qcNL9OkFVTNdv6wo6XoaS8eTdsY04=",
"ref": "refs/heads/master",
"rev": "abda2dc723e13dfc835535593321c514666e679e",
"revCount": 39,
"type": "git",
"url": "https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git?dir=common"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
"dir": "common",
"type": "git",
"url": "https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git?dir=common"
}
},
"flake-compat": {
"flake": false,
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
"id": "flake-utils",
"type": "indirect"
}
},
"flake-utils": {
"flakeUtils": {
"inputs": {
"systems": "systems"
"systems": "systems_2"
},
"locked": {
"lastModified": 1685518550,
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
"lastModified": 1726560853,
"narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
"rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a",
"type": "github"
},
"original": {
......@@ -51,107 +55,94 @@
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"nixpkgs": {
"locked": {
"lastModified": 1660459072,
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
"lastModified": 1714971268,
"narHash": "sha256-IKwMSwHj9+ec660l+I4tki/1NRoeGpyA2GdtdYpAgEw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "27c13997bf450a01219899f5a83bd6ffbfc70d3c",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
"id": "nixpkgs",
"ref": "nixos-23.11",
"type": "indirect"
}
},
"nixpkgs": {
"nixpkgsUnstable": {
"locked": {
"lastModified": 1702346276,
"narHash": "sha256-eAQgwIWApFQ40ipeOjVSoK4TEHVd6nbSd9fApiHIw5A=",
"lastModified": 1727348695,
"narHash": "sha256-J+PeFKSDV+pHL7ukkfpVzCOO7mBSrrpJ3svwBFABbhI=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "cf28ee258fd5f9a52de6b9865cdb93a1f96d09b7",
"rev": "1925c603f17fc89f4c8f6bf6f631a802ad85d784",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-23.11",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"nixpkgs_2": {
"locked": {
"lastModified": 1685801374,
"narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=",
"owner": "NixOS",
"lastModified": 1727397532,
"narHash": "sha256-pojbL/qteElw/nIXlN8kmHn/w6PQbEHr7Iz+WOXs0EM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "c37ca420157f4abc31e26f436c1145f8951ff373",
"rev": "f65141456289e81ea0d5a05af8898333cab5c53d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05",
"owner": "nixos",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"nixpkgs_3": {
"locked": {
"lastModified": 1698288402,
"narHash": "sha256-jIIjApPdm+4yt8PglX8pUOexAdEiAax/DXW3S/Mb21E=",
"lastModified": 1704145853,
"narHash": "sha256-G/1AMt9ibpeMlcxvD1vNaC8imGaK+g7zZ99e29BLgWw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "60b9db998f71ea49e1a9c41824d09aa274be1344",
"rev": "2d2ea8eab9e400618748ab1a6a108255233b602c",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-23.05",
"ref": "nixos-23.11",
"type": "indirect"
}
},
"pre-commit-hooks": {
"root": {
"inputs": {
"flake-compat": "flake-compat",
"commonFlake": "commonFlake",
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
"flakeUtils": "flakeUtils",
"nixpkgs": "nixpkgs_2",
"nixpkgsUnstable": "nixpkgsUnstable",
"versionFlake": "versionFlake"
}
},
"systems": {
"locked": {
"lastModified": 1698227354,
"narHash": "sha256-Fi5H9jbaQLmLw9qBi/mkR33CoFjNbobo5xWdX4tKz1Q=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "bd38df3d508dfcdff52cd243d297f218ed2257bf",
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks",
"version": "version"
}
},
"systems": {
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
......@@ -166,16 +157,16 @@
"type": "github"
}
},
"version": {
"versionFlake": {
"inputs": {
"nixpkgs": "nixpkgs_2"
"nixpkgs": "nixpkgs_3"
},
"locked": {
"lastModified": 1690668568,
"narHash": "sha256-jzixQKFFW4oxO0S4GYqbkFCXzhBd6com6Z9+MtVKakU=",
"lastModified": 1716914109,
"narHash": "sha256-JY0PLGWzYRDQ9daKLGOBWHHuYun9nSpH9J3aSk8iDmQ=",
"ref": "refs/heads/master",
"rev": "3838f03165b726e47d586c04a1821749375e1001",
"revCount": 37,
"rev": "fe8dd932d6c414a93b4a69c470792b2db038e0fb",
"revCount": 129,
"type": "git",
"url": "https://gitlab.schukai.com/oss/utilities/version.git"
},
......
flake.nix 0 → 100644
{
description = "HTTP-Negotiate is a library that provides a simple way to negotiate HTTP requests.";
inputs = {
nixpkgs = {url = "github:nixos/nixpkgs/nixos-24.05";};
nixpkgsUnstable = {url = "github:nixos/nixpkgs/nixos-unstable";};
flakeUtils = {url = "github:numtide/flake-utils";};
commonFlake = {
url = "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git?dir=common";
flake = true;
};
versionFlake = {
url = "git+https://gitlab.schukai.com/oss/utilities/version.git";
flake = true;
};
};
outputs = {
self,
nixpkgs,
nixpkgsUnstable,
flake-utils,
versionFlake,
commonFlake,
...
} @ inputs:
flake-utils.lib.eachDefaultSystem (system: let
inherit (nixpkgs.lib) optional;
commonPck = commonFlake.packages.${system}.common;
versionPck = versionFlake.packages.${system}.version;
pkgs' = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
common = commonPck;
})
(final: prev: {
version = versionPck;
})
(final: prev: {
dolt =
(import nixpkgsUnstable {
inherit system;
})
.dolt;
})
];
};
in {
packages = rec {
manual = pkgs'.callPackage ./nix/packages/manual.nix {inherit self pkgs';};
};
devShells = {
default = let
commonPck = commonFlake.packages.${system}.common;
commonScript = commonPck + "/bin/common";
versionPck = versionFlake.packages.${system}.version;
versionBin = versionPck + "/bin/version";
scriptGoTask = import ./nix/scripts/go-task.nix {inherit self pkgs' system;};
commonPackages = import ./nix/config/common-packages.nix {inherit pkgs';};
extendedPackages = [
scriptGoTask
];
scriptPackages = [
versionPck
];
shellPackages =
commonPackages
++ extendedPackages
++ scriptPackages;
in
pkgs'.mkShell {
nativeBuildInputs = shellPackages;
shellHook = ''
source ${commonScript}
if [ -n "$CI_JOB_TOKEN" ]; then
echo_fail "You are in a CI environment, this shell is not intended for CI, but for local development"
exit 1
fi
echo_header "Configuration Lib development shell"
readonly worktree=$(get_working_dir)
echo_hint "Working directory: ''${worktree}"
currentVersion=$(${versionBin} print -g)
if [ -z "''${currentVersion}" ]; then
echo_fail "No version found, check your git tags"
else
echo_hint "Current version: ''${currentVersion}"
fi
currentGitBranch=$(git rev-parse --abbrev-ref HEAD)
echo_hint "Current branch: ''${currentGitBranch}"
echo_hint "You can run the task command to see the available tasks"
echo_section "Happy hacking!"
'';
};
gitlab = let
commonPck = commonFlake.packages.${system}.common;
commonScript = commonPck + "/bin/common";
versionPck = versionFlake.packages.${system}.version;
scriptCleanUp = pkgs'.callPackage ./nix/scripts/clean-up.nix {inherit pkgs';};
scriptRunCITests = pkgs'.callPackage ./nix/scripts/run-ci-tests.nix {inherit pkgs';};
scriptRelease = pkgs'.callPackage ./nix/scripts/release.nix {inherit pkgs';};
commonPackages = import ./nix/config/common-packages.nix {inherit pkgs';};
extendedPackages = [
scriptCleanUp
scriptRunCITests
scriptRelease
];
scriptPackages = [
versionPck
];
shellPackages =
commonPackages
++ extendedPackages
++ scriptPackages;
in
pkgs'.mkShell {
nativeBuildInputs = shellPackages;
shellHook = ''
source ${commonScript}
if [ -z "$CI_JOB_TOKEN" ]; then
echo_fail "You are not in a CI environment, this shell is intended for CI, but for local development"
exit 1
fi
cd ''${CI_PROJECT_DIR} || exit 1
'';
};
};
});
}
{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.22.1";
commit = "36d6f93a8f2801323ab8a4e24826e542bfe22c5c";
projectURL = "https://gitlab.schukai.com/oss/configuration";
name = "negotiation";
mnemonic = "negotiation";
projectID = "512";
# this file is generated by nix/scripts/init-project.nix
# please don't edit it manually
}
\ No newline at end of file
{
# 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/libraries/go/network/http-negotiation";
name = "Negotiation";
mnemonic = "negotiation";
projectID = "412";
# this file is generated by nix/scripts/init-project.nix
# please don't edit it manually
}
\ No newline at end of file
{
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
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
''
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment