From 003f67aecb5d16111ed2717c485f7ba7ba58b418 Mon Sep 17 00:00:00 2001 From: Josh Chester Date: Fri, 23 Jan 2026 23:25:56 -0600 Subject: [PATCH] Add lint action for checkstyle Reviewed-on: https://gitea.softwaresmyth.com/numbers/Ornot/pulls/1 Co-authored-by: Josh Chester Co-committed-by: Josh Chester --- .gitea/workflows/build.yml | 18 +++++++ .gitea/workflows/hello_world.yml | 19 +++++++ .gitea/workflows/linting.yml | 54 +++++++++++++++++++ .../com/softwaresmyth/functions/OrNot.java | 19 ++++++- 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/build.yml create mode 100644 .gitea/workflows/hello_world.yml create mode 100644 .gitea/workflows/linting.yml diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml new file mode 100644 index 0000000..d343dcc --- /dev/null +++ b/.gitea/workflows/build.yml @@ -0,0 +1,18 @@ +name: Build with cached gradle +run-name: Building for ${{ gitea.actor }} +on: [label] + +jobs: + Build-with-gradle: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-java@v5 + with: + distribution: 'zulu' + java-version: '22' + cache: 'gradle' +# cache-dependency-path: | # optional +# sub-project/*.gradle* +# sub-project/**/gradle-wrapper.properties + - run: ./gradlew build --no-daemon \ No newline at end of file diff --git a/.gitea/workflows/hello_world.yml b/.gitea/workflows/hello_world.yml new file mode 100644 index 0000000..e18b794 --- /dev/null +++ b/.gitea/workflows/hello_world.yml @@ -0,0 +1,19 @@ +name: Gitea Actions Demo +run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +on: [push] + +jobs: + Explore-Gitea-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" + - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." + - name: Check out repository code + uses: actions/checkout@v6 + - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ gitea.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file diff --git a/.gitea/workflows/linting.yml b/.gitea/workflows/linting.yml new file mode 100644 index 0000000..0b6fb23 --- /dev/null +++ b/.gitea/workflows/linting.yml @@ -0,0 +1,54 @@ +name: Java Google Checkstyle + +permissions: + contents: read + pull-request: write + +on: [pull_request] + +jobs: + checkstyle: + name: 'Checkstyle Linter' + runs-on: ubuntu-latest + env: + CHECKSTYLE_VERSION: '13.0.0' + REVIEWDOG_VERSION: 'latest' + REVIEWDOG_GITEA_API_TOKEN: ${{ secrets.REVIEWDOG_TOKEN }} + GITEA_ADDRESS: http://gitea:3000 + steps: + - name: 'Pull code' + uses: actions/checkout@v6 + + - name: 'Find changed Java files' + id: changed-files + uses: tj-actions/changed-files@v44 + with: + files: | + **.java + + - name: 'Setup Java JDK' + uses: actions/setup-java@v4 + with: + java-version: '22' + distribution: 'zulu' + + - name: 'Setup Reviewdog' + uses: reviewdog/action-setup@v1 + with: + reviewdog_version: latest +# reviewdog_version: ${{ env.REVIEWDOG_VERSION }} + + - name: 'Run Checkstyle with Reviewdog' + if: steps.changed-files.outputs.any_changed == 'true' + run: | + wget https://github.com/checkstyle/checkstyle/releases/download/checkstyle-${{ env.CHECKSTYLE_VERSION }}/checkstyle-${{ env.CHECKSTYLE_VERSION }}-all.jar + + echo "Changed files:" + echo "${{ steps.changed-files.outputs.all_changed_files }}" + + java -jar checkstyle-${{ env.CHECKSTYLE_VERSION }}-all.jar -c google_checks.xml -f xml ${{ steps.changed-files.outputs.all_changed_files }} \ + | reviewdog -f=checkstyle \ + -name="Checkstyle" \ + -reporter="gitea-pr-review" \ + -level="warning" \ + -fail-on-error="true" \ No newline at end of file diff --git a/src/main/java/com/softwaresmyth/functions/OrNot.java b/src/main/java/com/softwaresmyth/functions/OrNot.java index 713b15c..cfddd49 100644 --- a/src/main/java/com/softwaresmyth/functions/OrNot.java +++ b/src/main/java/com/softwaresmyth/functions/OrNot.java @@ -2,18 +2,35 @@ package com.softwaresmyth.functions; import java.util.Optional; -public class OrNot +/** + * Utility class holding the library's methods. + */ +public enum OrNot { + ; // Enum with no variants for a utility class that is not meant to be instantiated. + + /** + * Method that does nothing. + * It fits any method signature that returns void. + */ public static void noop(Object... ignored) { //do nothing } + /** + * Method that does nothing. + * It fits any method signature that does not return void. + */ public static T returnNull(Object... ignored) { return null; } + /** + * Method that does nothing. + * It fits any method signature that returns {@link Optional} for any type. + */ public static Optional returnEmpty(Object... ignored) { return Optional.empty();