Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/build-main.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 <new_branch_name>\"; \
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.
Expand Down
10 changes: 8 additions & 2 deletions main-protection-win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ 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 <branch_name>`" >> %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%
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- region project data -->
<groupId>mx.whiteweb.sdev</groupId>
<artifactId>white-utils</artifactId>
<version>1.0.8</version>
<version>1.0.9</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>A lightweight library containing shared and generic utility classes for Java-based projects.</description>
<url>https://github.com/WhiteOrganization/white-utils</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
* &#64;Slf4j
* public class MyService implements WhiteLoggeable {
*
* &#64;Override
* public org.slf4j.Logger getLogger() {
* return log;
* }
* &#64;Override public org.slf4j.Logger getLogger() { return log; }
*
* public void myProcess(String name, int age) {
* var log = withSignature("myProcess(name, age)")
Expand Down