diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 17f62f0576f6761a7f2a4587ef88e74e3acd2022..4e6c35e84c4de8b7adf68e726ab6839da6781d59 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -23,14 +23,14 @@ stage: tag script: - devenv shell tag-version - + rules: - if: '$CI_COMMIT_TAG' when: never - if: '$CI_COMMIT_MESSAGE =~ /NOT_TAGIT/' - when: never - - when: on_success - + when: never + - when: on_success + release: tags: diff --git a/Taskfile.yaml b/Taskfile.yaml index b95f48cd1eed99cd6c07d847baa51e0c4a1b850e..8f822951fc80f7fefe98845e26717b9c9dd4babb 120000 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -1 +1 @@ -/nix/store/4bvalx54rgxmryi1jx7k70aq4ccr7phq-Taskfile.yaml \ No newline at end of file +/nix/store/hp4y487ym0n2nvcqmhix6irzffnhdx4a-Taskfile.yaml \ No newline at end of file diff --git a/devenv.lock b/devenv.lock index d6bb922f10ddf96c38c7185048b0baa8dcf049bd..d0d0a784eb3f9140dcad3bc477f50ef70261fdf2 100644 --- a/devenv.lock +++ b/devenv.lock @@ -74,11 +74,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1703992652, - "narHash": "sha256-C0o8AUyu8xYgJ36kOxJfXIroy9if/G6aJbNOpA5W0+M=", + "lastModified": 1704145853, + "narHash": "sha256-G/1AMt9ibpeMlcxvD1vNaC8imGaK+g7zZ99e29BLgWw=", "owner": "nixos", "repo": "nixpkgs", - "rev": "32f63574c85fbc80e4ba1fbb932cde9619bad25e", + "rev": "2d2ea8eab9e400618748ab1a6a108255233b602c", "type": "github" }, "original": { @@ -171,11 +171,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1704188267, - "narHash": "sha256-9Wrl8w8jQxhz8uuuojZX5a6EPqqlNY6/HzKa1RuKNfc=", + "lastModified": 1704308484, + "narHash": "sha256-aclQ3GUoElRa5OlVZgtxzP1iM6Lus8ffDLRfV+0R9gQ=", "ref": "refs/heads/master", - "rev": "ca971c11a1600679e981f28c5433581355033b9b", - "revCount": 42, + "rev": "8b59839682aafe4285c333a943046dc101d94a0d", + "revCount": 76, "type": "git", "url": "https://gitlab.schukai.com/oss/utilities/version.git" }, diff --git a/devenv.nix b/devenv.nix index 2114cfe87c2c880ade28a1b85cbccd752cb40a4a..5e2e9b7d0800c76b2f4645cf961e791db7c70a78 100644 --- a/devenv.nix +++ b/devenv.nix @@ -11,35 +11,36 @@ taskfileYaml = 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: - - devenv shell build-app - sources: - - source/**/*.go - - source/**/*.mod - - dist/** - - commit: - desc: Commit a feature - cmds: - - do-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 +## 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/** + + commit: + desc: Commit a feature + cmds: + - do-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 ''; }; @@ -52,7 +53,7 @@ command = "${pkgs.alejandra}/bin/alejandra" options = [] includes = [ "*.nix" ] - excludes = [] + excludes = [ "devenv.nix" ] [formatter.go] command = "${pkgs.go}/bin/gofmt" @@ -126,14 +127,14 @@ stage: tag script: - devenv shell tag-version - + rules: - if: '$CI_COMMIT_TAG' when: never - if: '$CI_COMMIT_MESSAGE =~ /NOT_TAGIT/' - when: never - - when: on_success - + when: never + - when: on_success + release: tags: @@ -280,13 +281,13 @@ in { scripts.tag-version.exec = '' #!${pkgs.bash}/bin/bash - + if [[ -z "''${CI_JOB_TOKEN}" ]]; then 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"}" @@ -298,24 +299,24 @@ 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." + echo " ✖ No bump wanted." exit 0 fi - + if [[ -z "''${NEWVERSION}" ]]; then - echo " ✖ No version found." + 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 diff --git a/flake.nix b/flake.nix index c08e62ccfd66b067d04be129718a34de18c8fa5e..e921e4f63bf3d14e13076fb1fdd0ac793108f977 100644 --- a/flake.nix +++ b/flake.nix @@ -13,7 +13,17 @@ rootPath = ./.; - project = import "${rootPath}/project.nix"; + goPkgReleaseData = import "${rootPath}/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"; + goPkgHash = + if (self ? shortRev) + then self.shortRev + else "dirty-not-for-production"; + goPkgVendorHash = goPkgReleaseData.vendorHash or null; # System types to support. supportedSystems = ["x86_64-linux" "x86_64-windows" "x86_64-darwin"]; @@ -28,18 +38,26 @@ pkgs = nixpkgsFor.${system}; in { version = pkgs.buildGoModule { - name = "version"; + name = goPkgName; # In 'nix develop', we don't need a copy of the source tree # in the Nix store. src = ././source; tags = []; # add your tags here (eq "netgo" "osusergo" "static_build") + ldflags = [ + "-X 'main.version=${goPkgVersion}'" + "-X 'main.commit=${goPkgHash}'" + "-X 'main.build=${lastModifiedDate}'" + "-X 'main.name=${goPkgName}'" + "-X 'main.mnemonic=${goPkgMnemonic}'" + ]; + #vendorHash = pkgs.lib.fakeHash; - vendorHash = project.vendorHash; + vendorHash = goPkgVendorHash; meta = with nixpkgs.legacyPackages.${system}.lib; { - description = "Version is a program that automates and simplifies the process of incrementing version numbers for software projects."; + description = goPkgDescription; homepage = "https://gitlab.schukai.com/oss/utilities/version"; license = licenses.mit; maintainers = with maintainers; ["schukai GmbH"]; diff --git a/project.nix b/project.nix index b44f2e3f2ee7d4e1de930557b04d72f8cf783fbf..9c246633ee655333b10aa88d3b3cc939efade2a4 100644 --- a/project.nix +++ b/project.nix @@ -1,10 +1,10 @@ { name = "Version"; mnemonic = "version"; - description = "Manage version information"; + description = "Version is a program that automates and simplifies the process of incrementing version numbers for software projects."; supportedSystems = ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]; compileForSystems = ["linux/arm64" "linux/amd64" "darwin/amd64" "windows/amd64"]; modulePath = "gitlab.schukai.com/oss/utilities/version"; - version="0.6.22"; + version = "0.6.22"; vendorHash = "sha256-uyWI6Gnko1J62XDk6jjRdqZ8TSFtwsTOlDwdR9Xc+ic="; } diff --git a/source/release.go b/source/release.go index e3f5901e15878e185b4c862538bc45e9f6dd4569..e5bce5a17770b732f64faad00861158eb8637648 100644 --- a/source/release.go +++ b/source/release.go @@ -3,11 +3,11 @@ package main // Used when building per // -ldflags "-X main.version=$version -X main.build=$(due --iso-8601 | tr -d "-" )" var ( - version = "dev" - build = "n/a" - mnemonic = "version" - name = "Version" - commit = "n/a" + version = "-/-" + build = "-/-" + mnemonic = "-/-" + name = "-/-" + commit = "-/-" ) type Accessor interface { diff --git a/treefmt.toml b/treefmt.toml index e585279b4929cf46df57e7bb326b108229f1be91..484d9a15458dca9a4bc67b2fa89786dca24301df 120000 --- a/treefmt.toml +++ b/treefmt.toml @@ -1 +1 @@ -/nix/store/7fz761spzs45g2kdvpa6fk9j21slwmdv-Taskfile.yaml \ No newline at end of file +/nix/store/smqjqjy0wa39nvk52jq6x8w1i4bs65g9-Taskfile.yaml \ No newline at end of file