diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b80c2f6c642fd96399921d44497c1791a9cefe86..fa545a6998d69fee812339394c21bfd6abb4ade3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,10 +17,10 @@ - release # if you want to debug the ci pipeline, uncomment the following lines - #debug: + #debug: # tags: # - nixos - # stage: tag + # stage: tag # script: # - export @@ -45,7 +45,7 @@ - nixos stage: release rules: - - if: '$CI_COMMIT_TAG_MESSAGE =~ /DO_RELEASE/' + - if: '$CI_COMMIT_TAG_MESSAGE =~ /DO_RELEASE/' when: on_success - when: never variables: diff --git a/devenv.nix b/devenv.nix index b04d996507db9755b33a017f24755013f28394cd..4858f87cba885dec9d7b17088fd9d79cf16569e2 100644 --- a/devenv.nix +++ b/devenv.nix @@ -8,55 +8,52 @@ modulesPath, ... }: let - - taskfileYaml = let - ciJobToken = builtins.getEnv "CI_JOB_TOKEN"; - gitCommit= if ciJobToken == "" then - (builtins.getFlake "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes").packages.${builtins.currentSystem}.git-commit - else - ""; - + gitCommit = + if ciJobToken == "" + then (builtins.getFlake "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes").packages.${builtins.currentSystem}.git-commit + else ""; + goPkgReleaseData = import ./project.nix; goPkgName = goPkgReleaseData.name or "goPkg"; - goPkgMnemonic = goPkgReleaseData.mnemonic or "go-pkg"; + goPkgMnemonic = goPkgReleaseData.mnemonic or "go-pkg"; in - pkgs.writeTextFile { - name = "Taskfile.yaml"; - text = '' -## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX -version: '3' - -tasks: - build: - desc: Build the app - aliases: - - b - cmds: - - build-app - sources: - - source/*.go - - source/**/*.go - - source/go.mod - - dist/** - - git-commit: - desc: Commit changes to git - cmds: - - ${gitCommit}/bin/git-commit - silent: true - - default: - desc: Print this help message - aliases: [d, help] - cmds: - - task --list - silent: true - -## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX - ''; - }; + pkgs.writeTextFile { + name = "Taskfile.yaml"; + text = '' + ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX + version: '3' + + tasks: + build: + desc: Build the app + aliases: + - b + cmds: + - build-app + sources: + - source/*.go + - source/**/*.go + - source/go.mod + - dist/** + + git-commit: + desc: Commit changes to git + cmds: + - ${gitCommit}/bin/git-commit + silent: true + + default: + desc: Print this help message + aliases: [d, help] + cmds: + - task --list + silent: true + + ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX + ''; + }; treefmtConfig = pkgs.writeTextFile { name = "treefmt.toml"; @@ -67,7 +64,7 @@ tasks: command = "${pkgs.alejandra}/bin/alejandra" options = [] includes = [ "*.nix" ] - excludes = [ "devenv.nix" ] + #excludes = [ "devenv.nix" ] [formatter.go] command = "${pkgs.go}/bin/gofmt" @@ -135,10 +132,10 @@ tasks: - release # if you want to debug the ci pipeline, uncomment the following lines - #debug: + #debug: # tags: # - nixos - # stage: tag + # stage: tag # script: # - export @@ -163,7 +160,7 @@ tasks: - nixos stage: release rules: - - if: '$CI_COMMIT_TAG_MESSAGE =~ /DO_RELEASE/' + - if: '$CI_COMMIT_TAG_MESSAGE =~ /DO_RELEASE/' when: on_success - when: never variables: @@ -176,54 +173,55 @@ tasks: ''; }; - goReleaserYaml = let + goReleaserYaml = let goPkgReleaseData = import ./project.nix; goPkgName = goPkgReleaseData.name or "goPkg"; goPkgMnemonic = goPkgReleaseData.mnemonic or "go-pkg"; in - pkgs.writeTextFile { - name = ".goreleaser.yml"; - text = '' - ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX - gitlab_urls: - api: https://gitlab.schukai.com/api/v4 - download: https://gitlab.schukai.com + pkgs.writeTextFile { + name = ".goreleaser.yml"; + text = '' + ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX + gitlab_urls: + api: https://gitlab.schukai.com/api/v4 + download: https://gitlab.schukai.com - # set to true if you use a self-signed certificate - skip_tls_verify: false + # set to true if you use a self-signed certificate + skip_tls_verify: false - use_package_registry: true + use_package_registry: true - # Set this if you set GITLAB_TOKEN to the value of CI_JOB_TOKEN. - # Since: v1.11 - use_job_token: false + # Set this if you set GITLAB_TOKEN to the value of CI_JOB_TOKEN. + # Since: v1.11 + use_job_token: false - project_name: ${goPkgMnemonic} + project_name: ${goPkgMnemonic} - builds: - - id: ${goPkgMnemonic} - goos: - - linux - - darwin - - windows - dir: ${config.devenv.root}/source - ldflags: - - -s -w - - -X main.version={{.Version}} - - -X 'main.commit={{.Commit}}' - - -X 'main.build={{.Date}}' - - -X 'main.mnemonic=${goPkgMnemonic}' - - -X 'main.name=${goPkgName}' + builds: + - id: ${goPkgMnemonic} + goos: + - linux + - darwin + - windows + dir: ${config.devenv.root}/source + ldflags: + - -s -w + - -X main.version={{.Version}} + - -X 'main.commit={{.Commit}}' + - -X 'main.build={{.Date}}' + - -X 'main.mnemonic=${goPkgMnemonic}' + - -X 'main.name=${goPkgName}' - ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX - ''; - }; + ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX + ''; + }; in { - env.APP_NAME = let - goPkgReleaseData = import ./project.nix; - goPkgMnemonic = goPkgReleaseData.mnemonic or "go-pkg"; - in goPkgMnemonic; + env.APP_NAME = let + goPkgReleaseData = import ./project.nix; + goPkgMnemonic = goPkgReleaseData.mnemonic or "go-pkg"; + in + goPkgMnemonic; # https://devenv.sh/packages/ packages = with pkgs; [ @@ -302,7 +300,7 @@ in { echo " ✖ Not in gitlab ci." exit 0 fi - + set -x ${pkgs.git}/bin/git config user.email "''${GITLAB_USER_EMAIL}" ${pkgs.git}/bin/git config user.name "''${GITLAB_USER_NAME:-"Gitlab CI"}" @@ -314,29 +312,29 @@ in { ${pkgs.git}/bin/git reset --hard origin/master ${pkgs.git}/bin/git checkout $CI_COMMIT_REF_NAME ${pkgs.git}/bin/git pull origin $CI_COMMIT_REF_NAME - + NEWVERSION=$(${inputs.version.defaultPackage."${builtins.currentSystem}"}/bin/version predict --git exit-code-if-no-bump) if [[ $? -ne 0 ]]; then echo " ✖ No bump wanted." exit 0 fi - + if [[ -z "''${NEWVERSION}" ]]; then echo " ✖ No version found." exit 0 fi - - sed -i "s/version\s*=\s*\".*\"/version=\"''${NEWVERSION}\"/" ${config.devenv.root}/project.nix + + sed -i "s/version\s*=\s*\".*\"/version = \"''${NEWVERSION}\"/" ${config.devenv.root}/project.nix ${pkgs.git}/bin/git add ${config.devenv.root}/project.nix ${pkgs.git}/bin/git commit -m "chore: Bump version to ''${NEWVERSION}" - + ${pkgs.git}/bin/git log --decorate=short --pretty=oneline - + ${pkgs.git}/bin/git tag -a "''${NEWVERSION}" -m "chore: Release ''${NEWVERSION} - DO_RELEASE" ${pkgs.git}/bin/git push origin $CI_COMMIT_REF_NAME --tags ''; - + scripts.common-functions.exec = '' if [ -t 1 ]; then @@ -373,15 +371,15 @@ in { fi echo "$hash" } - + echo_green() { echo -e "$GREEN ✔ $1$RESET" } - + echo_red() { echo -e "$RED ✖ $1$RESET" } - + echo_todo() { echo_bold "$BLUE • $1" } @@ -397,11 +395,11 @@ in { ${pkgs.git}/bin/git add "$project_nix" ${pkgs.git}/bin/git commit -m "chore: Update project version to $buildVer" "$project_nix" ${pkgs.git}/bin/git tag -f -a "$buildVer" -m "Release $buildVer" - + if is_true "$CI_MODE"; then ${pkgs.git}/bin/git push -o ci.skip origin ''${CI_COMMIT_REF_NAME} --tags fi - + else echo_green "Project version is up to date" fi @@ -424,8 +422,7 @@ in { fi ''; - - + scripts.update-files.exec = '' #!${pkgs.bash}/bin/bash source common-functions @@ -436,7 +433,7 @@ in { echo_red "$2 already exists" fi } - + update_symlink() { echo -e " → $1" local source_path="$1" @@ -448,7 +445,7 @@ in { echo_red "$RED ✖ $source_dir is not a directory. Please remove it manually and run the script again." exit 1 fi - + if [[ -L "$source_path" ]]; then if [[ "$(readlink "$source_path")" != "$target_path" ]]; then rm "$source_path" @@ -495,6 +492,23 @@ in { echo "$hash" ''; + ## this script should be run after debugging the ci pipeline + scripts.delete-pipeline.exec = '' + #!${pkgs.bash}/bin/bash + + pipeline_list=$(glab ci list) + + commit_hashes=$(echo "$pipeline_list" | awk '/#/{print $3}') + for hash in $commit_hashes; do + hh=$(echo "$hash" | cut -d"#" -f2) + echo "found hash: $hh" + glab ci delete "$hh" + done + + echo "done" + + ''; + scripts.build-app.exec = '' #!${pkgs.bash}/bin/bash ${pkgs.treefmt}/bin/treefmt @@ -509,9 +523,9 @@ in { scripts.update-hashes.exec = '' #!${pkgs.bash}/bin/bash - sed -i 's/vendorHash\s*=\s*".*"/vendorHash="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="/' ${config.devenv.root}/project.nix + sed -i 's/vendorHash\s*=\s*".*"/vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="/' ${config.devenv.root}/project.nix HASH=$(${pkgs.nix}/bin/nix build 2>&1 | grep 'got:' | awk '{print $2}') - sed -i "s/vendorHash\s*=\s*\".*\"/vendorHash=\"''${HASH}\"/" ${config.devenv.root}/project.nix + sed -i "s/vendorHash\s*=\s*\".*\"/vendorHash = \"''${HASH}\"/" ${config.devenv.root}/project.nix ''; enterShell = '' diff --git a/project.nix b/project.nix index 50961da9d2f484a607b76db62794429b3cb7aa42..e42bf7b35eec32432158113b099b7daf3d2b3313 100644 --- a/project.nix +++ b/project.nix @@ -6,5 +6,5 @@ compileForSystems = ["linux/arm64" "linux/amd64" "darwin/amd64" "windows/amd64"]; modulePath = "gitlab.schukai.com/oss/utilities/version"; version = "0.7.7"; ## don't change this line, it is updated automatically by GitLab CI - vendorHash="sha256-uyWI6Gnko1J62XDk6jjRdqZ8TSFtwsTOlDwdR9Xc+ic="; ## this is updated automatically by update-hashes + vendorHash = "sha256-uyWI6Gnko1J62XDk6jjRdqZ8TSFtwsTOlDwdR9Xc+ic="; ## this is updated automatically by update-hashes } diff --git a/treefmt.toml b/treefmt.toml index 503545cfc79fe78731db98370402b4b40992ab41..49c3f871015fbc004a02e160021e265cffb2a6b6 120000 --- a/treefmt.toml +++ b/treefmt.toml @@ -1 +1 @@ -/nix/store/wrp2lsy6h8mzr6fa4n71lqnxw5dliwmc-treefmt.toml \ No newline at end of file +/nix/store/f7brr7ah00s9303lhvk338lnyb1ifrys-treefmt.toml \ No newline at end of file