Compare commits

..

No commits in common. "155412f0fa411b2ad4c08b4aedffd3f8ae25d4b1" and "c2f8f9261324a8ced3f530265607bf65d678609f" have entirely different histories.

14 changed files with 87 additions and 189 deletions

View File

@ -3,12 +3,7 @@
name: Build
on:
push:
branches-ignore:
- "renovate/**"
tags-ignore:
- "**"
on: push
jobs:
build-gradle:
@ -19,9 +14,8 @@ jobs:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v1
with:
distribution: 'temurin'
java-version: 17
- name: Grant execute permission for gradlew
@ -52,10 +46,10 @@ jobs:
path: build/libs/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v1
- name: Login to ghcr.io
uses: docker/login-action@v2
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
@ -63,14 +57,20 @@ jobs:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.3
uses: tj-actions/branch-names@v5.2
- name: Set tag master
if: steps.branch-name.outputs.current_branch == 'master'
run: |
echo "tag=latest" >> $GITHUB_ENV
- name: Set tag
if: steps.branch-name.outputs.current_branch != 'master'
run: |
echo "tag=${{ steps.branch-name.outputs.current_branch }}" >> $GITHUB_ENV
- name: Build and push Docker
uses: docker/build-push-action@v3
uses: docker/build-push-action@v2
with:
push: true
context: .

View File

@ -1,78 +0,0 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
name: Build Release
on:
push:
tags:
- "**"
jobs:
build-gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Upload Jar File
uses: actions/upload-artifact@v2-preview
with:
name: claptrap_jar
path: build/libs/
build-docker:
runs-on: ubuntu-latest
needs:
- build-gradle
steps:
- uses: actions/checkout@v3
- name: Download artifact
uses: actions/download-artifact@v3.0.0
with:
# Artifact name
name: claptrap_jar
# Destination path
path: build/libs/
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v5.3
- name: Set tag
run: |
echo "tag=${{ steps.branch-name.outputs.tag }}" >> $GITHUB_ENV
- name: Build and push Docker
uses: docker/build-push-action@v3
with:
push: true
context: .
tags: |
ghcr.io/sebclem/claptrapbot:${{ env.tag }}
ghcr.io/sebclem/claptrapbot:latest
file: ./Dockerfile

View File

@ -1,10 +1,10 @@
FROM openjdk:18.0.1
FROM openjdk:17.0.2
WORKDIR /bot_src
ARG BUILD_NBR
ARG BRANCH_NAME
ARG BRANCH_NAME
ARG GITHUB_RUN_NUMBER
ADD build/libs/ClaptrapBot.jar /bot_src/claptrapbot.jar
ADD build/libs/ClaptrapBot-*.jar /bot_src/bot.jar
RUN java -version
CMD java -jar claptrapbot.jar
CMD java -jar bot.jar
LABEL org.opencontainers.image.source=https://github.com/Sebclem/ClaptrapBot/

View File

@ -4,14 +4,19 @@ plugins {
id 'java'
id 'groovy'
id 'org.liquibase.gradle' version '2.1.1'
id "nebula.lint" version "17.7.0"
id "com.gorylenko.gradle-git-properties" version "2.4.1"
id "nebula.lint" version "16.26.0"
}
def versionObj = new Version(major: 0, minor: 2, revision: 0)
group = "net.broken"
archivesBaseName = "ClaptrapBot"
version = "$versionObj"
sourceCompatibility = '17'
repositories {
mavenCentral()
maven {
@ -22,6 +27,7 @@ jar {
enabled(false)
}
configurations.implementation {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
}
@ -32,8 +38,6 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-log4j2")
implementation("org.springframework.boot:spring-boot-starter-oauth2-client")
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('io.micrometer:micrometer-registry-prometheus:1.9.1')
implementation('org.springdoc:springdoc-openapi-ui:1.6.9')
implementation('org.springdoc:springdoc-openapi-security:1.6.9')
@ -44,28 +48,28 @@ dependencies {
implementation('io.jsonwebtoken:jjwt-impl:0.11.5')
implementation('io.jsonwebtoken:jjwt-jackson:0.11.5')
implementation('com.sedmelluq:lavaplayer:1.3.78')
implementation('net.dv8tion:JDA:4.4.0_350')
implementation 'com.sedmelluq:lavaplayer:1.3.77'
implementation 'net.dv8tion:JDA:4.4.0_350'
implementation(platform("org.apache.logging.log4j:log4j-bom:2.17.2"))
implementation(platform("org.apache.logging.log4j:log4j-bom:2.17.1"))
implementation group: 'org.hibernate', name: 'hibernate-validator', version: '7.0.4.Final'
// Use MySQL Connector-J
implementation('mysql:mysql-connector-java:8.0.29')
implementation('org.reflections:reflections:0.10.2')
implementation('org.apache.commons:commons-lang3:3.12.0')
implementation 'mysql:mysql-connector-java:8.0.29'
implementation 'org.reflections:reflections:0.10.2'
implementation 'org.apache.commons:commons-lang3:3.12.0'
liquibaseRuntime('org.liquibase:liquibase-core:4.12.0')
liquibaseRuntime('org.liquibase:liquibase-groovy-dsl:3.0.2')
liquibaseRuntime('mysql:mysql-connector-java:8.0.29')
liquibaseRuntime 'org.liquibase:liquibase-core:4.12.0'
liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:3.0.2'
liquibaseRuntime 'mysql:mysql-connector-java:8.0.29'
liquibaseRuntime group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
liquibaseRuntime group: 'org.liquibase.ext', name: 'liquibase-hibernate5', version: '4.12.0'
liquibaseRuntime 'org.springframework.boot:spring-boot-starter-data-jpa'
liquibaseRuntime 'org.springframework.data:spring-data-jpa'
liquibaseRuntime 'org.springframework:spring-beans'
liquibaseRuntime 'net.dv8tion:JDA:4.4.0_350'
liquibaseRuntime 'com.sedmelluq:lavaplayer:1.3.78'
liquibaseRuntime 'com.sedmelluq:lavaplayer:1.3.77'
liquibaseRuntime sourceSets.main.output
}
@ -85,3 +89,17 @@ liquibase {
}
}
}
class Version {
String major, minor, revision
static String getBuild() {
System.getenv("GITHUB_RUN_NUMBER") ?: System.getProperty("BUILD_NUMBER") ?:
System.getenv("GIT_COMMIT")?.substring(0, 7) ?: System.getProperty("GIT_COMMIT")?.substring(0, 7) ?: "DEV"
}
String toString() {
"${major}.${minor}.${revision}_$build"
}
}

