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

chore: move from devenv to flake.nix #53

parent 513a0987
No related branches found
No related tags found
No related merge requests found
File moved
{ pkgs }:
pkgs.writeShellScriptBin "hello-world" ''
echo "Hello, world!"
''
source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0="
use devenv
\ No newline at end of file
watch_file $(find . -name "*.nix" -printf '"%p" ')
use flake
......@@ -13,3 +13,4 @@ smell.go
/.attach_*
.direnv/
.direnv/
.back
......@@ -37,7 +37,7 @@ test:
tags:
- nixos
script:
- devenv shell test-lib
- nix develop --command run-ci-tests
cache:
- key: nixos
......
run:
concurrency: 4
timeout: 5m
issues-exit-code: 2
tests: false
output:
show-stats: true
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# GitHub Copilot persisted chat sessions
/copilot/chatSessions
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="accountSettings">
<option name="activeProfile" value="profile:default" />
<option name="activeRegion" value="eu-west-1" />
<option name="recentlyUsedProfiles">
<list>
<option value="profile:default" />
</list>
</option>
<option name="recentlyUsedRegions">
<list>
<option value="eu-west-1" />
</list>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GoImports">
<option name="optimizeImportsOnTheFly" value="false" />
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="TsLint" enabled="true" level="WARNING" enabled_by_default="true" />
</profile>
</component>
\ No newline at end of file
......@@ -3,10 +3,7 @@
<component name="Go" enabled="true" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.devenv" />
<excludeFolder url="file://$MODULE_DIR$/.direnv" />
</content>
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettings">
<enabledExtensions>
<entry key="MermaidLanguageExtension" value="false" />
<entry key="PlantUMLLanguageExtension" value="true" />
</enabledExtensions>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="accountSettings">
<option name="activeProfile" value="profile:default" />
<option name="activeRegion" value="eu-west-1" />
<option name="recentlyUsedProfiles">
<list>
<option value="profile:default" />
</list>
</option>
<option name="recentlyUsedRegions">
<list>
<option value="eu-west-1" />
</list>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="9979eb22-471e-4f2f-b624-fd3edb5e8c6e" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.back/scripts/hello.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.golangci.yaml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/flake.lock" afterDir="false" />
<change afterPath="$PROJECT_DIR$/flake.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nix/scripts/build-cover-report.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nix/scripts/check-code.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nix/scripts/common.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nix/scripts/go-task.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nix/scripts/run-ci-tests.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nix/scripts/run-extended-tests.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/nix/scripts/run-tests.nix" afterDir="false" />
<change afterPath="$PROJECT_DIR$/schedule-time_test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.envrc" beforeDir="false" afterPath="$PROJECT_DIR$/.envrc" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitlab-ci.yml" beforeDir="false" afterPath="$PROJECT_DIR$/.gitlab-ci.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.gitignore" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/aws.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/go.imports.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/job-queues.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/job-queues.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/markdown.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Taskfile.yml" beforeDir="false" afterPath="$PROJECT_DIR$/.back/Taskfile.yml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database-6_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database-6_test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database.go" beforeDir="false" afterPath="$PROJECT_DIR$/database.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/database_test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/devenv.lock" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/devenv.nix" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/devenv.yaml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/errors.go" beforeDir="false" afterPath="$PROJECT_DIR$/errors.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/event-bus_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/event-bus_test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/job-generic.go" beforeDir="false" afterPath="$PROJECT_DIR$/job-generic.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/job-syncer.go" beforeDir="false" afterPath="$PROJECT_DIR$/job-syncer.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/job.go" beforeDir="false" afterPath="$PROJECT_DIR$/job.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/logger.go" beforeDir="false" afterPath="$PROJECT_DIR$/logger.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/manager.go" beforeDir="false" afterPath="$PROJECT_DIR$/manager.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/queue.go" beforeDir="false" afterPath="$PROJECT_DIR$/queue.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/runnable-fileoperation.go" beforeDir="false" afterPath="$PROJECT_DIR$/runnable-fileoperation.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/runnable-mail_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/runnable-mail_test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/runnable-sftp_test.go" beforeDir="false" afterPath="$PROJECT_DIR$/runnable-sftp_test.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/schedule-time.go" beforeDir="false" afterPath="$PROJECT_DIR$/schedule-time.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/scheduler-inotify.go" beforeDir="false" afterPath="$PROJECT_DIR$/scheduler-inotify.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/stat.go" beforeDir="false" afterPath="$PROJECT_DIR$/stat.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/worker.go" beforeDir="false" afterPath="$PROJECT_DIR$/worker.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ComposerSettings">
<execution />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Go File" />
</list>
</option>
</component>
<component name="GOROOT" url="file:///nix/store/fqzds43dcw7164rm1h51n54l2ipxi1qj-go-1.21.9/share/go" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="PhpWorkspaceProjectConfiguration" interpreter_name="PHP 8.2" />
<component name="ProjectColorInfo"><![CDATA[{
"customColor": "",
"associatedIndex": 8
}]]></component>
<component name="ProjectId" id="2fGcSxoYpsPbNVbRh8sUxQtBiHv" />
<component name="ProjectViewState">
<option name="flattenModules" value="true" />
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
<option name="showVisibilityIcons" value="true" />
<option name="sortByType" value="true" />
<option name="sortKey" value="BY_TYPE" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"DefaultGoTemplateProperty": "Go File",
"Go Test.TestScheduleJob in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
"Go Test.TestStructure in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
"Go Test.TestTimeFunctionSame in gitlab.schukai.com/oss/libraries/go/services/job-queues.executor": "Debug",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.go.formatter.settings.were.checked": "true",
"RunOnceActivity.go.migrated.go.modules.settings": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"git-widget-placeholder": "master",
"go.import.settings.migrated": "true",
"go.sdk.automatically.set": "true",
"last_opened_file_path": "/home/vs/workspaces/oss/go-libs/job-queues/nix/scripts",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"settings.editor.selected.configurable": "http.proxy",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/nix/scripts" />
<recent name="$PROJECT_DIR$/system/scripts" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/.back" />
</key>
</component>
<component name="RunManager" selected="Go Test.TestStructure in gitlab.schukai.com/oss/libraries/go/services/job-queues">
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="job-queues" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-i" />
<kind />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="TestScheduleJob in gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="job-queues" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="gitlab.schukai.com/oss/libraries/go/services/job-queues" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<pattern value="^\QTestScheduleJob\E$" />
<method v="2" />
</configuration>
<configuration name="TestStructure in gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="job-queues" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="gitlab.schukai.com/oss/libraries/go/services/job-queues" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<pattern value="^\QTestStructure\E$" />
<method v="2" />
</configuration>
<configuration name="TestTimeFunctionSame in gitlab.schukai.com/oss/libraries/go/services/job-queues" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="job-queues" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="gitlab.schukai.com/oss/libraries/go/services/job-queues" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<pattern value="^\QTestTimeFunctionSame\E$" />
<method v="2" />
</configuration>
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="job-queues" />
<working_directory value="$PROJECT_DIR$" />
<go_parameters value="-i" />
<kind />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$" />
<framework value="gotest" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Go Test.TestStructure in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
<item itemvalue="Go Test.TestScheduleJob in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
<item itemvalue="Go Test.TestTimeFunctionSame in gitlab.schukai.com/oss/libraries/go/services/job-queues" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="VgoProject">
<settings-migrated>true</settings-migrated>
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/schedule-time.go</url>
<line>61</line>
<option name="timeStamp" value="7" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/schedule-time.go</url>
<line>53</line>
<option name="timeStamp" value="8" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/schedule-time.go</url>
<line>51</line>
<option name="timeStamp" value="9" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
......@@ -51,16 +51,12 @@ func main() {
```
## Development
## Tests
Run tests using:
```bash
task test
```
| Command | Description |
|--------------------|--------------------------------------|
| ` task check-code` | Run linters and static code analysis |
| ` task run-tests` | Run tests |
## License
......
......@@ -7,7 +7,7 @@ package jobqueue
import (
"fmt"
"github.com/stretchr/testify/assert"
"gorm.io/driver/mysql"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"testing"
"time"
......@@ -20,8 +20,11 @@ func TestWriteToDB6(t *testing.T) {
// docker run --name mysql-test -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=testdb -p 3306:3306 -d mysql:latest && \
// docker logs -f mysql-test
dsn := "root:my-secret-pw@tcp(localhost:3306)/testdb?charset=utf8mb4&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
//dsn := "root:my-secret-pw@tcp(localhost:3306)/testdb?charset=utf8mb4&parseTime=True&loc=Local"
//db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
assert.NoError(t, err)
manager := NewManager()
manager.SetDB(db)
......
......@@ -153,7 +153,7 @@ func update(job *JobPersistence, db *gorm.DB) error {
}
}
for i, _ := range job.Logs {
for i := range job.Logs {
job.Logs[i].LogID = 0
_ = tx.Create(&job.Logs[i])
// no error handling, if it fails, it fails
......@@ -206,7 +206,7 @@ func save(job *JobPersistence, db *gorm.DB) error {
}
}
for i, _ := range job.Logs {
for i := range job.Logs {
job.Logs[i].LogID = 0
_ = tx.Create(&job.Logs[i])
// no error handling, if it fails, it fails
......
......@@ -42,6 +42,7 @@ func TestDeleteJob(t *testing.T) {
db.Model(&JobPersistence{}).Where("id = ?", "testJobID").Count(&count)
assert.Equal(t, int64(0), count)
}
func TestResetLogs(t *testing.T) {
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
assert.Nil(t, err)
......
{ pkgs ? import <nixpkgs> {}, inputs, phps, lib, config, modulesPath, ... }:
{
# https://devenv.sh/packages/
packages = with pkgs; [
inputs.version.defaultPackage."${builtins.currentSystem}"
appimage-run
blackbox
blackbox-terminal
coreutils-full
dbeaver
glibc.static
dbeaver
delve
dialog
drill
eza
fd
fd
feh
gcc12
gdlv
git
glab
gnugrep
gnumake
gnused
go-licenses
gosec
go-task
gum
httpie
hurl
jq
libffi
logrotate
meld
memcached
netcat
nixfmt
nodePackages.mermaid-cli
openssh
procps
ranger
unixtools.xxd
unzip
util-linux
wget
zlib
];
# https://devenv.sh/languages/
# languages.nix.enable = true;
languages = { go = { enable = true; }; };
difftastic.enable = true;
scripts.run-sshd.exec = ''
set -x
cd ${config.devenv.root}/docker/sftp-server
${pkgs.docker-client}/bin/docker docker build -t jobqueue-sftp-server .
cd -
${pkgs.coreutils}/bin/chmod 700 ${config.devenv.root}/.config/temp_rsa_key
${pkgs.coreutils}/bin/chmod 700 ${config.devenv.root}/.config/temp_ed25518_key
${pkgs.coreutils}/bin/mkdir -p ${config.devenv.root}/.devenv/chroot/home/demo/.ssh
${pkgs.coreutils}/bin/cat ${config.devenv.root}/.config/demo_ssh_key.pub > ${config.devenv.root}/.devenv/chroot/home/demo/.ssh/authorized_keys
${pkgs.coreutils}/bin/chmod 700 ${config.devenv.root}/.devenv/chroot/home/demo/.ssh
${pkgs.coreutils}/bin/chmod 600 ${config.devenv.root}/.devenv/chroot/home/demo/.ssh/authorized_keys
${pkgs.coreutils}/bin/cat <<EOF > ${config.devenv.root}/.config/sshd_config
AuthorizedKeysCommand ${pkgs.coreutils}/bin/cat ${config.devenv.root}/.devenv/chroot/home/demo/.ssh/authorized_keys
AuthorizedKeysCommandUser nobody
Match User root
ChrootDirectory ${config.devenv.root}/.devenv/chroot
ForceCommand internal-sftp
PasswordAuthentication no
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
PermitRootLogin no
AllowUsers demo root
EOF
${pkgs.openssh}/bin/sshd -D -e -o \
HostKey=${config.devenv.root}/.config/temp_rsa_key \
-f ${config.devenv.root}/.config/sshd_config \
-o HostKey=${config.devenv.root}/.config/temp_ed25518_key \
-o Port=''${1:-2222} \
-o AuthorizedKeysFile=${config.devenv.root}/.devenv/chroot/home/demo/.ssh/authorized_keys \
-o PidFile=${config.devenv.root}/.devenv/sshd.pid
'';
scripts.draw-graph.exec = ''
echo -e "Enter Meirmaid graph definition. ''${RED}End with Ctrl+D''${RESET}\n"
diagram=$(${pkgs.gum}/bin/gum write --placeholder "Enter Meirmaid graph definition. End with Ctrl+D")
tmpOutput=$(mktemp).png
echo "$diagram" | ${pkgs.nodePackages.mermaid-cli}/bin/mmdc -i - -o "$tmpOutput"
${pkgs.feh}/bin/feh $tmpOutput
# should delte the file, but does not work ask with gum
${pkgs.gum}/bin/gum confirm "Delete temporary file?"
if [ $? -eq 0 ]; then
rm "$tmpOutput"
else
echo "not deleting; file is at $tmpOutput"
fi
'';
scripts.get-go-default-packages.exec = ''
#!${pkgs.bash}/bin/bash
echo $(awk -F ' ' '/^module / { print $2 }' go.mod)
'';
# This script is executed when the app is built
# You can use it to build the app
scripts.test-lib.exec = ''
#!${pkgs.bash}/bin/bash
set -x
${pkgs.gosec}/bin/gosec ${config.devenv.root}
${pkgs.go}/bin/go test -mod=mod -tags 'runOnTask,osusergo,netgo' -a -ldflags "-extldflags '-static' -s -w" -cover -v ${config.devenv.root}
${pkgs.go}/bin/go test -mod=mod -tags 'runOnTask,osusergo,netgo' -a -ldflags "-extldflags '-static' -s -w" -bench -v ${config.devenv.root}
${pkgs.go}/bin/go test -mod=mod -tags 'runOnTask,osusergo,netgo' -a -ldflags "-extldflags '-static' -s -w" -race -v ${config.devenv.root}
'';
# This scritp is used to deploy the app to the gitlab registry
# It is used by the gitlab-ci.yml file
# The environment variables are set in the gitlab project settings
scripts.deploy-lib.exec = ''
#!${pkgs.bash}/bin/bash
PATH="''${PATH}":${pkgs.coreutils}/bin
PATH="''${PATH}":${pkgs.jq}/bin/
PATH="''${PATH}":${pkgs.curl}/bin/
PATH="''${PATH}":${pkgs.moreutils}/bin/
PATH="''${PATH}":${pkgs.gnutar}/bin
PATH="''${PATH}":${pkgs.gzip}/bin/
PATH="''${PATH}":${pkgs.eza}/bin/
PATH="''${PATH}":${pkgs.git}/bin/
PATH="''${PATH}":${
inputs.version.defaultPackage."${builtins.currentSystem}"
}/bin/
export PATH
if [[ -f .env-gitlab-ci ]]; then
source .env-gitlab-ci
rm .env-gitlab-ci
fi
set -x
## if $HOME not set, set it to current directory
if [[ -z "''${HOME}" ]]; then
HOME=$(pwd)
fi
export HOME
git config user.email "''${GITLAB_USER_EMAIL}"
git config user.name "''${GITLAB_USER_NAME:-"Gitlab CI"}"
git config pull.rebase true
git config http.sslVerify "false"
git remote set-url origin https://pad:''${GITLAB_TOKEN}@''${CI_REPOSITORY_URL#*@}
git fetch --all --tags --unshallow
git reset --hard origin/master
git checkout $CI_COMMIT_REF_NAME
git pull origin $CI_COMMIT_REF_NAME
if [ ! -z "''${CI_PROJECT_DIR}" ]; then
echo "CI_PROJECT_DIR is set, using it as project root."
project_root=$(realpath "''${CI_PROJECT_DIR}")/
elif [ ! -z "''${DEVENV_ROOT}" ]; then
echo "DEVENV_ROOT is set, using it as project root."
project_root=$(realpath "''${DEVENV_ROOT}")/
else
echo "Error: DEVENV_ROOT or CI_PROJECT_DIR environment variables are not set."
exit 1
fi
if [ ! -d "''${project_root}" ]; then
echo "Error: Project root directory does not seem to be valid."
echo "Check the DEVENV_ROOT or CI_PROJECT_DIR environment variables."
exit 1
fi
if [ -z "'CI_JOB_TOKEN" ]; then
echo "Error: CI_JOB_TOKEN variable is not set."
exit 1
fi
git --no-pager log --decorate=short --pretty=oneline
gitVersion=v$(version predict)
git tag -a $gitVersion -m"chore: bump version"
git --no-pager log --decorate=short --pretty=oneline
git push -o ci.skip origin ''${CI_COMMIT_REF_NAME} --tags
echo "done"
'';
enterShell = ''
cat <<'EOF' > CONTRIBUTING.md
# Contributing to schukai GmbH Projects
## Code of Conduct
Be a human, not an asshole. Common sense and basic human decency apply.
## Getting Started
### Setting up the Project
1. Fork the project on GitLab.
2. Clone your fork locally. Replace `[your-username]` with your GitLab username and `[project-name]` with the actual project name:
```bash
git clone $(git config --get remote.origin.url)
```
3. Add the upstream repository. Replace `[original-username]` and `[project-name]` with the original repository's username and project name:
```bash
git remote add upstream https://gitlab.schukai.com/[original-username]/[project-name].git
```
### Making Changes
1. Create a new branch:
```bash
git checkout -b new-feature-branch
```
2. Make your changes.
3. Commit your changes:
```bash
git commit -m "Description of change"
```
### Submitting a Merge Request
1. Push your changes to your fork:
```bash
git push origin new-feature-branch
```
2. Navigate to the original project repository on `gitlab.schukai.com`.
3. Open a Merge Request and provide a clear description of the changes.
## Coding Guidelines
- Follow the coding style used in the project.
- Write unit tests for new features.
- Ensure that all tests pass before submitting a Merge Request.
## Reporting Issues
If you find an issue, please create a new issue on `gitlab.schukai.com`.
## Additional Resources
- [GitLab Flow](https://docs.gitlab.com/ee/topics/gitlab_flow.html)
- [GitLab Merge Request Guidelines](https://docs.gitlab.com/ee/user/project/merge_requests/)
Thank you for your contribution!
EOF
cat <<'EOF' > LICENSE
Copyright (C) 2023 schukai GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
EOF
cat <<'EOF' > Taskfile.yml
# 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:
- docker pull atmoz/sftp:alpine
- docker pull axllent/mailpit
- echo "Execute unit tests in Go."
- test-lib
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
EOF
cat <<'EOF' > .gitlab-ci.yml
# 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
# services:
# - docker:dind
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
stages:
- test
- deploy
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
- env
- nix shell nixpkgs#docker-client -c docker info
after_script:
- if [ -f .env-gitlab-ci ]; then rm .env-gitlab-ci; fi
test:
stage: test
tags:
- nixos
script:
- devenv shell test-lib
cache:
- key: nixos
paths:
- /nix/store
artifacts:
paths:
- dist
deploy:
stage: deploy
tags:
- nixos
script:
- devenv shell -c deploy-lib
when: on_success
cache:
- key: nixos
paths:
- /nix/store
EOF
'';
scripts.do-git-commit.exec = ''
#!/usr/bin/env bash
# Define colors if the terminal supports it
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
RESET='\033[0m'
BOLD='\033[1m'
else
RED=""
GREEN=""
RESET=""
fi
step=1
reset
clear
# create random log file
LOGFILE="$(mktemp)"
if [ $? -ne 0 ]; then
echo -e "''${RED}✖ Could not create temporary log file. Exiting.''${RESET}"
exit 1
fi
log_and_display() {
echo -e "''${GREEN}==> $step. $1''${RESET}" | tee -a $LOGFILE
step=$((step + 1))
}
log_error_and_display() {
echo -e "''${RED}==> $step. $1''${RESET}" | tee -a $LOGFILE
}
printLogfileAndExit() {
exit_code=$1
echo -e "\n\n========================================\n\n\n"
echo -e "\n\n''${BOLD}Git and GitLab Automation Script''${RESET}\n\nI have performed the following actions:\n\n"
cat "$LOGFILE"
# Optional: Remove log file
rm -f "$LOGFILE"
if [ $exit_code -eq 0 ]; then
echo -e "\n''${GREEN}✔''${RESET} All actions were successful" | tee -a $LOGFILE
elif [ $exit_code -eq -1 ]; then
echo -e "\n''${RED}✖''${RESET} The script was manually cancelled" | tee -a $LOGFILE
exit_code=0
else
echo -e "\n''${RED}✖''${RESET} Some actions failed" | tee -a $LOGFILE
fi
exit $exit_code
}
print_headline() {
local title=$1
local underline=$(printf '─%.0s' $(seq 1 ''${#title}))
echo -e "\n\n''${BOLD}''${title}\n''${underline}''${RESET}\n"
}
do_cancel() {
echo -e "''${RED}==> ✖ Cancelled.''${RESET}" | tee -a $LOGFILE
printLogfileAndExit -1
}
# Function for unified logging and display
log_action() {
if [ $? -eq 0 ]; then
echo -e " ''${GREEN}✔''${RESET} $1: Successful" | tee -a $LOGFILE
else
echo -e " ''${RED}✖''${RESET} $1: Failed" | tee -a $LOGFILE
printLogfileAndExit 1
fi
}
print_what_to_do() {
echo -e "\n\nWhat do you want to do?\n"
}
git_status=$(git status --porcelain)
if [[ -z "$git_status" ]]; then
log_error_and_display "No changes to commit. Exiting."
printLogfileAndExit 0
fi
print_headline "Choose commit type"
selection=$(gum choose "feat: (new feature for the user, not a new feature for build script)" "fix: (bug fix for the user, not a fix to a build script)" "chore: (updating grunt tasks etc.; no production code change)" "docs: (changes to the documentation)" "style: (formatting, missing semi colons, etc; no production code change)" "refactor: (refactoring production code, eg. renaming a variable)" "test: (adding missing tests, refactoring tests; no production code change)" "Cancel")
commit_type=$(echo "$selection" | awk -F':' '{print $1}')
if [[ "$commit_type" == "Cancel" ]]; then
do_cancel
fi
log_and_display "You chose the commit type: $commit_type"
# NEXT STEP ISSUE HANDLING ############################################################################################################
#log_and_display "Issue handling"
gitlabIssues=()
while IFS= read -r line; do
if [[ $line =~ ^# ]]; then
id=$(echo "$line" | awk '{print substr($1, 2)}')
title=$(echo "$line" | awk -F'about' '{print $1}' | awk '{$1=$2=""; print substr($0, 3)}')
gitlabIssues+=("$id > $title")
fi
done < <(gum spin --spinner dot --show-output --title "Ask gitlab ..." -- glab issue list --output-format=details)
## if issues are available, ask if user wants to use an existing issue or create a new one
createOption="Create new issue"
existingOption="Use existing issue"
cancelOption="Cancel"
print_headline "Choose issue handling"
if [ ''${#gitlabIssues[@]} -eq 0 ]; then
log_and_display "There are no issues available."
print_what_to_do
choice=$(gum choose "$createOption" "$cancelOption")
else
log_and_display "There are ''${#gitlabIssues[@]} issues available."
print_what_to_do
choice=$(gum choose "$createOption" "$existingOption" "$cancelOption")
fi
if [[ "$choice" == "$cancelOption" ]]; then
do_cancel
fi
## array of issue ids
work_on_issue_ids=()
issue_text=""
if [[ "$choice" == "$createOption" ]]; then
print_headline "Create new issue"
issue_text=$(gum input --placeholder "Enter issue title")
echo -e "Enter issue description. ''${RED}End with Ctrl+D''${RESET}\n"
issue_description=$(gum write --placeholder "Enter issue description. End with Ctrl+D")
if [[ -z "$issue_text" ]]; then
log_error_and_display "Issue title is empty. Exiting."
printLogfileAndExit 1
fi
log_and_display "You entered the issue title: $issue_text"
log_and_display "You entered the issue description: $issue_description"
echo -e "\n"
gum confirm "Do you want to create this issue?"
# gum confirm exits with status 0 if confirmed and status 1 if cancelled.
if [ $? -eq 1 ]; then
do_cancel
fi
issue_output=$(glab issue create -t"$issue_text" --no-editor --description "$issue_description")
issue_id=$(echo "$issue_output" | grep -oP '(?<=/issues/)\d+')
work_on_issue_ids+=("$issue_id")
log_action "glab issue with id $issue_id created"
else
print_headline "Use existing issue"
echo -e "Select issue with arrow keys and press tab or space to select. Press enter to confirm.\n"
issue_ids=$(gum choose --no-limit "''${gitlabIssues[@]}")
# assign issue_ids to work_on_issue_ids. iterate over lines and take integer from beginning of line
while IFS= read -r line; do
work_on_issue_ids+=($(echo "$line" | grep -oP '^\d+'))
done <<<"$issue_ids"
fi
if [ ''${#work_on_issue_ids[@]} -eq 0 ]; then
log_and_display "No issue selected. Exiting."
printLogfileAndExit 0
fi
# NEXT STEP COMMIT MESSAGE ############################################################################################################
# print work_on_issue_ids
work_on_issue_ids_string=""
for i in "''${work_on_issue_ids[@]}"; do
work_on_issue_ids_string+="#$i "
done
log_and_display "You chose to work on the following issues: ''${work_on_issue_ids_string}"
print_headline "Check for changes to commit"
# ' ' = unmodified
# M = modified
# T = file type changed (regular file, symbolic link or submodule)
# A = added
# D = deleted
# R = renamed
# C = copied (if config option status.renames is set to "copies")
# U = updated but unmerged
# https://man.freebsd.org/cgi/man.cgi?query=git-status&sektion=1&manpath=freebsd-release-ports
count_all_changes=$(echo "$git_status" | wc -l)
count_staged_changes=$(echo "$git_status" | grep -c '^M')
count_new_staged_files=$(echo "$git_status" | grep -c '^A')
count_staged_changes=$((count_staged_changes + count_new_staged_files))
git_options_all="All $count_all_changes changes"
git_options_staged="Only the $count_staged_changes staged changes"
git_options_select_files="Select files"
git_options_cancel="Cancel"
git_options_array=()
if [[ $count_all_changes -gt 0 ]]; then
git_options_array+=("$git_options_all")
fi
if [[ $count_staged_changes -gt 0 ]]; then
git_options_array+=("$git_options_staged")
fi
git_options_array+=( "$git_options_select_files" )
git_options_array+=( "$git_options_cancel" )
selection=$(gum choose "''${git_options_array[@]}")
if [[ "$selection" == "$git_options_cancel" ]]; then
do_cancel
fi
if [[ "$selection" == "$git_options_all" ]]; then
git add -A
echo "1"
elif [[ "$selection" == "$git_options_select_files" ]]; then
files=()
while IFS= read -r line; do
files+=("$line")
done <<<"$git_status"
selected_files=$(gum choose --no-limit "''${files[@]}")
# no files selected
if [[ -z "$selected_files" ]]; then
log_and_display "No files selected. Exiting."
printLogfileAndExit 0
fi
# add selected files
while IFS= read -r line; do
## git proclimne could have letter, ? or ! at the beginning of the line
file=$(echo "$line" | awk '{print $2}')
if [[ -z "$file" || ! -f "$file" ]]; then
log_and_display "No file found in line: $line"
continue
fi
git add "$file"
done <<<"$selected_files"
fi
## count staged changes again and print
count_staged_changes=$(echo "$git_status" | grep -c '^M')
count_new_staged_files=$(echo "$git_status" | grep -c '^A')
count_staged_changes=$((count_staged_changes + count_new_staged_files))
log_and_display "You have $count_staged_changes staged changes to commit."
# NEXT STEP COMMIT MESSAGE ############################################################################################################
print_headline "Enter commit message"
commit_message=$(gum input --placeholder "Enter commit message" --value "$commit_type: $issue_text $work_on_issue_ids_string")
if [[ -z "$commit_message" ]]; then
log_error_and_display "Commit message is empty. Exiting."
printLogfileAndExit 1
fi
log_and_display "You entered the commit message: $commit_message"
gum confirm "Do you want to commit with this message?"
if [ $? -eq 1 ]; then
do_cancel
fi
# NEXT STEP COMMIT ####################################################################################################################
print_headline "Committing changes"
if ! git commit -m "$commit_message" ; then
log_error_and_display "Commit failed. Exiting."
printLogfileAndExit 1
fi
log_and_display "Commit successful."
# NEXT STEP PUSH ######################################################################################################################
print_headline "Pushing changes"
if ! git push ; then
log_error_and_display "Push failed. Exiting."
printLogfileAndExit 1
fi
log_and_display "Push successful."
# Close issue ######################################################################################################################
print_headline "Closing issues"
for issue_id in "''${work_on_issue_ids[@]}"; do
gum confirm "Do you want to close issue #$issue_id?"
if [ $? -eq 1 ]; then
continue
fi
if ! glab issue close "$issue_id" ; then
log_error_and_display "Closing issue $issue_id failed. Exiting."
else
log_and_display "Closing issue $issue_id successful."
fi
done
printLogfileAndExit 0
'';
}
inputs:
nixpkgs:
url: github:nixos/nixpkgs/nixos-23.11
version:
url: git+https://gitlab.schukai.com/oss/utilities/version.git
flake: true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment