diff --git a/.github/workflows/build-project.yml b/.github/workflows/build-project.yml new file mode 100644 index 0000000..629fde0 --- /dev/null +++ b/.github/workflows/build-project.yml @@ -0,0 +1,50 @@ +name: Build InsideAgentDev +run-name: ${{ github.actor }} started a build process. +on: [ push ] +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'oracle' + java-version: '23.0.1' + - run: | + mvn test + + + build: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'oracle' + java-version: '23.0.1' + - run: | + mvn package --file pom.xml + - name: Extract Maven project version + run: | + echo "RELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV + - uses: actions/upload-artifact@v4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + name: InsideAgentDev-${{env.RELEASE_VERSION}} + path: out/Bot/InsideAgentDev-${{env.RELEASE_VERSION}}.jar + + + lint: + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: 'oracle' + java-version: '23.0.1' + - run: | + mvn checkstyle:check \ No newline at end of file diff --git a/.github/workflows/label.yml b/.github/workflows/label.yml deleted file mode 100644 index a8a1bd7..0000000 --- a/.github/workflows/label.yml +++ /dev/null @@ -1,22 +0,0 @@ -# This workflow will triage pull requests and apply a label based on the -# paths that are modified in the pull request. -# -# To use this workflow, you will need to set up a .github/labeler.yml -# file with configuration. For more information, see: -# https://github.com/actions/labeler - -name: Labeler -on: [pull_request] - -jobs: - label: - - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - - steps: - - uses: actions/labeler@v4 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml deleted file mode 100644 index dab69fe..0000000 --- a/.github/workflows/maven-publish.yml +++ /dev/null @@ -1,34 +0,0 @@ -# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path - -name: Maven Package - -on: - release: - types: [created] - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '11' - distribution: 'temurin' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Publish to GitHub Packages Apache Maven - run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml - env: - GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 8f1d781..0000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,39 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn package --file pom.xml - test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn test --file pom.xml diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index b7908a7..0000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,27 +0,0 @@ -# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. -# -# You can adjust the behavior by modifying this file. -# For more information, see: -# https://github.com/actions/stale -name: Mark stale issues and pull requests - -on: - schedule: - - cron: '22 19 * * *' - -jobs: - stale: - - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - - steps: - - uses: actions/stale@v5 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - stale-issue-message: 'Stale issue message' - stale-pr-message: 'Stale pull request message' - stale-issue-label: 'no-issue-activity' - stale-pr-label: 'no-pr-activity' diff --git a/.gitignore b/.gitignore index e415a37..0488f74 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ /target/ /src/main/resources/loginInfo.yml /.idea/ -/src/test/ +/src/test/java/ApiTesting.java /out/ \ No newline at end of file diff --git a/DockerFile b/DockerFile deleted file mode 100644 index 68e84ad..0000000 --- a/DockerFile +++ /dev/null @@ -1,4 +0,0 @@ -FROM openjdk:18-jdk-alpine -ARG JAR_FILE=target/*.jar -COPY ${JAR_FILE} inside-agent.jar -ENTRYPOINT ["java", "-jar", "/inside-agent.jar"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f1e977 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM ubuntu:latest +ARG MVN_VERSION + +WORKDIR /InsideAgentBot +COPY ./out/Bot/InsideAgentDev-${MVN_VERSION}.jar app.jar +COPY ./out/Bot/config/* ./config/ + +RUN apt-get update \ + && apt-get install -y \ + wget \ + maven \ + && rm -rf /var/lib/apt/lists/* +RUN wget https://download.oracle.com/java/24/latest/jdk-24_linux-x64_bin.deb +RUN dpkg -i jdk-24_linux-x64_bin.deb +RUN rm jdk-24_linux-x64_bin.deb + +ENTRYPOINT ["java","-jar","app.jar"] \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 542fe76..6f7880a 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -5,7 +5,15 @@ InsideAgentDev 0.10.0 + ${project.basedir}/src/test/java/ + + maven-surefire-plugin + 3.1.2 + + + + maven-compiler-plugin 3.10.1 @@ -58,6 +66,25 @@ ./docs/ + + maven-checkstyle-plugin + 3.6.0 + + + validate + + check + + + + + UTF-8 + true + false + false + false + + @@ -92,6 +119,26 @@ pom test + + org.junit.jupiter + junit-jupiter-engine + 5.10.0 + test + + + junit-platform-engine + org.junit.platform + + + junit-jupiter-api + org.junit.jupiter + + + apiguardian-api + org.apiguardian + + + 17 diff --git a/pom.xml b/pom.xml index 7f6bfe2..cba949c 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,18 @@ InsideAgentDev 0.10.0 + ${project.basedir}/src/test/java/ + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -70,6 +81,27 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.6.0 + + UTF-8 + true + false + false + false + + + + validate + + check + + + + + @@ -231,6 +263,19 @@ 8.3.0 + + org.junit.jupiter + junit-jupiter-engine + 5.10.0 + test + + + + org.mockito + mockito-core + 5.6.0 + + diff --git a/src/test/java/unit/BasicTests.java b/src/test/java/unit/BasicTests.java new file mode 100644 index 0000000..8641d78 --- /dev/null +++ b/src/test/java/unit/BasicTests.java @@ -0,0 +1,94 @@ +package unit; + +import dev.jacrispys.JavaBot.utils.SecretData; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class BasicTests { + + @Test + void verifyTrue() { + Assertions.assertTrue(true); + } + + @Test + void verifyFalse() { + Assertions.assertFalse(false); + } + + @Test + void verifyInfoLogging() { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + System.setOut(new PrintStream(out)); + + Logger logger = LoggerFactory.getLogger(BasicTests.class); + logger.info("Hello, World!"); + + final String logMessage = out.toString(); + Assertions.assertTrue(logMessage.contains("Hello, World!")); + + } + + @Test + void verifyDebugLogging() { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + System.setOut(new PrintStream(out)); + + Logger logger = LoggerFactory.getLogger(BasicTests.class); + logger.debug("Hello, World!"); + + final String logMessage = out.toString(); + Assertions.assertTrue(logMessage.contains("Hello, World!")); + + } + + @Test + void verifyNoTraceLogging() { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + System.setOut(new PrintStream(out)); + + Logger logger = LoggerFactory.getLogger(BasicTests.class); + logger.trace("Hello, World!"); + + final String logMessage = out.toString(); + Assertions.assertFalse(logMessage.contains("Hello, World!")); + + } + + @Test + void configGenerated() throws IOException, InvocationTargetException, IllegalAccessException, NoSuchMethodException { + SecretData.initLoginInfo(); + Class clazz = SecretData.class; + Method m = clazz.getDeclaredMethod("getClassPath"); + m.setAccessible(true); + String classPath = (String) m.invoke(null); + m.setAccessible(false); + String path = classPath + File.separator + "config" + File.separator + "loginInfo.yml"; + File file = new File(path); + Assertions.assertTrue(file.exists()); + } +} + +class TraceLoggingTest { + @Test + void verifyTraceLogging() { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + System.setOut(new PrintStream(out)); + + Logger logger = LoggerFactory.getLogger(TraceLoggingTest.class); + logger.trace("Hello, World!"); + + final String logMessage = out.toString(); + Assertions.assertTrue(logMessage.contains("Hello, World!")); + + } +} diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000..d074bc7 --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,14 @@ + + + + false + + %d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-15.-15logger{0}) %highlight(%-6level) %msg%n + + + + + + + +