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

fix: update ci tools #7

parent 96877fcc
No related branches found
No related tags found
No related merge requests found
......@@ -46,13 +46,6 @@ tasks:
cmds:
- ${gitCommit}/bin/git-commit
silent: true
commit:
desc: Commit a feature
cmds:
- do-git-commit
silent: true
default:
desc: Print this help message
......@@ -66,7 +59,7 @@ tasks:
};
treefmtConfig = pkgs.writeTextFile {
name = "Taskfile.yaml";
name = "treefmt.toml";
text = ''
## DO NOT EDIT THIS FILE MANUALLY, IT IS GENERATED BY NIX
......@@ -208,7 +201,12 @@ tasks:
- 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}'
- -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
......@@ -331,33 +329,142 @@ in {
${pkgs.git}/bin/git push origin $CI_COMMIT_REF_NAME --tags
'';
scripts.common-functions.exec = ''
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RESET='\033[0m'
BOLD='\033[1m'
else
RED=""
GREEN=""
RESET=""
fi
is_true() {
val="$1"
if [ "$val" = 'true' ] || [ "$val" = '1' ]; then
return 0
else
return 1
fi
}
get_commit_hash() {
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"
}
echo_green() {
echo -e "$GREEN ✔ $1$RESET"
}
echo_red() {
echo -e "$RED ✖ $1$RESET"
}
echo_todo() {
echo_bold "$BLUE • $1"
}
update_project_version() {
if version auto --git --exit-code-if-no-bump --verbose
then
buildVer=$(version print --git)
local project_nix="${config.devenv.root}/project.nix"
sed -i "s/^\s*version\s*=.*/ version = \"$buildVer\";/" "$project_nix"
echo_green "Project version updated to $buildVer"
${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
}
get_project_version() {
echo "$(version print --git)"
}
if [ -z "$DEBUG_MODE" ]; then
DEBUG_MODE='false'
fi
if [ -n "$CI_JOB_TOKEN" ]; then
CI_MODE='true'
fi
if is_true "$DEBUG_MODE" || is_true "$CI_MODE"; then
set -x
fi
'';
scripts.update-files.exec = ''
#!${pkgs.bash}/bin/bash
update_symlink() {
local source_path="$1"
local target_path="$2"
local file_name="$(basename "$target_path")"
if [[ -L "$source_path" ]]; then
if [[ "$(readlink "$source_path")" != "$target_path" ]]; then
# Link exists but is not up to date
rm "$source_path"
ln -s "$target_path" "$source_path"
fi
elif [[ -e "$source_path" ]]; then
echo "$file_name already exists. Please rename or delete it."
exit 1
else
ln -s "$target_path" "$source_path"
fi
}
source common-functions
create_symlink() {
if ln -s "$1" "$2" 2>/dev/null; then
echo_green "$2 created"
else
echo_red "$2 already exists"
fi
}
update_symlink() {
echo -e " → $1"
local source_path="$1"
local target_path="$2"
local file_name="$(basename "$target_path")"
local source_dir="$(dirname "$source_path")"
mkdir -p "$source_dir" || true
if [[ ! -d "$source_dir" ]]; then
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"
create_symlink "$target_path" "$source_path"
echo_green "$GREEN ✔ $source_path updated$RESET"
else
echo_green "$GREEN ✔ $source_path is up to date$RESET"
fi
elif [[ -e "$source_path" ]]; then
echo_red "$RED ✖ $source_path already exists and is not a symlink. Please remove it manually and run the script again."
exit 1
else
create_symlink "$target_path" "$source_path"
fi
}
# Usage for Taskfile.yaml
update_symlink "${config.devenv.root}/Taskfile.yaml" "${taskfileYaml}"
update_symlink "${config.devenv.root}/.goreleaser.yml" "${goReleaserYaml}"
update_symlink "${config.devenv.root}/treefmt.toml" "${treefmtConfig}"
# Usage for Taskfile.yaml
update_symlink "${config.devenv.root}/Taskfile.yaml" "${taskfileYaml}"
update_symlink "${config.devenv.root}/.goreleaser.yml" "${goReleaserYaml}"
update_symlink "${config.devenv.root}/treefmt.toml" "${treefmtConfig}"
cat ${gitlabCiYaml} > "${config.devenv.root}/.gitlab-ci.yml"
cat ${gitlabCiYaml} > "${config.devenv.root}/.gitlab-ci.yml"
'';
......
......@@ -5,6 +5,6 @@
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.26"; ## don't change this line, it is updated automatically by GitLab CI
vendorHash="sha256-uyWI6Gnko1J62XDk6jjRdqZ8TSFtwsTOlDwdR9Xc+ic="; ## this is updated automatically by update-hashes
version = "0.6.26"; ## don't change this line, it is updated automatically by GitLab CI
vendorHash = "sha256-uyWI6Gnko1J62XDk6jjRdqZ8TSFtwsTOlDwdR9Xc+ic="; ## this is updated automatically by update-hashes
}
/nix/store/smqjqjy0wa39nvk52jq6x8w1i4bs65g9-Taskfile.yaml
\ No newline at end of file
/nix/store/wrp2lsy6h8mzr6fa4n71lqnxw5dliwmc-treefmt.toml
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment