From 3020a854af4975fcf20ce6b582a14a0abdaa3e85 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Mon, 29 Jan 2024 20:59:32 +0100 Subject: [PATCH] chore: integrate git-commit #4 --- flake.lock | 75 ++- flake.nix | 55 +-- .../go/application/xflags/devenv.nix | 458 +++++++++--------- .../go/utilities/pathfinder/devenv.nix | 458 +++++++++--------- system/scripts/update-hashes.nix | 4 +- system/scripts/update-version.nix | 63 ++- 6 files changed, 589 insertions(+), 524 deletions(-) diff --git a/flake.lock b/flake.lock index ffae94d..9030291 100644 --- a/flake.lock +++ b/flake.lock @@ -87,6 +87,21 @@ "type": "github" } }, + "git-commit": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1, + "narHash": "sha256-8hXrOA8SKy//ctoL1poIhJwuT7G4rvVu7FguROzEoDg=", + "path": "./git-commit", + "type": "path" + }, + "original": { + "path": "./git-commit", + "type": "path" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -164,6 +179,25 @@ "type": "github" } }, + "nix-templates": { + "inputs": { + "git-commit": "git-commit", + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1704993617, + "narHash": "sha256-++u7I3KCDgP+JhW70k5tiLfBESWVSKdVK7aei0G+mR8=", + "ref": "refs/heads/master", + "rev": "e63b1d6ae5526158fa2a1f4cd53b0ea4f4c93573", + "revCount": 18, + "type": "git", + "url": "https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git" + }, + "original": { + "type": "git", + "url": "https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git" + } + }, "nixpkgs": { "locked": { "lastModified": 1678875422, @@ -231,6 +265,36 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1704874635, + "narHash": "sha256-YWuCrtsty5vVZvu+7BchAxmcYzTMfolSPP5io8+WYCg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "3dc440faeee9e889fe2d1b4d25ad0f430d449356", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-23.11", + "type": "indirect" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1706373441, + "narHash": "sha256-S1hbgNbVYhuY2L05OANWqmRzj4cElcbLuIkXTb69xkk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "56911ef3403a9318b7621ce745f5452fb9ef6867", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-23.11", + "type": "indirect" + } + }, + "nixpkgs_4": { "locked": { "lastModified": 1706098335, "narHash": "sha256-r3dWjT8P9/Ah5m5ul4WqIWD8muj5F+/gbCdjiNVBKmU=", @@ -246,7 +310,7 @@ "type": "github" } }, - "nixpkgs_3": { + "nixpkgs_5": { "locked": { "lastModified": 1705856552, "narHash": "sha256-JXfnuEf5Yd6bhMs/uvM67/joxYKoysyE3M2k6T3eWbg=", @@ -262,7 +326,7 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_6": { "locked": { "lastModified": 1704145853, "narHash": "sha256-G/1AMt9ibpeMlcxvD1vNaC8imGaK+g7zZ99e29BLgWw=", @@ -311,7 +375,8 @@ "flake-parts": "flake-parts", "flake-root": "flake-root", "mk-shell-bin": "mk-shell-bin", - "nixpkgs": "nixpkgs_2", + "nix-templates": "nix-templates", + "nixpkgs": "nixpkgs_4", "treefmt-nix": "treefmt-nix", "versionsTool": "versionsTool" } @@ -333,7 +398,7 @@ }, "treefmt-nix": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_5" }, "locked": { "lastModified": 1706285206, @@ -351,7 +416,7 @@ }, "versionsTool": { "inputs": { - "nixpkgs": "nixpkgs_4" + "nixpkgs": "nixpkgs_6" }, "locked": { "lastModified": 1704542622, diff --git a/flake.nix b/flake.nix index ad6b851..36d1edf 100644 --- a/flake.nix +++ b/flake.nix @@ -8,7 +8,7 @@ flake-root.url = "github:srid/flake-root"; treefmt-nix.url = "github:numtide/treefmt-nix"; versionsTool.url = "git+https://gitlab.schukai.com/oss/utilities/version.git"; - git-commit.url = "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes#git-commit"; + nix-templates.url = "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes.git"; }; nixConfig = { @@ -17,9 +17,10 @@ }; outputs = inputs @ { - self, + self, flake-parts, versionsTool, + nix-templates, ... }: flake-parts.lib.mkFlake {inherit inputs;} { @@ -27,7 +28,6 @@ inputs.devenv.flakeModule inputs.flake-root.flakeModule inputs.treefmt-nix.flakeModule - inputs.git-commit.flakeModule ]; systems = (import ./project.nix).supportedSystems; @@ -50,24 +50,19 @@ portAsString = toString projectDefinition.k8s.port; in { - - - packages = rec { - default = self.packages.${system}.bob; - + bob = let projectDefinition = import ./project.nix; sourcePath = ./source; - + timestamp = with (import <nixpkgs> {}); - builtins.readFile ( - runCommand "timestamp" - { when = builtins.currentTime; } - "echo -n `date -d @$when +%Y-%m-%d_%H-%M-%S` > $out" - ); - + builtins.readFile ( + runCommand "timestamp" + {when = builtins.currentTime;} + "echo -n `date -d @$when +%Y-%m-%d_%H-%M-%S` > $out" + ); in # https://nixos.wiki/wiki/Go pkgs.buildGoModule { @@ -104,7 +99,7 @@ nativeBuildInputs = with system; [pkgs.alejandra pkgs.shellcheck pkgs.shfmt]; doCheck = true; - + checkPhase = '' cd ${sourcePath} if ! go test -v ./... 2>&1 | cat ; then @@ -115,9 +110,8 @@ echo "Test passed: '$out' is as expected." ''; }; - }; - + treefmt.config = { inherit (config.flake-root) projectRootFile; programs.alejandra.enable = true; @@ -131,16 +125,14 @@ devenv.shells = let projectDefinition = import ./project.nix; buildRoot = ./.; - in { default = rec { name = projectDefinition.name; - - scripts = let - versionsTool = inputs.versionsTool.defaultPackage."${builtins.currentSystem}"; - - workingDirectory = builtins.getEnv "PWD"; - + + scripts = let + versionsTool = inputs.versionsTool.defaultPackage."${builtins.currentSystem}"; + + workingDirectory = builtins.getEnv "PWD"; in { treefmt.exec = '' ${config.treefmt.build.wrapper}/bin/treefmt @@ -161,18 +153,21 @@ update-hashes.exec = import ./system/scripts/update-hashes.nix { inherit pkgs config buildRoot projectDefinition workingDirectory; }; - + update-version.exec = import ./system/scripts/update-version.nix { inherit pkgs config buildRoot projectDefinition versionsTool workingDirectory; }; - }; imports = []; packages = with pkgs; [ inputs.versionsTool.defaultPackage."${builtins.currentSystem}" + inputs.nix-templates.packages."${builtins.currentSystem}".git-commit + nodePackages.prettier-plugin-toml + nodePackages.prettier go-task + alejandra ]; languages.nix.enable = true; @@ -186,11 +181,9 @@ }; }; }; - + flake = { - - defaultPackage = self.packages.${builtins.currentSystem}.bob; + defaultPackage = self.packages.${builtins.currentSystem}.bob; }; - }; } diff --git a/source/vendor/gitlab.schukai.com/oss/libraries/go/application/xflags/devenv.nix b/source/vendor/gitlab.schukai.com/oss/libraries/go/application/xflags/devenv.nix index 5fdd16f..94ce670 100644 --- a/source/vendor/gitlab.schukai.com/oss/libraries/go/application/xflags/devenv.nix +++ b/source/vendor/gitlab.schukai.com/oss/libraries/go/application/xflags/devenv.nix @@ -1,6 +1,12 @@ -{ pkgs ? import <nixpkgs> {}, inputs, phps, lib, config, modulesPath, ... }: - { + pkgs ? import <nixpkgs> {}, + inputs, + phps, + lib, + config, + modulesPath, + ... +}: { # https://devenv.sh/packages/ packages = with pkgs; [ inputs.version.defaultPackage."${builtins.currentSystem}" @@ -50,22 +56,22 @@ # https://devenv.sh/languages/ # languages.nix.enable = true; - languages = { go = { enable = true; }; }; + languages = {go = {enable = true;};}; difftastic.enable = true; - + 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 + # You can use it to build the app scripts.test-lib.exec = '' #!${pkgs.bash}/bin/bash #set -euo pipefail set -x - + PATH="''${PATH}":${pkgs.coreutils}/bin PATH="''${PATH}":${pkgs.findutils}/bin PATH="''${PATH}":${pkgs.jq}/bin/ @@ -141,7 +147,7 @@ project_root=$(realpath "''${DEVENV_ROOT}")/ else echo "Error: DEVENV_ROOT or CI_PROJECT_DIR environment variables are not set." - exit 1 + exit 1 fi if [ ! -d "''${project_root}" ]; then @@ -157,7 +163,7 @@ git --no-pager log --decorate=short --pretty=oneline gitVersion=v$(version predict) - git tag -a $gitVersion -m"chore: bump version" + 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 @@ -166,214 +172,214 @@ ''; 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: - - 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 -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 - -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 - -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 - + + 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: + - 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 + 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 + + 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 + + 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 = '' @@ -520,7 +526,7 @@ EOF 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 @@ -559,7 +565,7 @@ EOF if [ ''${#work_on_issue_ids[@]} -eq 0 ]; then log_and_display "No issue selected. Exiting." printLogfileAndExit 0 - fi + fi # NEXT STEP COMMIT MESSAGE ############################################################################################################ # print work_on_issue_ids @@ -622,9 +628,9 @@ EOF 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." @@ -639,10 +645,10 @@ EOF log_and_display "No file found in line: $line" continue fi - + git add "$file" done <<<"$selected_files" - + fi ## count staged changes again and print @@ -695,21 +701,19 @@ EOF 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." + log_and_display "Closing issue $issue_id successful." fi done printLogfileAndExit 0 ''; - - } diff --git a/source/vendor/gitlab.schukai.com/oss/libraries/go/utilities/pathfinder/devenv.nix b/source/vendor/gitlab.schukai.com/oss/libraries/go/utilities/pathfinder/devenv.nix index 5fdd16f..94ce670 100644 --- a/source/vendor/gitlab.schukai.com/oss/libraries/go/utilities/pathfinder/devenv.nix +++ b/source/vendor/gitlab.schukai.com/oss/libraries/go/utilities/pathfinder/devenv.nix @@ -1,6 +1,12 @@ -{ pkgs ? import <nixpkgs> {}, inputs, phps, lib, config, modulesPath, ... }: - { + pkgs ? import <nixpkgs> {}, + inputs, + phps, + lib, + config, + modulesPath, + ... +}: { # https://devenv.sh/packages/ packages = with pkgs; [ inputs.version.defaultPackage."${builtins.currentSystem}" @@ -50,22 +56,22 @@ # https://devenv.sh/languages/ # languages.nix.enable = true; - languages = { go = { enable = true; }; }; + languages = {go = {enable = true;};}; difftastic.enable = true; - + 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 + # You can use it to build the app scripts.test-lib.exec = '' #!${pkgs.bash}/bin/bash #set -euo pipefail set -x - + PATH="''${PATH}":${pkgs.coreutils}/bin PATH="''${PATH}":${pkgs.findutils}/bin PATH="''${PATH}":${pkgs.jq}/bin/ @@ -141,7 +147,7 @@ project_root=$(realpath "''${DEVENV_ROOT}")/ else echo "Error: DEVENV_ROOT or CI_PROJECT_DIR environment variables are not set." - exit 1 + exit 1 fi if [ ! -d "''${project_root}" ]; then @@ -157,7 +163,7 @@ git --no-pager log --decorate=short --pretty=oneline gitVersion=v$(version predict) - git tag -a $gitVersion -m"chore: bump version" + 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 @@ -166,214 +172,214 @@ ''; 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: - - 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 -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 - -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 - -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 - + + 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: + - 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 + 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 + + 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 + + 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 = '' @@ -520,7 +526,7 @@ EOF 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 @@ -559,7 +565,7 @@ EOF if [ ''${#work_on_issue_ids[@]} -eq 0 ]; then log_and_display "No issue selected. Exiting." printLogfileAndExit 0 - fi + fi # NEXT STEP COMMIT MESSAGE ############################################################################################################ # print work_on_issue_ids @@ -622,9 +628,9 @@ EOF 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." @@ -639,10 +645,10 @@ EOF log_and_display "No file found in line: $line" continue fi - + git add "$file" done <<<"$selected_files" - + fi ## count staged changes again and print @@ -695,21 +701,19 @@ EOF 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." + log_and_display "Closing issue $issue_id successful." fi done printLogfileAndExit 0 ''; - - } diff --git a/system/scripts/update-hashes.nix b/system/scripts/update-hashes.nix index ae4799e..3651786 100644 --- a/system/scripts/update-hashes.nix +++ b/system/scripts/update-hashes.nix @@ -11,13 +11,13 @@ in '' #!${pkgs.bash}/bin/bash ${common} - + defaultHash="${pkgs.lib.fakeHash}" echo_step "Reset vendorHash to default value: $defaultHash" ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*null|vendorHash = \"$defaultHash\"|g" ${workingDirectory}/project.nix ${pkgs.gnused}/bin/sed -i "s|vendorHash\s*=\s*\"[^\"]\"|vendorHash = \"$defaultHash\"|g" ${workingDirectory}/project.nix - + RESULT=$(${pkgs.nix}/bin/nix build .#goPkg 2>&1) if [[ $? -ne 0 ]]; then diff --git a/system/scripts/update-version.nix b/system/scripts/update-version.nix index c8a6b60..4c13134 100644 --- a/system/scripts/update-version.nix +++ b/system/scripts/update-version.nix @@ -8,49 +8,48 @@ }: let serviceSourcePath = "${buildRoot}/"; common = import ./common.nix {inherit pkgs;}; - in '' -#!${pkgs.bash}/bin/bash + #!${pkgs.bash}/bin/bash -${common} + ${common} -cmd=${versionsTool}/bin/version + cmd=${versionsTool}/bin/version -echo_step "Getting current commit hash" -HASH=$(${pkgs.git}/bin/git -C ${workingDirectory}/ rev-parse --short HEAD) -echo_ok "Current commit hash is ''${HASH}" - -echo_step "Replacing hash in project.nix" -if ! ${pkgs.gnused}/bin/sed -i "s|commitHash\s*=\s*\"[^\"]*\"|commitHash = \"''${HASH}\"|g" ${workingDirectory}/project.nix ; then - echo_fail "Hash not replaced" - exit 1 -fi + echo_step "Getting current commit hash" + HASH=$(${pkgs.git}/bin/git -C ${workingDirectory}/ rev-parse --short HEAD) + echo_ok "Current commit hash is ''${HASH}" -echo_ok "Hash updated" + echo_step "Replacing hash in project.nix" + if ! ${pkgs.gnused}/bin/sed -i "s|commitHash\s*=\s*\"[^\"]*\"|commitHash = \"''${HASH}\"|g" ${workingDirectory}/project.nix ; then + echo_fail "Hash not replaced" + exit 1 + fi -echo_step "Checking if there is a new version" -if ! $cmd auto --git --exit-code-if-no-bump ; then - echo_fail "No version jump to a new version" -fi + echo_ok "Hash updated" -VERSION=$($cmd print --git) -echo_step "Current version is ''${VERSION}" + echo_step "Checking if there is a new version" + if ! $cmd auto --git --exit-code-if-no-bump ; then + echo_fail "No version jump to a new version" + fi -if [[ -z "''${VERSION}" ]]; then - echo_fail "Could not get the current version" - exit 1 -fi + VERSION=$($cmd print --git) + echo_step "Current version is ''${VERSION}" -echo_step "Check version in project.nix" + if [[ -z "''${VERSION}" ]]; then + echo_fail "Could not get the current version" + exit 1 + fi -# check if version replaced -if ! ${pkgs.gnused}/bin/sed -i "s/version\s*=\s*\"[^\"]*\"/version = \"''${VERSION}\"/g" ${workingDirectory}/project.nix; then - echo_fail "Version not replaced" - exit 1 -fi + echo_step "Check version in project.nix" -${pkgs.git}/bin/git -C ${workingDirectory}/ commit -m "chore: Version and hash updated to $VERSION, $HASH" ${workingDirectory}/project.nix -echo_ok "Version and hash updated" + # check if version replaced + if ! ${pkgs.gnused}/bin/sed -i "s/version\s*=\s*\"[^\"]*\"/version = \"''${VERSION}\"/g" ${workingDirectory}/project.nix; then + echo_fail "Version not replaced" + exit 1 + fi + + ${pkgs.git}/bin/git -C ${workingDirectory}/ commit -m "chore: Version and hash updated to $VERSION, $HASH" ${workingDirectory}/project.nix + echo_ok "Version and hash updated" '' -- GitLab