diff --git a/.github/workflows/build-main.yml b/.github/workflows/build-main.yml new file mode 100644 index 0000000..1d99c51 --- /dev/null +++ b/.github/workflows/build-main.yml @@ -0,0 +1,24 @@ +name: Build Main + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 8 + + - name: Build and verify + run: mvn -B -e -DskipTests=false verify diff --git a/README.md b/README.md index 4ab9739..bf4742e 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,16 @@ [![Maven Central](https://img.shields.io/maven-central/v/mx.whiteweb.sdev/white-utils.svg)](https://search.maven.org/artifact/mx.whiteweb.sdev/white-utils) [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) -[![Build Status](https://img.shields.io/badge/build-passing-brightgreen.svg)](#) +[![Build Main](https://github.com/WhiteOrganization/white-utils/actions/workflows/build-main.yml/badge.svg)](https://github.com/WhiteOrganization/white-utils/actions/workflows/build-main.yml) + + A lightweight library containing shared and generic utility classes for Java-based projects. ## 1) What is this repository for? ### 1.1) Quick summary -Version: `1.0.8` +Version: `1.0.9` **White_Utils** is a public Java library that provides standardized and generic utility classes to simplify common operations such as logging, formatting, and general helper functions across Java and Maven projects. It is published for public consumption and is also used as a standard within White Organization. @@ -41,7 +43,7 @@ public class MyService implements WhiteLoggeable { public void myProcess(String name, int age) { // Method chaining is supported - all logging methods return LogContext var log = withSignature("myProcess(name, age)") - .start("Processing user {} with age {}", name, age) + .start("Processing user {} with age {}", name, age); log.debug("User age is {}", age); if (age < 18) { @@ -71,13 +73,39 @@ This library uses: ### 3.3) Configuration Steps -#### 3.3.1) Environment Configuration -_Please execute the `main-protection-win.bat` file in the root directory of the project -to protect the main branch from being corrupted unintentionally._ +#### 3.3.1) `main` Branch Protection +In order for us to ensure that the `main` branch isn't accidentally corrupted, we're implementing a check that will prevent users from pushing directly to `main` and forces every change to be merged with a pull request. + +You can execute this file: [`main-protection-win.bat`](main-protection-win.bat) before editing any text, code, branches, or anything in this repository to help you with these cases. + +#### 3.3.2) Git Alias +When executing [`main-protection-win.bat`](main-protection-win.bat), the script will open a file in notepad. -You will require all the Development elements in your environment. +Only if you haven't done so already, paste the following git alias script at the end of that file : -An IDE with Maven support is suggested for you to make any modifications to the code. +``` + +[alias] + main2branch = "!f() { \ + if [ \"$#\" -ne 1 ]; then \ + echo \"Usage: git main2branch \"; \ + exit 1; \ + fi; \ + current_branch=$(git rev-parse --abbrev-ref HEAD); \ + if [ \"$current_branch\" != \"main\" ]; then \ + echo \"Error: You must be on 'main' branch to use this alias.\"; \ + exit 1; \ + fi; \ + new_branch=$1; \ + git fetch origin main || exit 1; \ + git branch \"$new_branch\" || exit 1; \ + git reset --hard origin/main || exit 1; \ + echo \"Moved local-only commits to branch '$new_branch'.\"; \ + git checkout \"$new_branch\" || exit 1; \ + }; f" + +``` +This script creates a new alias, `main2branch`, that takes all local commits on main, that aren't present in origin, and moves them to a new branch, with a customizable name. Usage: `git main2branch new-branch`. This is useful for situations when you accidentally commit on `main` locally, and need to move those changes to the new branch. ## 4) How to Deploy? The deployment process is automated at this point, once the new version is detected to be merge into main from a PR, a GitHub action will build the artifact and upload it to Maven Central. diff --git a/main-protection-win.bat b/main-protection-win.bat index 932b9e5..be91ad6 100644 --- a/main-protection-win.bat +++ b/main-protection-win.bat @@ -17,8 +17,10 @@ echo then >> %HOOK_FILE% echo. echo ^>^&2 "Pushing to branch $branch is not allowed. To push to this branch:" >> %HOOK_FILE% echo. echo ^>^&2 "1) Create a new branch with the commits you already have: 'git branch new-branch'" >> %HOOK_FILE% echo. echo ^>^&2 "2) Make sure you know how many commits you need to go back and the number of commits will be called 'n'" >> %HOOK_FILE% -echo. echo ^>^&2 "3) Move master back by n commits (this will delete the commits from master but not from your new branch): 'git reset --hard HEAD~n'" >> %HOOK_FILE% -echo. echo ^>^&2 "4) Checkout from the new branch and then push from there and generate a Pull Request to this branch: 'git checkout new-branch'" >> %HOOK_FILE% +echo. echo ^>^&2 "3) Move $branch back by n commits (this will delete the commits from $branch but not from your new branch): 'git reset --hard HEAD~n'" >> %HOOK_FILE% +echo. echo ^>^&2 "4) Checkout from the new branch and then push from there" >> %HOOK_FILE% +echo. echo ^>^&2 " --> You can complete points 1-4 with the `main2branch` alias. You can read more about the `main2branch` alias in the README file. If you have already configured the alias its usage is: `git main2branch `" >> %HOOK_FILE% +echo. echo ^>^&2 "5) Try to generate the Pull Request again from this branch ." >> %HOOK_FILE% echo exit 1 >> %HOOK_FILE% echo fi >> %HOOK_FILE% echo done >> %HOOK_FILE% @@ -26,6 +28,10 @@ echo done >> %HOOK_FILE% echo exit 0 >> %HOOK_FILE% echo Created pre-push hook successfully, now `push`es are blocked on the main branches. + +echo Paste the git alias script mentioned in +echo this repository's README at the end of the file that will open after you continue. pause +notepad %USERPROFILE%\.gitconfig exit REM endlocal diff --git a/pom.xml b/pom.xml index c2dac60..2425a09 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ mx.whiteweb.sdev white-utils - 1.0.8 + 1.0.9 ${project.groupId}:${project.artifactId} A lightweight library containing shared and generic utility classes for Java-based projects. https://github.com/WhiteOrganization/white-utils diff --git a/src/main/java/org/white_sdev/utils/logging/WhiteLoggeable.java b/src/main/java/org/white_sdev/utils/logging/WhiteLoggeable.java index 743ff47..c9fe1b1 100644 --- a/src/main/java/org/white_sdev/utils/logging/WhiteLoggeable.java +++ b/src/main/java/org/white_sdev/utils/logging/WhiteLoggeable.java @@ -5,10 +5,7 @@ * @Slf4j * public class MyService implements WhiteLoggeable { * - * @Override - * public org.slf4j.Logger getLogger() { - * return log; - * } + * @Override public org.slf4j.Logger getLogger() { return log; } * * public void myProcess(String name, int age) { * var log = withSignature("myProcess(name, age)")