diff --git a/Taskfile.yaml b/Taskfile.yaml index 8f822951fc80f7fefe98845e26717b9c9dd4babb..3641038cb9548ad11b1f1d6f8035ad6559cfda61 120000 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -1 +1 @@ -/nix/store/hp4y487ym0n2nvcqmhix6irzffnhdx4a-Taskfile.yaml \ No newline at end of file +/nix/store/r21ipdiswnz3fcsn51i8l1zipjp91f91-Taskfile.yaml \ No newline at end of file diff --git a/devenv.nix b/devenv.nix index 5e2e9b7d0800c76b2f4645cf961e791db7c70a78..e5082530a0ea0b81df88e60883d8fd83ef3589a6 100644 --- a/devenv.nix +++ b/devenv.nix @@ -8,7 +8,10 @@ modulesPath, ... }: let - taskfileYaml = pkgs.writeTextFile { + taskfileYaml = let + gitCommit = (builtins.getFlake "git+https://gitlab.schukai.com/schukai/entwicklung/nix-flakes").packages.${builtins.currentSystem}.git-commit; + in + pkgs.writeTextFile { name = "Taskfile.yaml"; text = '' ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX @@ -26,6 +29,13 @@ tasks: - source/**/*.go - source/go.mod - dist/** + + git-commit: + desc: Commit changes to git + cmds: + - ${gitCommit}/bin/git-commit + silent: true + commit: desc: Commit a feature @@ -155,7 +165,15 @@ tasks: ''; }; - goReleaserYaml = pkgs.writeTextFile { + goReleaserYaml = let + goPkgReleaseData = import ./project.nix; + goPkgName = goPkgReleaseData.name or "goPkg"; + goPkgMnemonic = goPkgReleaseData.mnemonic or "go-pkg"; + goPkgDescription = goPkgReleaseData.description or "this is a goPkg"; + goPkgVersion = goPkgReleaseData.version or "0.1.0"; + + in + pkgs.writeTextFile { name = ".goreleaser.yml"; text = '' ## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX @@ -172,36 +190,18 @@ tasks: # Since: v1.11 use_job_token: false - project_name: version + project_name: ${goPkgMnemonic} builds: - - id: version + - id: ${goPkgMnemonic} goos: - linux - darwin - windows - # goarch: - # - amd64 - ## - arm64 - ## - "386" - # goarm: - # - "6" - ## gomips: - ## - hardfloat - ## goamd64: - ## - v1 - # targets: - # - linux_amd64_v1 - # - linux_arm64 - ## - linux_386 - # - darwin_amd64_v1 - # - darwin_arm64 - # - windows_amd64_v1 - # - windows_arm64 - # - windows_386 dir: ${config.devenv.root}/source ldflags: - - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.build={{.Date}} + - -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 ''; @@ -286,39 +286,38 @@ 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"}" - ${pkgs.git}/bin/git config credential.helper '!f() { echo "username=gitlab-ci-token"; echo "password=''${CI_JOB_TOKEN}"; }; f' - ${pkgs.git}/bin/git config pull.rebase true - ${pkgs.git}/bin/git config http.sslVerify "false" - ${pkgs.git}/bin/git remote set-url origin https://pad:''${GITLAB_TOKEN}@''${CI_REPOSITORY_URL#*@} - ${pkgs.git}/bin/git fetch --all --tags --unshallow - ${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 - ${pkgs.git}/bin/git add ${config.devenv.root}/project.nix - ${pkgs.git}/bin/git commit -m "chore: Bump version to ''${NEWVERSION} (NOT_TAGIT)" - - ${pkgs.git}/bin/git log --decorate=short --pretty=oneline - - ${pkgs.git}/bin/git tag -a "''${NEWVERSION}" -m "chore: Release ''${NEWVERSION} (NOT_TAGIT)" - ${pkgs.git}/bin/git push origin $CI_COMMIT_REF_NAME --tags + + set -x + ${pkgs.git}/bin/git config user.email "''${GITLAB_USER_EMAIL}" + ${pkgs.git}/bin/git config user.name "''${GITLAB_USER_NAME:-"Gitlab CI"}" + ${pkgs.git}/bin/git config credential.helper '!f() { echo "username=gitlab-ci-token"; echo "password=''${CI_JOB_TOKEN}"; }; f' + ${pkgs.git}/bin/git config pull.rebase true + ${pkgs.git}/bin/git config http.sslVerify "false" + ${pkgs.git}/bin/git remote set-url origin https://pad:''${GITLAB_TOKEN}@''${CI_REPOSITORY_URL#*@} + ${pkgs.git}/bin/git fetch --all --tags --unshallow + ${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 + ${pkgs.git}/bin/git add ${config.devenv.root}/project.nix + ${pkgs.git}/bin/git commit -m "chore: Bump version to ''${NEWVERSION} (NOT_TAGIT)" + + ${pkgs.git}/bin/git log --decorate=short --pretty=oneline + + ${pkgs.git}/bin/git tag -a "''${NEWVERSION}" -m "chore: Release ''${NEWVERSION} (NOT_TAGIT)" + ${pkgs.git}/bin/git push origin $CI_COMMIT_REF_NAME --tags ''; scripts.update-files.exec = '' @@ -357,9 +356,25 @@ in { difftastic.enable = true; + scripts.get-commit-hash.exec = '' + #!${pkgs.bash}/bin/bash + hash="" + if [[ -n "$CI_COMMIT_SHORT_SHA" ]]; then + hash="$CI_COMMIT_SHORT_SHA" + else + hash="$(git rev-parse --short HEAD)" + + if [[ -n "$(git status --porcelain)" ]]; then + hash="''${hash}-dirty" + fi + fi + echo "$hash" + ''; + scripts.build-app.exec = '' #!${pkgs.bash}/bin/bash ${pkgs.treefmt}/bin/treefmt + update-hashes ${pkgs.nix}/bin/nix build .#version ''; @@ -370,7 +385,6 @@ in { scripts.update-hashes.exec = '' #!${pkgs.bash}/bin/bash - set -x 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