From 7572dfab5c6997271039cf76ad8848f1e66563ac Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:23:24 +0200 Subject: [PATCH 01/16] refactor(old): remove all the ansible related staff --- old/install.yml | 145 --------------------------------- old/tasks/alacritty.yml | 17 ---- old/tasks/bash.yml | 19 ----- old/tasks/bluetooth.yml | 7 -- old/tasks/dunst.yml | 11 --- old/tasks/git.yml | 21 ----- old/tasks/grub2-themes.yml | 19 ----- old/tasks/gtk3.yml | 9 -- old/tasks/homebrew.yml | 37 --------- old/tasks/i3.yml | 15 ---- old/tasks/neofetch.yml | 11 --- old/tasks/neovim.yml | 19 ----- old/tasks/nitrogen.yml | 10 --- old/tasks/ohmyzsh.yml | 22 ----- old/tasks/paru.yml | 36 -------- old/tasks/polybar.yml | 11 --- old/tasks/rofi.yml | 11 --- old/tasks/rofithemes.yml | 21 ----- old/tasks/sddm-sugar-candy.yml | 24 ------ old/tasks/sddm.yml | 21 ----- old/tasks/spotify.yml | 63 -------------- old/tasks/starship.yml | 12 --- old/tasks/tmux.yml | 11 --- old/tasks/tpm.yml | 23 ------ old/tasks/vim-plug.yml | 41 ---------- old/tasks/vim.yml | 11 --- old/tasks/zsh.yml | 11 --- old/vars/os_Archlinux.yml | 106 ------------------------ old/vars/os_MacOSX.yml | 51 ------------ old/vars/profiles/profile1.yml | 57 ------------- 30 files changed, 872 deletions(-) delete mode 100644 old/install.yml delete mode 100644 old/tasks/alacritty.yml delete mode 100644 old/tasks/bash.yml delete mode 100644 old/tasks/bluetooth.yml delete mode 100644 old/tasks/dunst.yml delete mode 100644 old/tasks/git.yml delete mode 100644 old/tasks/grub2-themes.yml delete mode 100644 old/tasks/gtk3.yml delete mode 100644 old/tasks/homebrew.yml delete mode 100644 old/tasks/i3.yml delete mode 100644 old/tasks/neofetch.yml delete mode 100644 old/tasks/neovim.yml delete mode 100644 old/tasks/nitrogen.yml delete mode 100644 old/tasks/ohmyzsh.yml delete mode 100644 old/tasks/paru.yml delete mode 100644 old/tasks/polybar.yml delete mode 100644 old/tasks/rofi.yml delete mode 100644 old/tasks/rofithemes.yml delete mode 100644 old/tasks/sddm-sugar-candy.yml delete mode 100644 old/tasks/sddm.yml delete mode 100644 old/tasks/spotify.yml delete mode 100644 old/tasks/starship.yml delete mode 100644 old/tasks/tmux.yml delete mode 100644 old/tasks/tpm.yml delete mode 100644 old/tasks/vim-plug.yml delete mode 100644 old/tasks/vim.yml delete mode 100644 old/tasks/zsh.yml delete mode 100644 old/vars/os_Archlinux.yml delete mode 100644 old/vars/os_MacOSX.yml delete mode 100644 old/vars/profiles/profile1.yml diff --git a/old/install.yml b/old/install.yml deleted file mode 100644 index cc18855..0000000 --- a/old/install.yml +++ /dev/null @@ -1,145 +0,0 @@ ---- -- hosts: localhost - become: true - tasks: - - name: Get Profile variables - include_vars: "profiles/{{ profile }}.yml" - when: profile is defined - - - name: Get Os variables if no profile - include_vars: "os_{{ ansible_facts['distribution'] }}.yml" - when: profile is undefined - - - name: Before installation - block: - - name: Print before tasks - debug: - var: before - - - name: Run before tasks - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ before }}" - when: before is defined - - - name: Create Workspaces directory - file: - path: "{{ home_dir }}/{{ workspace_dir }}" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - mode: "0755" - when: workspace_dir is defined - - - name: Update packages - shell: "{{ update_command }}" - when: update_command is defined - become_user: "{{ username }}" - - - name: Install IDE - block: - - name: Print ide packages - debug: - var: ide_packages - - - name: Install IDE packages - shell: "{{ install_command }} {{ item }}" - with_items: - - "{{ ide_packages }}" - ignore_errors: true - become_user: "{{ username }}" - - - name: Init IDE configurations - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ ide_config }}" - - - name: Copy user local directory - copy: - src: .local/ - dest: "{{ home_dir }}/.local" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - remote_src: yes - mode: "0755" - - - name: Copy environment configuration - copy: - src: .env - dest: "{{ home_dir }}/.env" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - remote_src: yes - mode: "0755" - - - name: Copy aliases - copy: - src: .aliases - dest: "{{ home_dir }}/.aliases" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - remote_src: yes - mode: "0755" - - - name: Set default shell - shell: "sudo usermod --shell /bin/{{ default_shell }} {{ username }}" - ignore_errors: true - - - name: Set default keyboard layout using setxkbmap - shell: "setxkbmap -layout {{ default_keyboard }}" - when: default_keyboard is defined - become_user: "{{ username }}" - when: ide_install - - - name: Install system environment - block: - - name: Print system packages - debug: - var: system_packages - - - name: Install system packages - shell: "{{ install_command }} {{ item }}" - with_items: - - "{{ system_packages }}" - ignore_errors: true - become_user: "{{ username }}" - - - name: Init system configurations - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ system_config }}" - when: system_config is defined - when: system_install - - - name: Install general packages - block: - - name: Print system packages - debug: - var: general_packages - - - name: Install general packages - shell: "{{ install_command }} {{ item }}" - with_items: - - "{{ general_packages }}" - ignore_errors: true - become_user: "{{ username }}" - - - name: Init general configurations - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ general_config }}" - when: general_config is defined - when: general_install - - - name: After installation - block: - - name: Print after tasks - debug: - var: after - - - name: Run after tasks - include_tasks: "tasks/{{ item }}.yml" - with_items: - - "{{ after }}" - when: after is defined diff --git a/old/tasks/alacritty.yml b/old/tasks/alacritty.yml deleted file mode 100644 index be71f7d..0000000 --- a/old/tasks/alacritty.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -- name: Create alacritty configuration directory - file: - path: "{{ home_dir }}/.config/alacritty" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Init alacritty configuration - copy: - remote_src: yes - src: .config/alacritty/alacritty.yml - dest: "{{ home_dir }}/.config/alacritty/alacritty.yml" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes diff --git a/old/tasks/bash.yml b/old/tasks/bash.yml deleted file mode 100644 index be48ff5..0000000 --- a/old/tasks/bash.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Init bashrc - copy: - remote_src: yes - src: .bashrc - dest: "{{ home_dir }}/.bashrc" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - -- name: Install bash configuration dependencies - shell: "{{ install_command }} {{ bash_package }}" - loop: - - bash-completion - loop_control: - loop_var: bash_package - become_user: "{{ username }}" - diff --git a/old/tasks/bluetooth.yml b/old/tasks/bluetooth.yml deleted file mode 100644 index 1d0d2d3..0000000 --- a/old/tasks/bluetooth.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Enable and start bluetooth - systemd: - name: bluetooth - state: started - enabled: yes - diff --git a/old/tasks/dunst.yml b/old/tasks/dunst.yml deleted file mode 100644 index e5841a5..0000000 --- a/old/tasks/dunst.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy Dunst configurations - copy: - src: .config/dunst/ - dest: "{{ home_dir }}/.config/dunst/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/git.yml b/old/tasks/git.yml deleted file mode 100644 index 5467a6a..0000000 --- a/old/tasks/git.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Add Global gitignore - copy: - remote_src: yes - src: .gitignore - dest: "{{ home_dir }}/.gitignore" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - -- name: Add Global gitconfig - copy: - remote_src: yes - src: .gitconfig - dest: "{{ home_dir }}/.gitconfig" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/grub2-themes.yml b/old/tasks/grub2-themes.yml deleted file mode 100644 index 58ca469..0000000 --- a/old/tasks/grub2-themes.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Remove grub2-themes repository if already exists - file: - state: absent - path: "/tmp/grub2-themes/" - -- name: Clone grub2-themes repository - git: - repo: git@github.com:vinceliuice/grub2-themes.git - dest: "/tmp/grub2-themes/" - become_user: "{{ username }}" - -- name: Install grub2 whitesur theme - shell: - cmd: "./install.sh -b -t whitesur -i color" - chdir: "/tmp/grub2-themes" - become: true - ignore_errors: true - diff --git a/old/tasks/gtk3.yml b/old/tasks/gtk3.yml deleted file mode 100644 index fc18d18..0000000 --- a/old/tasks/gtk3.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -- name: Copy gtk3 session - copy: - src: .config/gtk-3.0/ - dest: "{{ home_dir }}/.config/gtk-3.0/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - remote_src: yes diff --git a/old/tasks/homebrew.yml b/old/tasks/homebrew.yml deleted file mode 100644 index c202294..0000000 --- a/old/tasks/homebrew.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -- name: Enable xcode-select - shell: "xcode-select --install" - register: xcode_result - ignore_errors: true - become_user: "{{ username }}" - -- name: Check if xcode is already installed - debug: - msg: "Xcode is already installed" - when: xcode_result.rc != 0 - -- name: Install homebrew - block: - - name: Remove homebrew repository if already exists - file: - state: absent - path: "/tmp/homebrew.sh" - - - name: Download homebrew installation - get_url: - url: https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh - dest: "/tmp/homebrew.sh" - - - name: Recursively change ownership of homebrew script - file: - path: "/tmp/homebrew.sh" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0777' - - - name: Run homebrew install script - shell: "NONINTERACTIVE=1 bash /tmp/homebrew.sh" - register: homebrew_result - ignore_errors: true - become_user: "{{ username }}" - diff --git a/old/tasks/i3.yml b/old/tasks/i3.yml deleted file mode 100644 index 988173a..0000000 --- a/old/tasks/i3.yml +++ /dev/null @@ -1,15 +0,0 @@ ---- -- name: Copy i3wm configurations - copy: - src: .config/i3/ - dest: "{{ home_dir }}/.config/i3/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - -- name: Restart i3 - shell: "i3-msg restart" - become_user: "{{ username }}" - diff --git a/old/tasks/neofetch.yml b/old/tasks/neofetch.yml deleted file mode 100644 index 830d535..0000000 --- a/old/tasks/neofetch.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy neofetch configurations - copy: - src: .config/neofetch/ - dest: "{{ home_dir }}/.config/neofetch/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/neovim.yml b/old/tasks/neovim.yml deleted file mode 100644 index cf21725..0000000 --- a/old/tasks/neovim.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -- name: Create config/nvim directory - file: - path: "{{ home_dir }}/.config/nvim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - mode: "0755" - -- name: copy init.vim - copy: - remote_src: yes - src: .config/nvim/init.vim - dest: "{{ home_dir }}/.config/nvim/init.vim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/nitrogen.yml b/old/tasks/nitrogen.yml deleted file mode 100644 index 3c35a04..0000000 --- a/old/tasks/nitrogen.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: Copy nitrogen configuration - copy: - src: .config/nitrogen - dest: "{{ home_dir }}/.config/nitrogen" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes diff --git a/old/tasks/ohmyzsh.yml b/old/tasks/ohmyzsh.yml deleted file mode 100644 index a418bf8..0000000 --- a/old/tasks/ohmyzsh.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -- name: Download oh-my-zsh installation - get_url: - url: https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh - dest: "/tmp/ohmyzsh.sh" - -- name: Set default shell value if not defined - set_fact: - default_shell: "{{ default_shell | default('') }}" - when: default_shell is undefined - -- name: Run oh-my-zsh install script - shell: "KEEP_ZSHRC=yes CHSH={{ (default_shell == 'zsh' ) | ternary ('yes', 'no') }} sh /tmp/ohmyzsh.sh --unattended" - register: ohmyzsh_result - ignore_errors: true - become_user: "{{ username }}" - -- name: Check if oh-my-zsh is already installed - debug: - msg: "Oh-my-zsh is already installed" - when: ohmyzsh_result.stdout == "The $ZSH folder already exists ({{ home_dir }}/.oh-my-zsh).\nYou'll need to remove it if you want to reinstall." - diff --git a/old/tasks/paru.yml b/old/tasks/paru.yml deleted file mode 100644 index de9fb99..0000000 --- a/old/tasks/paru.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -- name: Install base-devel packages - shell: sudo pacman -S --needed base-devel - -- name: Remove paru repository if already exists - file: - state: absent - path: "/tmp/paru" - -- name: Clone paru repository - git: - repo: https://github.com/Morganamilo/paru - dest: "/tmp/paru" - -- name: Recursively change ownership of paru directory - file: - path: "/tmp/paru" - state: directory - recurse: yes - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - -- name: Build paru - shell: - cmd: "makepkg -si" - chdir: "/tmp/paru" - become_user: "{{ username }}" - register: paru_result - ignore_errors: true - -- name: Check if paru is already install - debug: - msg: "Paru is probably already installed" - when: paru_result.rc != 0 - diff --git a/old/tasks/polybar.yml b/old/tasks/polybar.yml deleted file mode 100644 index 9f96430..0000000 --- a/old/tasks/polybar.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy polybar configurations - copy: - src: .config/polybar/ - dest: "{{ home_dir }}/.config/polybar/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/rofi.yml b/old/tasks/rofi.yml deleted file mode 100644 index 10b6512..0000000 --- a/old/tasks/rofi.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Copy rofi configurations - copy: - src: .config/rofi/ - dest: "{{ home_dir }}/.config/rofi/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - diff --git a/old/tasks/rofithemes.yml b/old/tasks/rofithemes.yml deleted file mode 100644 index 839d422..0000000 --- a/old/tasks/rofithemes.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Install rofi themes - git: - repo: https://github.com/lr-tech/rofi-themes-collection.git - dest: "/tmp/rofi-themes/" - -- name: Install rofi themes collection - copy: - src: /tmp/rofi-themes/themes - dest: "{{ home_dir }}/.local/share/rofi/" - directory_mode: yes - remote_src: yes - -- name: Recursively change ownership of a directory - file: - path: "{{ home_dir }}/.local/share/rofi/" - state: directory - recurse: yes - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' diff --git a/old/tasks/sddm-sugar-candy.yml b/old/tasks/sddm-sugar-candy.yml deleted file mode 100644 index ea0e01d..0000000 --- a/old/tasks/sddm-sugar-candy.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -- name: Install sddm themes and dependencies - shell: "{{ install_command }} {{ sddm_package }}" - loop: - - sddm-theme-sugar-candy-git - loop_control: - loop_var: sddm_package - become_user: "{{ username }}" - -- name: Update theme of sddm - replace: - path: /etc/sddm.conf - regexp: '^Current=$' - replace: 'Current=Sugar-Candy' - -- name: Update sddm sugar-candy theme - copy: - remote_src: yes - src: sddm/theme.conf - dest: "/usr/share/sddm/themes/Sugar-Candy/theme.conf" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - diff --git a/old/tasks/sddm.yml b/old/tasks/sddm.yml deleted file mode 100644 index 51b9a8e..0000000 --- a/old/tasks/sddm.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -- name: Copy sddm configurations - copy: - src: /usr/lib/sddm/sddm.conf.d/default.conf - dest: /etc/sddm.conf - owner: "{{ username }}" - group: "{{ group | default(username) }}" - directory_mode: yes - mode: '0755' - remote_src: yes - -- name: Disable display-manager to change it - systemd: - name: display-manager - enabled: no - -- name: Enable sddm as diplay-manager - systemd: - name: sddm - enabled: yes - diff --git a/old/tasks/spotify.yml b/old/tasks/spotify.yml deleted file mode 100644 index 233bc27..0000000 --- a/old/tasks/spotify.yml +++ /dev/null @@ -1,63 +0,0 @@ ---- -- name: Install spotify configuration dependencies - shell: "{{ install_command }} {{ spotify_package }}" - loop: - - spicetify-cli - - spicetify-themes-git - loop_control: - loop_var: spotify_package - become_user: "{{ username }}" - -- name: Change permission to Spotify files - shell: > - chmod a+wr /opt/spotify ; - chmod a+wr /opt/spotify/Apps -R ; - -- name: Exec spotify to setup configuration - shell: > - spotify & - sleep 5 ; killall -q spotify - become_user: "{{ username }}" - -- name: Init spicetify configuration - shell: "spicetify" - become_user: "{{ username }}" - -- name: Enable spotify devtool - shell: "spicetify backup apply enable-devtool ;" - become_user: "{{ username }}" - -- name: Get spicetify directory for Dribbblish - shell: "echo $(dirname $(spicetify -c))/Themes/Dribbblish" - register: spicetify_dir - -- name: Create extensions directory - file: - path: "{{ spicetify_dir.stdout }}/../../Extensions" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Enable spotify devtool - copy: - src: /usr/share/spicetify-cli/Themes/Dribbblish/dribbblish.js - dest: "{{ spicetify_dir.stdout }}/../../Extensions/dribbblish.js" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - remote_src: yes - -- name: Enable dribbblish extension - shell: "spicetify config extensions {{ spicetify_dir.stdout }}/../../Extensions/dribbblish.js" - become_user: "{{ username }}" - -- name: Change theme and colorscheme - shell: "spicetify config current_theme Dribbblish color_scheme nord-dark" - become_user: "{{ username }}" - -- name: Change css configuration - shell: "spicetify config inject_css 1 replace_colors 1 overwrite_assets 1" - become_user: "{{ username }}" - -- name: Apply spicetify configuration - shell: "spicetify apply" - become_user: "{{ username }}" diff --git a/old/tasks/starship.yml b/old/tasks/starship.yml deleted file mode 100644 index c24945a..0000000 --- a/old/tasks/starship.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -- name: Download bash starship installation - get_url: - url: https://starship.rs/install.sh - dest: "/tmp/starship.sh" - -- name: Run starship install script - shell: "sh /tmp/starship.sh -y" - register: starship_result - ignore_errors: true - become_user: "{{ username }}" - diff --git a/old/tasks/tmux.yml b/old/tasks/tmux.yml deleted file mode 100644 index d956ba8..0000000 --- a/old/tasks/tmux.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Init Tmux Conf - copy: - remote_src: yes - src: .tmux.conf - dest: "{{ home_dir }}/.tmux.conf" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/tpm.yml b/old/tasks/tpm.yml deleted file mode 100644 index 30f5877..0000000 --- a/old/tasks/tpm.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -- name: Create Workspaces directory - file: - path: "{{ home_dir }}/.tmux/plugins" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - mode: "0755" - -- name: Install tmux plugin manager - git: - repo: https://github.com/tmux-plugins/tpm - dest: "{{ home_dir }}/.tmux/plugins/tpm" - -- name: Install Tmux plugins - shell: "TMUX_PLUGIN_MANAGER_PATH={{ home_dir }}/.tmux/plugins/ {{ home_dir }}/.tmux/plugins/tpm/bin/install_plugins" - -- name: Update Tmux plugins - shell: "TMUX_PLUGIN_MANAGER_PATH={{ home_dir }}/.tmux/plugins/ {{ home_dir }}/.tmux/plugins/tpm/bin/update_plugins all" - -- name: Clean Tmux plugins - shell: "TMUX_PLUGIN_MANAGER_PATH={{ home_dir }}.tmux/plugins/ {{ home_dir }}/.tmux/plugins/tpm/bin/clean_plugins" - diff --git a/old/tasks/vim-plug.yml b/old/tasks/vim-plug.yml deleted file mode 100644 index eb31c42..0000000 --- a/old/tasks/vim-plug.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -- name: Create vim directory - file: - path: "{{ home_dir }}/.vim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Add vim plugins - copy: - remote_src: yes - src: .vim/plugins.vim - dest: "{{ home_dir }}/.vim/plugins.vim" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - -- name: Create vim autoload directory - file: - path: "{{ home_dir }}/.vim/autoload/" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - state: directory - -- name: Download plug.vim - get_url: - url: https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim - dest: "{{ home_dir }}/.vim/autoload/plug.vim" - -- name: Install vim plugins - shell: "vim +PlugInstall! +qa!" - args: - stdin: "\n" - become_user: "{{ username }}" - -- name: Clean vim plugins - shell: "vim +PlugClean! +qa!" - args: - stdin: "\n" - become_user: "{{ username }}" diff --git a/old/tasks/vim.yml b/old/tasks/vim.yml deleted file mode 100644 index c7cec86..0000000 --- a/old/tasks/vim.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Init vimrc - copy: - remote_src: yes - src: .vimrc - dest: "{{ home_dir }}/.vimrc" - owner: "{{ username }}" - group: "{{ group | default(username) }}" - mode: '0755' - backup: yes - diff --git a/old/tasks/zsh.yml b/old/tasks/zsh.yml deleted file mode 100644 index 47594d8..0000000 --- a/old/tasks/zsh.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -- name: Init zshrc - copy: - remote_src: yes - src: .zshrc - dest: "{{ home_dir }}/.zshrc" - mode: '0755' - owner: "{{ username }}" - group: "{{ group | default(username) }}" - backup: yes - diff --git a/old/vars/os_Archlinux.yml b/old/vars/os_Archlinux.yml deleted file mode 100644 index bf49de6..0000000 --- a/old/vars/os_Archlinux.yml +++ /dev/null @@ -1,106 +0,0 @@ ---- -# === Archlinux === -os: Archlinux - -# === System configuration === -username: wabri -install_command: paru -S --noconfirm -update_command: paru -Syyu --noconfirm -home_dir: /home/wabri -workspace_dir: Documents/Workspaces -default_shell: zsh -default_keyboard: us -ide_install: true -system_install: true -general_install: true - -# === Before === -before: - - paru - -# === After === -after: - - bluetooth - -# === Packages === -ide_packages: - - git - - alacritty - - bash - - zsh - - vim - - tmux - - fzf - - nerd-fonts-source-code-pro - - ttf-iosevka-nerd - - ripgrep - - exa - - bat - - git-delta - - nodejs - -system_packages: - - i3-gaps - - playerctl - - arandr - - picom - - nitrogen - - dunst - - arc-x-icons-theme - - blueberry - - rofi - - nordic-theme - - breeze-icons - - graphite-cursor-theme-git - - betterlockscreen - - polybar - - nautilus - - pavucontrol - - sddm - -general_packages: - - vagrant - - spotify - - firefox - - obinskit - - htop - - gtop - - ncdu - - duf - - tldr - - etcher-bin - - vlc - - telegram-desktop - - whatsapp-for-linux - - slack-desktop - - bitwarden - - obs-studio - -# === Configurations === -ide_config: - - alacritty - - vim - - vim-plug - - tmux - - tpm - - bash - - ohmyzsh - - starship - - zsh - - ohmyzsh - - git - -system_config: - - dunst - - rofi - - rofithemes - - gtk3 - - nitrogen - - polybar - - i3 - - sddm - - sddm-sugar-candy - -general_config: - - spotify - diff --git a/old/vars/os_MacOSX.yml b/old/vars/os_MacOSX.yml deleted file mode 100644 index c643560..0000000 --- a/old/vars/os_MacOSX.yml +++ /dev/null @@ -1,51 +0,0 @@ ---- -# === System configuration === -username: test -group: staff -install_command: brew install --quiet -home_dir: /Users/test -workspace_dir: Documents/Workspaces -default_shell: zsh -ide_install: true -system_install: true -general_install: true - -# === Before === -before: - - homebrew - -# === Packages === -ide_packages: - - git - - alacritty - - zsh - - vim - - tmux - - fzf - - ripgrep - - exa - - bat - - git-delta - - starship - -system_packages: - - vagrant - - ruby - - tldr - - ncdu - - duf - - gtop - -general_packages: - - homebrew/cask-drivers/obinskit - - spotify - - balenaetcher - -# === Configurations === -ide_config: - - alacritty - - vim - - tmux - - zsh - - git - diff --git a/old/vars/profiles/profile1.yml b/old/vars/profiles/profile1.yml deleted file mode 100644 index 9b4e027..0000000 --- a/old/vars/profiles/profile1.yml +++ /dev/null @@ -1,57 +0,0 @@ ---- -# === Archlinux === -os: Debian - -# === System configuration === -username: test -install_command: apt-get install --yes -update_command: apt-get update --yes -home_dir: /home/test -workspace_dir: workspace -default_shell: bash -default_keyboard: us -ide_install: false -system_install: false -general_install: false - -# === Before === -#before: -# - paru - -# === After === -#after: -# - bluetooth - -# === Packages === -ide_packages: - - git - - bash - - vim - - tmux - -#system_packages: -# - playerctl -# - arandr -# - blueberry -# - rofi -# - nautilus - -#general_packages: -# - spotify -# - firefox -# - etcher-bin - -# === Configurations === - -ide_config: - - git - - vim - - bash - - tmux - -#system_config: -# - dunst -# - rofi - -#general_config: -# - spotify From 8326cae31d4b6ca343e9530662ded40cdce8476e Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:24:32 +0200 Subject: [PATCH 02/16] fix(Makefile): no new line at the end of the file --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cdfab5f..c3123d5 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,3 @@ build: @echo "Building daje..." - go build -o ./bin/daje . \ No newline at end of file + go build -o ./bin/daje . From bc8475fd7beaa3d3954971e14334e6f4cfc2d61f Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:27:17 +0200 Subject: [PATCH 03/16] chore(go.mod): update cobra package --- go.mod | 4 ++-- go.sum | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index d4fd62b..af74985 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,9 @@ module github.com/Schrodinger-Hat/Daje go 1.18 -require github.com/spf13/cobra v1.4.0 +require github.com/spf13/cobra v1.8.0 require ( - github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect ) diff --git a/go.sum b/go.sum index 0dd8697..c9dfb45 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,16 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= +github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= +github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 2e26948fec7d404abfd5c397f1c341e166000ef3 Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:39:33 +0200 Subject: [PATCH 04/16] refactor(Makefile): add more useful build --- .gitignore | 3 +++ DEVELOPMENT.md | 41 +++++++++++++++++++++++++++++++++++++++++ Makefile | 14 ++++++++++++-- README.md | 9 ++------- constants/contants.go | 4 +++- 5 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 DEVELOPMENT.md diff --git a/.gitignore b/.gitignore index ce27c3b..a53b64a 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ bin # Mac .DS_Store dist/ + +# DAJE +testdata diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md new file mode 100644 index 0000000..4c9f691 --- /dev/null +++ b/DEVELOPMENT.md @@ -0,0 +1,41 @@ +# Development documentation + +## Git Workflow + +We use the [**Forking Workflow**](https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow), so first of all you need a fork of the project and only then you can start contribute to the project. + +## Branches + +The main branch is the only one that are going to be used, no development. The reason is that we don't need it at this moment, we will consider adding more complexity later on if necessary. + +## Requirements + +- [go](https://go.dev/) version **1.18^** +- [gmake](https://www.gnu.org/software/make/) + +## Setup environment + +``` +go mod tidy +``` + +## Run test with testdata + +In the root folder, run: + +``` +make build-test-dev +``` + +This generates all the binary files necessary for daje, now you should find `daje` inside the `bin` directory. To check if everything is gone ok you can run: + +``` +./bin/daje checkhealt +``` + +## Version + +Read this [https://go.dev/doc/modules/version-numbers](https://go.dev/doc/modules/version-numbers). + +Every pull request merged to main will create a new version, this mean that every commit to the main branch will create a new version. + diff --git a/Makefile b/Makefile index c3123d5..4c60a51 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,13 @@ +CURRENT_DIR := $(shell pwd) + +# The version in this build has the form `|` build: - @echo "Building daje..." - go build -o ./bin/daje . + @echo "PROD: Building daje..." + go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD)" -o ./bin/daje . + +# For debugging reason the version in this build has the form `++` +build-test-dev: + @echo "TEST-DEV: Building daje for testing pourpose..." + rm -rf $(CURRENT_DIR)/testdata + go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.DajeConfigBaseDir=$(CURRENT_DIR)/testdata -X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git branch --show-current)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l)" -o ./bin/daje . + diff --git a/README.md b/README.md index b8abc6c..a830daa 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,6 @@ A general purpose dotfiles installer under development, not ready to be used! -### Tech stack - -- [golang](https://go.dev/) - - - ## Usage WIP @@ -67,7 +61,8 @@ WIP Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. -If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". +If you have a suggestion that would make this better, please fork the repo and create a pull request, you can find all the development information in [DEVELOPMENT.md](DEVELOPMENT.md). You can also simply open an issue with the tag "enhancement". + Don't forget to give the project a star! Thanks again! diff --git a/constants/contants.go b/constants/contants.go index ac13532..8e9e4cd 100644 --- a/constants/contants.go +++ b/constants/contants.go @@ -1,3 +1,5 @@ package constants -const DajeDotFile = ".daje" +var DajeConfigBaseDir = "~/.config/" +var DajeDotfileName = "daje.conf" +var Version = "" From 4ceed4014f255b2bd597c776aff4694bb765448c Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:40:45 +0200 Subject: [PATCH 05/16] feat(go.sum): update version in go.sum --- go.sum | 6 ------ 1 file changed, 6 deletions(-) diff --git a/go.sum b/go.sum index c9dfb45..d0e8c2c 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,10 @@ -github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.4.0 h1:y+wJpx64xcgO1V+RcnwW0LEHxTKRi2ZDPSBjWnrg88Q= -github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 55975ce99543e4a3d3b5b582cde4bef106515b05 Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Thu, 13 Jun 2024 17:42:00 +0200 Subject: [PATCH 06/16] fix(internal): change configuration setup --- internal/config/config.go | 36 +++++++++++++++++++++++++++++ internal/config/config_folder.go | 39 -------------------------------- pkg/cmd/init/init.go | 17 +++++++------- 3 files changed, 45 insertions(+), 47 deletions(-) create mode 100644 internal/config/config.go delete mode 100644 internal/config/config_folder.go diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..07df96e --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,36 @@ +package config + +import ( + "log" + "os" + "path/filepath" + + "github.com/Schrodinger-Hat/Daje/constants" +) + +func InitEmptyDaje() error { + dajeConfigPath := filepath.Join(constants.DajeConfigBaseDir) + if err := os.Mkdir(dajeConfigPath, 0755); err != nil { + return err + } + + dajeConfigFile := filepath.Join(constants.DajeConfigBaseDir, constants.DajeDotfileName) + if _, err := os.Create(dajeConfigFile); err != nil { + return err + } + + return nil +} + +func IsDajeInitialized() bool { + dotFile := filepath.Join(constants.DajeConfigBaseDir, constants.DajeDotfileName) + if _, err := os.Stat(dotFile); err != nil { + if os.IsNotExist(err) { + return false + } + + log.Fatal(err) + } + + return true +} diff --git a/internal/config/config_folder.go b/internal/config/config_folder.go deleted file mode 100644 index 4e7f54a..0000000 --- a/internal/config/config_folder.go +++ /dev/null @@ -1,39 +0,0 @@ -package config - -import ( - "log" - "os" - "os/user" - "path/filepath" - - "github.com/Schrodinger-Hat/Daje/constants" -) - -func InitEmptyDaje() error { - currentUser, err := user.Current() - if err != nil { - return err - } - dotFile := filepath.Join(currentUser.HomeDir, constants.DajeDotFile) - if err = os.Mkdir(dotFile, os.ModeDir); err != nil { - return err - } - return nil -} - -func IsDajeInitialized() bool { - currentUser, err := user.Current() - if err != nil { - log.Fatal(err) - } - dotFile := filepath.Join(currentUser.HomeDir, constants.DajeDotFile) - if _, err := os.Stat(dotFile); err != nil { - if os.IsNotExist(err) { - return false - } - - log.Fatal(err) - } - - return true -} diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index 6d7cff2..c5279d5 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -21,17 +21,18 @@ func NewCmdInit() *cobra.Command { } func submitAction() error { - if config.IsDajeInitialized() { + if !config.IsDajeInitialized() { + err := config.InitEmptyDaje() + if err != nil { + fmt.Println(err) + return nil + } + + fmt.Println("Daje has been initialized successfully!") + } else { fmt.Println("Daje has been already initialized in the system.") return nil } - err := config.InitEmptyDaje() - if err != nil { - return nil - } - - fmt.Println("Daje has been initialized successfully!") - return nil } From ffea2573942a8c5aadeaa03bf2790bcb9831e1ab Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:52:07 +0200 Subject: [PATCH 07/16] feat(checkhealth): create new command to check overall status --- Makefile | 24 ++++++++++++++++++----- constants/contants.go | 4 ++++ internal/tuning/tuning.go | 6 ++++++ pkg/cmd/checkhealth/checkhealth.go | 31 ++++++++++++++++++++++++++++++ pkg/cmd/root/root.go | 2 ++ 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 internal/tuning/tuning.go create mode 100644 pkg/cmd/checkhealth/checkhealth.go diff --git a/Makefile b/Makefile index 4c60a51..ffc3e30 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,27 @@ CURRENT_DIR := $(shell pwd) +clean: + @echo "\n----- Start CLEAN -----\n" + @echo "# Remove all the daje metadata and builds..." + rm -r $(CURRENT_DIR)/bin &>/dev/null + @echo "\n----- End CLEAN -----" + # The version in this build has the form `|` -build: - @echo "PROD: Building daje..." +build: clean + @echo "\n----- Start BUILD -----\n" + @echo "# Building daje for production environment..." go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD)" -o ./bin/daje . + @echo "\n----- End BUILD -----" # For debugging reason the version in this build has the form `++` -build-test-dev: - @echo "TEST-DEV: Building daje for testing pourpose..." - rm -rf $(CURRENT_DIR)/testdata +build-test-dev: clean + @echo "\n----- Start BUILD-TEST-DEV -----\n" + @echo "# Building daje for development environment..." go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.DajeConfigBaseDir=$(CURRENT_DIR)/testdata -X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git branch --show-current)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l)" -o ./bin/daje . + @echo "\n----- End BUILD-TEST-DEV -----" +checkhealth: build-test-dev + @echo "\n----- Start CHECKHEALTH -----\n" + @echo "# run checkhealth command..." + ./bin/daje checkhealth + @echo "\n----- End CHECKHEALTH -----" diff --git a/constants/contants.go b/constants/contants.go index 8e9e4cd..c5220fe 100644 --- a/constants/contants.go +++ b/constants/contants.go @@ -1,5 +1,9 @@ package constants +import "path" + var DajeConfigBaseDir = "~/.config/" var DajeDotfileName = "daje.conf" +var DajeDotfilePath = path.Join(DajeConfigBaseDir, DajeDotfileName) + var Version = "" diff --git a/internal/tuning/tuning.go b/internal/tuning/tuning.go new file mode 100644 index 0000000..8c26411 --- /dev/null +++ b/internal/tuning/tuning.go @@ -0,0 +1,6 @@ +package tuning + +// TODO: when the first tuning options will be available we need something to prove that the system is tuned accordingly to the configuration +func IsSystemTuned() bool { + return true +} diff --git a/pkg/cmd/checkhealth/checkhealth.go b/pkg/cmd/checkhealth/checkhealth.go new file mode 100644 index 0000000..d1eb47e --- /dev/null +++ b/pkg/cmd/checkhealth/checkhealth.go @@ -0,0 +1,31 @@ +package checkhealth + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/Schrodinger-Hat/Daje/constants" + "github.com/Schrodinger-Hat/Daje/internal/tuning" +) + +func NewCmdCheckhealth() *cobra.Command { + cmd := &cobra.Command{ + Use: "checkhealth [flags]", + Short: "Check Daje health", + RunE: func(cmd *cobra.Command, args []string) error { + return submitAction() + }, + } + + return cmd +} + +func submitAction() error { + + fmt.Println("Version: ", constants.Version) + fmt.Println("Configuration path: ", constants.DajeDotfilePath) + fmt.Println("Tuning: ", tuning.IsSystemTuned()) + + return nil +} diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index f3b35f9..2068490 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -3,6 +3,7 @@ package root import ( "github.com/spf13/cobra" + "github.com/Schrodinger-Hat/Daje/pkg/cmd/checkhealth" initCmd "github.com/Schrodinger-Hat/Daje/pkg/cmd/init" ) @@ -18,6 +19,7 @@ $ daje init } cmd.AddCommand(initCmd.NewCmdInit()) + cmd.AddCommand(checkhealth.NewCmdCheckhealth()) return cmd } From 89e611cf36b7964a486c8ffd7609e24533c83250 Mon Sep 17 00:00:00 2001 From: GabrielePuliti <12409541+Wabri@users.noreply.github.com> Date: Fri, 14 Jun 2024 11:59:00 +0200 Subject: [PATCH 08/16] docs(DEVELOPMENT): update with checkhealth new command --- DEVELOPMENT.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 4c9f691..3e46275 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -30,7 +30,36 @@ make build-test-dev This generates all the binary files necessary for daje, now you should find `daje` inside the `bin` directory. To check if everything is gone ok you can run: ``` -./bin/daje checkhealt +./bin/daje checkhealth +``` + +You should have something like this: + +```bash +----- Start CLEAN ----- + +# Remove all the daje metadata and builds... +rm -r /bin &>/dev/null + +----- End CLEAN ----- + +----- Start BUILD-TEST-DEV ----- + +# Building daje for development environment... +go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.DajeConfigBaseDir=/testdata -X +github.com/Schrodinger-Hat/Daje/constants.Version=" -o ./bin/daje . + +----- End BUILD-TEST-DEV ----- + +----- Start CHECKHEALTH ----- + +# run checkhealth command... +./bin/daje checkhealth +Version: +Configuration path: /testdata/daje.conf +Tuning: true + +----- End CHECKHEALTH ----- ``` ## Version From 7bd71496e260fbd88450ee57d7438e33e60e3169 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Thu, 1 Aug 2024 17:42:13 +0200 Subject: [PATCH 09/16] feat(*): add basic function to handle configuration --- Makefile | 6 +-- constants/contants.go | 14 +++++-- go.mod | 25 ++++++++++++- go.sum | 59 ++++++++++++++++++++++++++++++ internal/config/config.go | 45 +++++++++++++---------- internal/dotfiles/init.go | 25 +++++++++++++ internal/tuning/tuning.go | 6 --- main.go | 6 ++- pkg/cmd/checkhealth/checkhealth.go | 30 ++++++++++----- pkg/cmd/init/init.go | 36 ++++++++++-------- pkg/cmd/root/root.go | 8 ++-- testdata/.config/daje/.dajerc | 2 + testdata/.dajerc | 2 + 13 files changed, 198 insertions(+), 66 deletions(-) create mode 100644 internal/dotfiles/init.go delete mode 100644 internal/tuning/tuning.go create mode 100644 testdata/.config/daje/.dajerc create mode 100644 testdata/.dajerc diff --git a/Makefile b/Makefile index ffc3e30..72a6fc4 100644 --- a/Makefile +++ b/Makefile @@ -3,21 +3,21 @@ CURRENT_DIR := $(shell pwd) clean: @echo "\n----- Start CLEAN -----\n" @echo "# Remove all the daje metadata and builds..." - rm -r $(CURRENT_DIR)/bin &>/dev/null + rm -r $(CURRENT_DIR)/bin &2>/dev/null @echo "\n----- End CLEAN -----" # The version in this build has the form `|` build: clean @echo "\n----- Start BUILD -----\n" @echo "# Building daje for production environment..." - go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD)" -o ./bin/daje . + go build -ldflags "-X github.com/Schroedinger-Hat/Daje/constants.Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD)" -o ./bin/daje . @echo "\n----- End BUILD -----" # For debugging reason the version in this build has the form `++` build-test-dev: clean @echo "\n----- Start BUILD-TEST-DEV -----\n" @echo "# Building daje for development environment..." - go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.DajeConfigBaseDir=$(CURRENT_DIR)/testdata -X github.com/Schrodinger-Hat/Daje/constants.Version=$(shell git branch --show-current)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l)" -o ./bin/daje . + go build -ldflags "-X github.com/Schroedinger-Hat/Daje/constants.DajeBasePath=$(CURRENT_DIR)/testdata -X github.com/Schroedinger-Hat/Daje/constants.Version=$(shell git branch --show-current)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l | tr -d ' ')" -o ./bin/daje . @echo "\n----- End BUILD-TEST-DEV -----" checkhealth: build-test-dev diff --git a/constants/contants.go b/constants/contants.go index c5220fe..910d44a 100644 --- a/constants/contants.go +++ b/constants/contants.go @@ -1,9 +1,15 @@ package constants -import "path" +var DajeBasePath = "~" +var DajeConfigFileName = ".dajerc" +var DajeConfigPathOrder = []string{ + ".config/daje/", + ".", +} -var DajeConfigBaseDir = "~/.config/" -var DajeDotfileName = "daje.conf" -var DajeDotfilePath = path.Join(DajeConfigBaseDir, DajeDotfileName) +var DajeConfigParameters = []string{ + "dotfiles_directory", + "dotfiles_remote", +} var Version = "" diff --git a/go.mod b/go.mod index af74985..5bb2a07 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,31 @@ -module github.com/Schrodinger-Hat/Daje +module github.com/Schroedinger-Hat/Daje go 1.18 -require github.com/spf13/cobra v1.8.0 +require ( + github.com/spf13/cobra v1.8.0 + github.com/spf13/viper v1.19.0 +) require ( + github.com/fsnotify/fsnotify v1.7.0 // indirect + github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/sagikazarmark/locafero v0.4.0 // indirect + github.com/sagikazarmark/slog-shim v0.1.0 // indirect + github.com/sourcegraph/conc v0.3.0 // indirect + github.com/spf13/afero v1.11.0 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/subosito/gotenv v1.6.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.9.0 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/text v0.14.0 // indirect + gopkg.in/ini.v1 v1.67.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d0e8c2c..4966411 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,69 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= +github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= +github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= +github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= +github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= +github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= +github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= +github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI= +github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= +github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= +go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= +gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= +gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/config/config.go b/internal/config/config.go index 07df96e..f7f8b11 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,36 +1,41 @@ package config import ( + "errors" "log" "os" - "path/filepath" + "path" - "github.com/Schrodinger-Hat/Daje/constants" + "github.com/Schroedinger-Hat/Daje/constants" + "github.com/spf13/viper" ) -func InitEmptyDaje() error { - dajeConfigPath := filepath.Join(constants.DajeConfigBaseDir) - if err := os.Mkdir(dajeConfigPath, 0755); err != nil { - return err - } +func ExtractConfigParameter(elementName string) (string, error) { + return viper.GetString(elementName), nil +} - dajeConfigFile := filepath.Join(constants.DajeConfigBaseDir, constants.DajeDotfileName) - if _, err := os.Create(dajeConfigFile); err != nil { - return err +func LoadConfig() error { + configFilePath, err := getConfigFilePath() + if err != nil { + errorMessage := "LoadConfig:getConfigFilePath->" + err.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) + } + viper.SetConfigFile(configFilePath) + if err = viper.ReadInConfig(); err != nil { + errorMessage := "LoadConfig:SetConfigFile->" + err.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) } - return nil } -func IsDajeInitialized() bool { - dotFile := filepath.Join(constants.DajeConfigBaseDir, constants.DajeDotfileName) - if _, err := os.Stat(dotFile); err != nil { - if os.IsNotExist(err) { - return false +func getConfigFilePath() (string, error) { + for _, value := range constants.DajeConfigPathOrder { + currentFilepath := path.Join(constants.DajeBasePath, value, constants.DajeConfigFileName) + if _, err := os.Stat(currentFilepath); err == nil { + return currentFilepath, nil } - - log.Fatal(err) } - - return true + return "", errors.New("getConfigFilePath: Configuration not found") } diff --git a/internal/dotfiles/init.go b/internal/dotfiles/init.go new file mode 100644 index 0000000..02d52d0 --- /dev/null +++ b/internal/dotfiles/init.go @@ -0,0 +1,25 @@ +package dotfiles + +import ( + "errors" + "log" + "os" + "path" + + "github.com/Schroedinger-Hat/Daje/constants" + "github.com/spf13/viper" +) + +func InitializeDotfiles() error { + err := os.MkdirAll(path.Join( + constants.DajeBasePath, + viper.GetString("dotfiles_directory"), + ), os.ModePerm) + + if err != nil { + errorMessage := "InitializeDotfiles->" + err.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) + } + return nil +} diff --git a/internal/tuning/tuning.go b/internal/tuning/tuning.go deleted file mode 100644 index 8c26411..0000000 --- a/internal/tuning/tuning.go +++ /dev/null @@ -1,6 +0,0 @@ -package tuning - -// TODO: when the first tuning options will be available we need something to prove that the system is tuned accordingly to the configuration -func IsSystemTuned() bool { - return true -} diff --git a/main.go b/main.go index 254ea12..5347506 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,9 @@ package main import ( "os" - "github.com/Schrodinger-Hat/Daje/pkg/cmd/root" + "github.com/Schroedinger-Hat/Daje/constants" + "github.com/Schroedinger-Hat/Daje/pkg/cmd/root" + "github.com/spf13/viper" ) type exitCode int @@ -14,6 +16,8 @@ const ( ) func main() { + viper.SetConfigType("yaml") + viper.SetConfigName(constants.DajeConfigFileName) code := mainRun() os.Exit(int(code)) } diff --git a/pkg/cmd/checkhealth/checkhealth.go b/pkg/cmd/checkhealth/checkhealth.go index d1eb47e..a706689 100644 --- a/pkg/cmd/checkhealth/checkhealth.go +++ b/pkg/cmd/checkhealth/checkhealth.go @@ -1,31 +1,41 @@ package checkhealth import ( - "fmt" + "errors" + "log" "github.com/spf13/cobra" + "github.com/spf13/viper" - "github.com/Schrodinger-Hat/Daje/constants" - "github.com/Schrodinger-Hat/Daje/internal/tuning" + "github.com/Schroedinger-Hat/Daje/constants" + "github.com/Schroedinger-Hat/Daje/internal/config" ) -func NewCmdCheckhealth() *cobra.Command { +func CmdCheckhealth() *cobra.Command { cmd := &cobra.Command{ Use: "checkhealth [flags]", Short: "Check Daje health", - RunE: func(cmd *cobra.Command, args []string) error { - return submitAction() + RunE: func(cmd *cobra.Command, args []string) error { //nolint:all + return submitCmdCheckhealth() }, } return cmd } -func submitAction() error { +func submitCmdCheckhealth() error { + err := config.LoadConfig() + if err != nil { + errorMessage := "Checkhealth->" + err.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) + } + log.Println("[Checkhealth]:[LoadConfig]", "Configuration Path:"+viper.GetViper().ConfigFileUsed()) - fmt.Println("Version: ", constants.Version) - fmt.Println("Configuration path: ", constants.DajeDotfilePath) - fmt.Println("Tuning: ", tuning.IsSystemTuned()) + log.Println("[Checkhealth]:[ConfigValues]") + for _, value := range constants.DajeConfigParameters { + log.Println(value + ": " + viper.GetString(value)) + } return nil } diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index c5279d5..0e7048a 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -1,38 +1,42 @@ package init import ( - "fmt" + "errors" + "log" "github.com/spf13/cobra" - "github.com/Schrodinger-Hat/Daje/internal/config" + "github.com/Schroedinger-Hat/Daje/internal/config" + "github.com/Schroedinger-Hat/Daje/internal/dotfiles" ) -func NewCmdInit() *cobra.Command { +func CmdInit() *cobra.Command { cmd := &cobra.Command{ Use: "init [flags]", Short: "Initialize daje on your system", RunE: func(cmd *cobra.Command, args []string) error { //nolint:all - return submitAction() + return submitCmdInit() }, } return cmd } -func submitAction() error { - if !config.IsDajeInitialized() { - err := config.InitEmptyDaje() - if err != nil { - fmt.Println(err) - return nil - } - - fmt.Println("Daje has been initialized successfully!") - } else { - fmt.Println("Daje has been already initialized in the system.") - return nil +func submitCmdInit() error { + funcErrorHandle := func(err error) error { + errorMessage := "CmdInit->" + err.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) + } + functionOrder := []func() error{ + config.LoadConfig, + dotfiles.InitializeDotfiles, } + for _, function := range functionOrder { + if err := function(); err != nil { + return funcErrorHandle(err) + } + } return nil } diff --git a/pkg/cmd/root/root.go b/pkg/cmd/root/root.go index 2068490..1599880 100644 --- a/pkg/cmd/root/root.go +++ b/pkg/cmd/root/root.go @@ -3,8 +3,8 @@ package root import ( "github.com/spf13/cobra" - "github.com/Schrodinger-Hat/Daje/pkg/cmd/checkhealth" - initCmd "github.com/Schrodinger-Hat/Daje/pkg/cmd/init" + "github.com/Schroedinger-Hat/Daje/pkg/cmd/checkhealth" + initCmd "github.com/Schroedinger-Hat/Daje/pkg/cmd/init" ) func NewCmdRoot() *cobra.Command { @@ -18,8 +18,8 @@ $ daje init `, } - cmd.AddCommand(initCmd.NewCmdInit()) - cmd.AddCommand(checkhealth.NewCmdCheckhealth()) + cmd.AddCommand(initCmd.CmdInit()) + cmd.AddCommand(checkhealth.CmdCheckhealth()) return cmd } diff --git a/testdata/.config/daje/.dajerc b/testdata/.config/daje/.dajerc new file mode 100644 index 0000000..344ba0d --- /dev/null +++ b/testdata/.config/daje/.dajerc @@ -0,0 +1,2 @@ +dotfiles_directory: ../dotfiles +dotfiles_remote: https://github.com/Wabri/dotfiles diff --git a/testdata/.dajerc b/testdata/.dajerc new file mode 100644 index 0000000..55feb50 --- /dev/null +++ b/testdata/.dajerc @@ -0,0 +1,2 @@ +dotfiles_directory: .config/dotfiles +dotfiles_remote: https://github.com/Wabri/dotfiles From 540886b43fa69cdb0ffac38fb0ae41e4ed78bf39 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Thu, 8 Aug 2024 15:07:32 +0200 Subject: [PATCH 10/16] feat(.github/workflows): add new ci steps --- .github/workflows/ci.yaml | 40 ++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f1b27a3..5dfa50d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,17 +13,47 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: wagoid/commitlint-github-action@v4 - with: - firstParent: true - golangci: - name: lint + + - uses: wagoid/commitlint-github-action@v6 + + golangci-lint: + needs: commit_lint runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Run golangci-lint uses: golangci/golangci-lint-action@v6 with: version: latest only-new-issues: false args: --timeout 2m --config .golangci.yaml + + go_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Run unit test + run: go test + + checkhealth: + runs-on: ubuntu-latest + needs: go_test + steps: + - uses: actions/checkout@v4 + + - name: Run checkhealth + run: make checkhealth + + - id: pr_calculate + run: echo "pr=pr#${{ github.ref_name }}" | sed "s/\/merge//" >> "$GITHUB_OUTPUT" + + - id: sha_short + run: echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" + + - uses: actions/upload-artifact@v4 + with: + name: daje-${{ steps.pr_calculate.outputs.pr }}-${{ steps.sha_short.outputs.sha_short }} + path: bin/daje + From bf1c699797bd64de3415cd16f26ac23d6eefe704 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:57:09 +0200 Subject: [PATCH 11/16] feat(tests): initialise tests --- constants/constants_test.go | 1 + internal/config/config_test.go | 1 + internal/dotfiles/init_test.go | 1 + main_test.go | 24 ++++++++++++++++++++++++ pkg/cmd/checkhealth/checkhealth_test.go | 1 + pkg/cmd/init/init_test.go | 1 + pkg/cmd/root/root_test.go | 1 + 7 files changed, 30 insertions(+) create mode 100644 constants/constants_test.go create mode 100644 internal/config/config_test.go create mode 100644 internal/dotfiles/init_test.go create mode 100644 main_test.go create mode 100644 pkg/cmd/checkhealth/checkhealth_test.go create mode 100644 pkg/cmd/init/init_test.go create mode 100644 pkg/cmd/root/root_test.go diff --git a/constants/constants_test.go b/constants/constants_test.go new file mode 100644 index 0000000..1255fc8 --- /dev/null +++ b/constants/constants_test.go @@ -0,0 +1 @@ +package constants diff --git a/internal/config/config_test.go b/internal/config/config_test.go new file mode 100644 index 0000000..d912156 --- /dev/null +++ b/internal/config/config_test.go @@ -0,0 +1 @@ +package config diff --git a/internal/dotfiles/init_test.go b/internal/dotfiles/init_test.go new file mode 100644 index 0000000..3acdce0 --- /dev/null +++ b/internal/dotfiles/init_test.go @@ -0,0 +1 @@ +package dotfiles diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..1141a43 --- /dev/null +++ b/main_test.go @@ -0,0 +1,24 @@ +package main + +import ( + "os" + "testing" +) + +// For fun +func Test_MainRunShouldExitOkWhenNoSubcommand(t *testing.T) { + _, w, _ := os.Pipe() + stdout := os.Stdout + stderr := os.Stderr + + os.Stdout = w + os.Stderr = w + + if mainRun() != exitOk { + t.Fatal("mainRun() not ok") + } + + _ = w.Close() + os.Stdout = stdout + os.Stderr = stderr +} diff --git a/pkg/cmd/checkhealth/checkhealth_test.go b/pkg/cmd/checkhealth/checkhealth_test.go new file mode 100644 index 0000000..e02b12d --- /dev/null +++ b/pkg/cmd/checkhealth/checkhealth_test.go @@ -0,0 +1 @@ +package checkhealth diff --git a/pkg/cmd/init/init_test.go b/pkg/cmd/init/init_test.go new file mode 100644 index 0000000..3631b0c --- /dev/null +++ b/pkg/cmd/init/init_test.go @@ -0,0 +1 @@ +package init diff --git a/pkg/cmd/root/root_test.go b/pkg/cmd/root/root_test.go new file mode 100644 index 0000000..c804031 --- /dev/null +++ b/pkg/cmd/root/root_test.go @@ -0,0 +1 @@ +package root From 7d48322fedecd4f3c1b9155f09f3c0fc2c31c900 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Sat, 10 Aug 2024 16:37:42 +0200 Subject: [PATCH 12/16] feat(internal/config): add config tests --- internal/config/config.go | 3 +- internal/config/config_test.go | 54 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index f7f8b11..af2b2a3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -33,7 +33,8 @@ func LoadConfig() error { func getConfigFilePath() (string, error) { for _, value := range constants.DajeConfigPathOrder { currentFilepath := path.Join(constants.DajeBasePath, value, constants.DajeConfigFileName) - if _, err := os.Stat(currentFilepath); err == nil { + _, err := os.Stat(currentFilepath) + if err == nil { return currentFilepath, nil } } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index d912156..820d566 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -1 +1,55 @@ package config + +import ( + "errors" + "os" + "path" + "testing" + + "github.com/Schroedinger-Hat/Daje/constants" +) + +const configNotExistsFileName = ".confignotexists" + +func Test_getConfigFilePathShouldPassWithNoErrorsWhenFindConfigurationFile(t *testing.T) { + workingDirectory, _ := os.Getwd() + constants.DajeBasePath = workingDirectory + "/../../testdata" + + _, err := getConfigFilePath() + + if err != nil { + t.Fatalf("getConfigFilePath should pass with no errors when find configuration file: expected=\"\" - get=\"%v\"", err) + } +} + +func Test_getConfigFilePathShouldReturnTheExactPathWhenItFindTheConfigurationFile(t *testing.T) { + workingDirectory, _ := os.Getwd() + constants.DajeBasePath = workingDirectory + "/../../testdata" + expectedConfigPath := path.Join(constants.DajeBasePath, "../testdata/.config/daje", constants.DajeConfigFileName) + + path, _ := getConfigFilePath() + + if path != expectedConfigPath { + t.Fatalf("getConfigFilePath should return the exact path when find configuration file: expected=%v - get=%v", expectedConfigPath, path) + } +} + +func Test_getConfigFilePathShouldFailWhenDontFindConfigurationFile(t *testing.T) { + constants.DajeConfigFileName = configNotExistsFileName + + _, err := getConfigFilePath() + errExpected := errors.New("getConfigFilePath: Configuration not found") + + if err.Error() != errExpected.Error() { + t.Fatalf("getConfigFilePath should fail when don't find configuration file: expected=%v - get=%v", errExpected, err) + } +} + +func Test_getConfigFilePathShouldHaveEmptyPathWhenDontFindConfigurationFile(t *testing.T) { + constants.DajeConfigFileName = configNotExistsFileName + path, _ := getConfigFilePath() + + if path != "" { + t.Fatalf("getConfigFilePath should have empty path when don't find configuration file: expected=\"\" - get=%v", path) + } +} From 61c3fce3b964e3ffa01dca04a8928ca6c9010113 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:48:33 +0200 Subject: [PATCH 13/16] fix(*): update path with absolute + more --- DEVELOPMENT.md | 2 +- Makefile | 6 ++- constants/contants.go | 16 +++++--- internal/config/config.go | 65 ++++++++++++++++++++++-------- internal/config/config_test.go | 34 ++++++++-------- internal/dotfiles/init.go | 9 ++--- main.go | 8 +++- pkg/cmd/checkhealth/checkhealth.go | 13 +----- testdata/.config/daje/.dajerc | 5 ++- testdata/.dajerc | 5 ++- 10 files changed, 98 insertions(+), 65 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 3e46275..db2f909 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -46,7 +46,7 @@ rm -r /bin &>/dev/null ----- Start BUILD-TEST-DEV ----- # Building daje for development environment... -go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.DajeConfigBaseDir=/testdata -X +go build -ldflags "-X github.com/Schrodinger-Hat/Daje/constants.ConfigBasepath=/testdata -X github.com/Schrodinger-Hat/Daje/constants.Version=" -o ./bin/daje . ----- End BUILD-TEST-DEV ----- diff --git a/Makefile b/Makefile index 72a6fc4..44743a9 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ CURRENT_DIR := $(shell pwd) +BRANCH := $(shell git branch --show-current) +DAJE_TEST_NAME := daje-test-$(BRANCH) clean: @echo "\n----- Start CLEAN -----\n" @@ -17,11 +19,11 @@ build: clean build-test-dev: clean @echo "\n----- Start BUILD-TEST-DEV -----\n" @echo "# Building daje for development environment..." - go build -ldflags "-X github.com/Schroedinger-Hat/Daje/constants.DajeBasePath=$(CURRENT_DIR)/testdata -X github.com/Schroedinger-Hat/Daje/constants.Version=$(shell git branch --show-current)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l | tr -d ' ')" -o ./bin/daje . + go build -ldflags "-X github.com/Schroedinger-Hat/Daje/constants.ConfigBasepath=$(CURRENT_DIR)/testdata -X github.com/Schroedinger-Hat/Daje/constants.Version=$(BRANCH)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l | tr -d ' ')" -o ./bin/$(DAJE_TEST_NAME) . @echo "\n----- End BUILD-TEST-DEV -----" checkhealth: build-test-dev @echo "\n----- Start CHECKHEALTH -----\n" @echo "# run checkhealth command..." - ./bin/daje checkhealth + ./bin/$(DAJE_TEST_NAME) checkhealth @echo "\n----- End CHECKHEALTH -----" diff --git a/constants/contants.go b/constants/contants.go index 910d44a..17e3136 100644 --- a/constants/contants.go +++ b/constants/contants.go @@ -1,15 +1,19 @@ package constants -var DajeBasePath = "~" -var DajeConfigFileName = ".dajerc" -var DajeConfigPathOrder = []string{ +var ConfigBasepath = "" +var ConfigFileName = ".dajerc" +var ConfigPathOrder = []string{ ".config/daje/", ".", } -var DajeConfigParameters = []string{ - "dotfiles_directory", - "dotfiles_remote", +var ConfigParameters = []string{ + "dotfiles.local", + "dotfiles.remote", +} + +var ConfigParametersPath = []string{ + "dotfiles.local", } var Version = "" diff --git a/internal/config/config.go b/internal/config/config.go index af2b2a3..626a954 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -10,33 +10,64 @@ import ( "github.com/spf13/viper" ) -func ExtractConfigParameter(elementName string) (string, error) { - return viper.GetString(elementName), nil +type configReturn struct { + Value string + Error error } func LoadConfig() error { - configFilePath, err := getConfigFilePath() - if err != nil { - errorMessage := "LoadConfig:getConfigFilePath->" + err.Error() - log.Fatal(errorMessage) - return errors.New(errorMessage) + configFilePath := "" + viperReadInConfig := func() configReturn { + viper.SetConfigFile(configFilePath) + return configReturn{"", viper.ReadInConfig()} } - viper.SetConfigFile(configFilePath) - if err = viper.ReadInConfig(); err != nil { - errorMessage := "LoadConfig:SetConfigFile->" + err.Error() - log.Fatal(errorMessage) - return errors.New(errorMessage) + functionOrder := []func() configReturn{ + checkBasePath, + getConfigFilePath, + viperReadInConfig, } + + for _, function := range functionOrder { + result := function() + if result.Value != "" { + configFilePath = result.Value + } + if result.Error != nil { + errorMessage := "LoadConfig->" + result.Error.Error() + log.Fatal(errorMessage) + return errors.New(errorMessage) + } + } + + pathRelativeToAbsolute(path.Dir(configFilePath)) return nil } -func getConfigFilePath() (string, error) { - for _, value := range constants.DajeConfigPathOrder { - currentFilepath := path.Join(constants.DajeBasePath, value, constants.DajeConfigFileName) +func checkBasePath() configReturn { + if constants.ConfigBasepath == "" { + homepath, err := os.UserHomeDir() + if err != nil { + return configReturn{"", errors.New("getConfigFilePath: User home not found")} + } + constants.ConfigBasepath = homepath + } + return configReturn{"", nil} +} + +func pathRelativeToAbsolute(configDirectory string) { + for _, value := range constants.ConfigParametersPath { + configValue := viper.GetString(value) + viper.Set(value, path.Join(configDirectory, configValue)) + } +} + +func getConfigFilePath() configReturn { + for _, value := range constants.ConfigPathOrder { + currentFilepath := path.Join(constants.ConfigBasepath, value, constants.ConfigFileName) _, err := os.Stat(currentFilepath) if err == nil { - return currentFilepath, nil + return configReturn{currentFilepath, nil} } } - return "", errors.New("getConfigFilePath: Configuration not found") + return configReturn{"", errors.New("getConfigFilePath: Configuration not found")} } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 820d566..1c3ab98 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -13,43 +13,43 @@ const configNotExistsFileName = ".confignotexists" func Test_getConfigFilePathShouldPassWithNoErrorsWhenFindConfigurationFile(t *testing.T) { workingDirectory, _ := os.Getwd() - constants.DajeBasePath = workingDirectory + "/../../testdata" + constants.ConfigBasepath = workingDirectory + "/../../testdata" - _, err := getConfigFilePath() + result := getConfigFilePath() - if err != nil { - t.Fatalf("getConfigFilePath should pass with no errors when find configuration file: expected=\"\" - get=\"%v\"", err) + if result.Error != nil { + t.Fatalf("getConfigFilePath should pass with no errors when find configuration file: expected=\"\" - get=\"%v\"", result.Error) } } func Test_getConfigFilePathShouldReturnTheExactPathWhenItFindTheConfigurationFile(t *testing.T) { workingDirectory, _ := os.Getwd() - constants.DajeBasePath = workingDirectory + "/../../testdata" - expectedConfigPath := path.Join(constants.DajeBasePath, "../testdata/.config/daje", constants.DajeConfigFileName) + constants.ConfigBasepath = workingDirectory + "/../../testdata" + expectedConfigPath := path.Join(constants.ConfigBasepath, "../testdata/.config/daje", constants.ConfigFileName) - path, _ := getConfigFilePath() + result := getConfigFilePath() - if path != expectedConfigPath { - t.Fatalf("getConfigFilePath should return the exact path when find configuration file: expected=%v - get=%v", expectedConfigPath, path) + if result.Value != expectedConfigPath { + t.Fatalf("getConfigFilePath should return the exact path when find configuration file: expected=%v - get=%v", expectedConfigPath, result.Value) } } func Test_getConfigFilePathShouldFailWhenDontFindConfigurationFile(t *testing.T) { - constants.DajeConfigFileName = configNotExistsFileName + constants.ConfigFileName = configNotExistsFileName - _, err := getConfigFilePath() + result := getConfigFilePath() errExpected := errors.New("getConfigFilePath: Configuration not found") - if err.Error() != errExpected.Error() { - t.Fatalf("getConfigFilePath should fail when don't find configuration file: expected=%v - get=%v", errExpected, err) + if result.Error.Error() != errExpected.Error() { + t.Fatalf("getConfigFilePath should fail when don't find configuration file: expected=%v - get=%v", errExpected, result.Error) } } func Test_getConfigFilePathShouldHaveEmptyPathWhenDontFindConfigurationFile(t *testing.T) { - constants.DajeConfigFileName = configNotExistsFileName - path, _ := getConfigFilePath() + constants.ConfigFileName = configNotExistsFileName + result := getConfigFilePath() - if path != "" { - t.Fatalf("getConfigFilePath should have empty path when don't find configuration file: expected=\"\" - get=%v", path) + if result.Value != "" { + t.Fatalf("getConfigFilePath should have empty path when don't find configuration file: expected=\"\" - get=%v", result.Value) } } diff --git a/internal/dotfiles/init.go b/internal/dotfiles/init.go index 02d52d0..0a7fb89 100644 --- a/internal/dotfiles/init.go +++ b/internal/dotfiles/init.go @@ -6,20 +6,17 @@ import ( "os" "path" - "github.com/Schroedinger-Hat/Daje/constants" "github.com/spf13/viper" ) func InitializeDotfiles() error { - err := os.MkdirAll(path.Join( - constants.DajeBasePath, - viper.GetString("dotfiles_directory"), - ), os.ModePerm) - + err := os.MkdirAll(path.Join(viper.GetString("dotfiles.local")), os.ModePerm) if err != nil { errorMessage := "InitializeDotfiles->" + err.Error() log.Fatal(errorMessage) return errors.New(errorMessage) } + + // TODO: clone dotfiles.remote return nil } diff --git a/main.go b/main.go index 5347506..5743d1b 100644 --- a/main.go +++ b/main.go @@ -1,9 +1,11 @@ package main import ( + "log" "os" "github.com/Schroedinger-Hat/Daje/constants" + "github.com/Schroedinger-Hat/Daje/internal/config" "github.com/Schroedinger-Hat/Daje/pkg/cmd/root" "github.com/spf13/viper" ) @@ -17,7 +19,11 @@ const ( func main() { viper.SetConfigType("yaml") - viper.SetConfigName(constants.DajeConfigFileName) + viper.SetConfigName(constants.ConfigFileName) + if err := config.LoadConfig(); err != nil { + errorMessage := "main->" + err.Error() + log.Fatal(errorMessage) + } code := mainRun() os.Exit(int(code)) } diff --git a/pkg/cmd/checkhealth/checkhealth.go b/pkg/cmd/checkhealth/checkhealth.go index a706689..84276c2 100644 --- a/pkg/cmd/checkhealth/checkhealth.go +++ b/pkg/cmd/checkhealth/checkhealth.go @@ -1,14 +1,12 @@ package checkhealth import ( - "errors" "log" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/Schroedinger-Hat/Daje/constants" - "github.com/Schroedinger-Hat/Daje/internal/config" ) func CmdCheckhealth() *cobra.Command { @@ -24,17 +22,10 @@ func CmdCheckhealth() *cobra.Command { } func submitCmdCheckhealth() error { - err := config.LoadConfig() - if err != nil { - errorMessage := "Checkhealth->" + err.Error() - log.Fatal(errorMessage) - return errors.New(errorMessage) - } log.Println("[Checkhealth]:[LoadConfig]", "Configuration Path:"+viper.GetViper().ConfigFileUsed()) - log.Println("[Checkhealth]:[ConfigValues]") - for _, value := range constants.DajeConfigParameters { - log.Println(value + ": " + viper.GetString(value)) + for _, value := range constants.ConfigParameters { + log.Println("[Checkhealth]:[LoadConfig]", value+": "+viper.GetString(value)) } return nil diff --git a/testdata/.config/daje/.dajerc b/testdata/.config/daje/.dajerc index 344ba0d..a57f439 100644 --- a/testdata/.config/daje/.dajerc +++ b/testdata/.config/daje/.dajerc @@ -1,2 +1,3 @@ -dotfiles_directory: ../dotfiles -dotfiles_remote: https://github.com/Wabri/dotfiles +dotfiles: + local: ../dotfiles + remote: https://github.com/Wabri/dotfiles diff --git a/testdata/.dajerc b/testdata/.dajerc index 55feb50..2e0eb92 100644 --- a/testdata/.dajerc +++ b/testdata/.dajerc @@ -1,2 +1,3 @@ -dotfiles_directory: .config/dotfiles -dotfiles_remote: https://github.com/Wabri/dotfiles +dotfiles: + local: .config/dotfiles + remote: https://github.com/Wabri/dotfiles From a73df2a9878dfb0a96d50bad11f4fbb813e43323 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Fri, 30 Aug 2024 17:58:41 +0200 Subject: [PATCH 14/16] refactor(Makefile): extract parameters for readability --- Makefile | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 44743a9..24ae183 100644 --- a/Makefile +++ b/Makefile @@ -2,24 +2,38 @@ CURRENT_DIR := $(shell pwd) BRANCH := $(shell git branch --show-current) DAJE_TEST_NAME := daje-test-$(BRANCH) +# Build Flags +FLAG_PREFIX := -X github.com/Schroedinger-Hat/Daje/constants +# TEST-DEV +FLAG_TEST-DEV_CONFIGBASEPATH := $(FLAG_PREFIX).ConfigBasepath=$(CURRENT_DIR)/testdata +FLAG_TEST-DEV_VERSION := $(FLAG_PREFIX).Version=$(BRANCH)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l | tr -d ' ') +# PROD +FLAG_VERSION := $(FLAG_PREFIX).Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD) + clean: @echo "\n----- Start CLEAN -----\n" @echo "# Remove all the daje metadata and builds..." rm -r $(CURRENT_DIR)/bin &2>/dev/null @echo "\n----- End CLEAN -----" +test: + @echo "\n----- Start BUILD -----\n" + @echo "# Running unit test..." + go test ./... + @echo "\n----- End BUILD -----" + # The version in this build has the form `|` -build: clean +build: test clean @echo "\n----- Start BUILD -----\n" @echo "# Building daje for production environment..." - go build -ldflags "-X github.com/Schroedinger-Hat/Daje/constants.Version=$(shell git describe --exact-match --tags $(git rev-parse HEAD) 2>/dev/null || git rev-parse --short HEAD)" -o ./bin/daje . + go build -ldflags "$(FLAG_VERSION)" -o ./bin/daje . @echo "\n----- End BUILD -----" # For debugging reason the version in this build has the form `++` -build-test-dev: clean +build-test-dev: test clean @echo "\n----- Start BUILD-TEST-DEV -----\n" @echo "# Building daje for development environment..." - go build -ldflags "-X github.com/Schroedinger-Hat/Daje/constants.ConfigBasepath=$(CURRENT_DIR)/testdata -X github.com/Schroedinger-Hat/Daje/constants.Version=$(BRANCH)+$(shell git rev-parse --short origin/main)+$(shell git status --porcelain | wc -l | tr -d ' ')" -o ./bin/$(DAJE_TEST_NAME) . + go build -ldflags "$(FLAG_TEST-DEV_CONFIGBASEPATH) $(FLAG_TEST-DEV_VERSION)" -o ./bin/$(DAJE_TEST_NAME) . @echo "\n----- End BUILD-TEST-DEV -----" checkhealth: build-test-dev From 94b806ba53c0bb898c727adca980c621ce949458 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:07:41 +0200 Subject: [PATCH 15/16] refactor(config): update function return struct --- internal/config/config.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 626a954..70de080 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -10,18 +10,18 @@ import ( "github.com/spf13/viper" ) -type configReturn struct { +type configFunctionReturn struct { Value string Error error } func LoadConfig() error { configFilePath := "" - viperReadInConfig := func() configReturn { + viperReadInConfig := func() configFunctionReturn { viper.SetConfigFile(configFilePath) - return configReturn{"", viper.ReadInConfig()} + return configFunctionReturn{"", viper.ReadInConfig()} } - functionOrder := []func() configReturn{ + functionOrder := []func() configFunctionReturn{ checkBasePath, getConfigFilePath, viperReadInConfig, @@ -43,15 +43,15 @@ func LoadConfig() error { return nil } -func checkBasePath() configReturn { +func checkBasePath() configFunctionReturn { if constants.ConfigBasepath == "" { homepath, err := os.UserHomeDir() if err != nil { - return configReturn{"", errors.New("getConfigFilePath: User home not found")} + return configFunctionReturn{"", errors.New("getConfigFilePath: User home not found")} } constants.ConfigBasepath = homepath } - return configReturn{"", nil} + return configFunctionReturn{"", nil} } func pathRelativeToAbsolute(configDirectory string) { @@ -61,13 +61,13 @@ func pathRelativeToAbsolute(configDirectory string) { } } -func getConfigFilePath() configReturn { +func getConfigFilePath() configFunctionReturn { for _, value := range constants.ConfigPathOrder { currentFilepath := path.Join(constants.ConfigBasepath, value, constants.ConfigFileName) _, err := os.Stat(currentFilepath) if err == nil { - return configReturn{currentFilepath, nil} + return configFunctionReturn{currentFilepath, nil} } } - return configReturn{"", errors.New("getConfigFilePath: Configuration not found")} + return configFunctionReturn{"", errors.New("getConfigFilePath: Configuration not found")} } From 808ec65db8c0458675815bf9ef98e5e08c3b1d23 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Fri, 30 Aug 2024 18:11:37 +0200 Subject: [PATCH 16/16] refactor(main): extract LoadConfig from if condition --- main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 5743d1b..154b026 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,8 @@ const ( func main() { viper.SetConfigType("yaml") viper.SetConfigName(constants.ConfigFileName) - if err := config.LoadConfig(); err != nil { + err := config.LoadConfig() + if err != nil { errorMessage := "main->" + err.Error() log.Fatal(errorMessage) }