View File

@ -2,5 +2,5 @@
"extends": [
"config:base"
],
"commitMessagePrefix": ":arrow_up:"
"commitMessageSuffix": "[skip ci]"
}

View File

@ -33,8 +33,8 @@ public class GuildController {
@GetMapping("inviteLink")
public InviteLink getInviteLink() {
return new InviteLink(guildService.getInviteLink());
String link = MainBot.jda.setRequiredScopes("applications.commands").getInviteUrl(Permission.getPermissions(1644971949399L));
return new InviteLink(link);
}
@GetMapping("/{guildId}/voiceChannels")

View File

@ -0,0 +1,21 @@
package net.Broken.Api.Controllers;
import net.Broken.Api.Security.Data.JwtPrincipal;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/v2/hello")
@CrossOrigin(origins = "*", maxAge = 3600)
public class HelloController {
@GetMapping("world")
public String helloWorld(Authentication authentication){
JwtPrincipal principal = (JwtPrincipal) authentication.getPrincipal();
return "Hello " + principal.user().getUsername();
}
}

View File

@ -2,34 +2,33 @@ package net.Broken.Api.OpenApi;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
import net.Broken.VersionLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class OpenApiConfig {
private final VersionLoader versionLoader;
public OpenApiConfig(VersionLoader version) {
this.versionLoader = version;
}
@Bean
public OpenAPI customOpenAPI() {
final String securitySchemeName = "JWT";
return new OpenAPI().addSecurityItem(
new SecurityRequirement().addList(securitySchemeName)).components(
new Components().addSecuritySchemes(
securitySchemeName,
new SecurityScheme().name(securitySchemeName)
// final String apiTitle = String.format("%s API", StringUtils.capitalize(moduleName));
return new OpenAPI()
.addSecurityItem(new SecurityRequirement().addList(securitySchemeName))
.components(
new Components()
.addSecuritySchemes(securitySchemeName,
new SecurityScheme()
.name(securitySchemeName)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT"))
).addServersItem(new Server().url("/").description("Default"))
.info(new Info().title("ClaptrapBot API").version(versionLoader.getVersion()));
.bearerFormat("JWT")
)
)
.addServersItem(new Server().url("/").description("Default"));
}
}

View File

@ -29,7 +29,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/swagger-ui/**").permitAll()
.antMatchers("/swagger-ui.html").permitAll()
.antMatchers("/v3/api-docs/**").permitAll()
.antMatchers("/actuator/**").permitAll()
.anyRequest().authenticated();
http.addFilterBefore(jwtFilter(), UsernamePasswordAuthenticationFilter.class);

View File

@ -66,9 +66,4 @@ public class GuildService {
return roles;
}
public String getInviteLink(){
return MainBot.jda.setRequiredScopes("applications.commands").getInviteUrl(Permission.getPermissions(1644971949399L));
}
}

View File

@ -23,7 +23,6 @@ import javax.security.auth.login.LoginException;
import java.util.List;
public class Init {
static private final Logger logger = LogManager.getLogger();

View File

@ -7,9 +7,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import java.util.HashMap;
@ -35,14 +32,11 @@ public class MainBot {
ConfigurableApplicationContext ctx = SpringApplication.run(MainBot.class, args);
BotConfigLoader config = ctx.getBean(BotConfigLoader.class);
VersionLoader versionLoader = ctx.getBean(VersionLoader.class);
logger.info("=======================================");
logger.info("--------------Starting Bot-------------");
logger.info("=======================================");
logger.info("Version: " + versionLoader.getVersion());
jda = Init.initJda(config);
if (jda == null) {
System.exit(SpringApplication.exit(ctx, () -> {
@ -53,14 +47,4 @@ public class MainBot {
Init.polish(jda, config);
ready = true;
}
@Bean
public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
PropertySourcesPlaceholderConfigurer propsConfig
= new PropertySourcesPlaceholderConfigurer();
propsConfig.setLocation(new ClassPathResource("git.properties"));
propsConfig.setIgnoreResourceNotFound(true);
propsConfig.setIgnoreUnresolvablePlaceholders(true);
return propsConfig;
}
}

View File

@ -1,24 +0,0 @@
package net.Broken;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class VersionLoader {
@Value("${git.branch}")
private String branch;
@Value("${git.tags}")
private String tags;
@Value("${git.commit.id.abbrev}")
private String commitId;
public String getVersion(){
String version;
if(tags.isEmpty()){
version = "DEV-" + branch + "-" + commitId;
}else{
version = tags;
}
return version;
}
}

View File

@ -28,18 +28,3 @@ discord:
springdoc:
paths-to-match: /api/v2/**
show-actuator: true
management:
info:
git:
mode: full
enabled: true
endpoints:
enabled-by-default: true
web:
exposure:
include: health, info, prometheus
endpoint:
prometheus:
enabled: true