Clean for release

This commit is contained in:
SebClem 2022-06-30 18:02:32 +02:00
parent 5d8f189913
commit fc01439199
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
13 changed files with 179 additions and 78 deletions

View File

@ -3,7 +3,12 @@
name: Build
on: push
on:
push:
branches-ignore:
- "renovate/**"
tags-ignore:
- "**"
jobs:
build-gradle:
@ -16,6 +21,7 @@ jobs:
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
- name: Grant execute permission for gradlew
@ -59,13 +65,7 @@ jobs:
id: branch-name
uses: tj-actions/branch-names@v5.3
- 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

78
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,78 @@
# 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

@ -4,7 +4,7 @@ ARG BUILD_NBR
ARG BRANCH_NAME
ARG BRANCH_NAME
ARG GITHUB_RUN_NUMBER
ADD build/libs/ClaptrapBot-*.jar /bot_src/bot.jar
ADD build/libs/ClaptrapBot.jar /bot_src/claptrapbot.jar
RUN java -version
CMD java -jar bot.jar
CMD java -jar claptrapbot.jar
LABEL org.opencontainers.image.source=https://github.com/Sebclem/ClaptrapBot/

View File

@ -5,18 +5,13 @@ plugins {
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"
}
def versionObj = new Version(major: 0, minor: 2, revision: 0)
group = "net.broken"
archivesBaseName = "ClaptrapBot"
version = "$versionObj"
sourceCompatibility = '17'
repositories {
mavenCentral()
maven {
@ -27,7 +22,6 @@ jar {
enabled(false)
}
configurations.implementation {
exclude group: "org.springframework.boot", module: "spring-boot-starter-logging"
}
@ -38,6 +32,8 @@ 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')
@ -48,21 +44,21 @@ dependencies {
implementation('io.jsonwebtoken:jjwt-impl:0.11.5')
implementation('io.jsonwebtoken:jjwt-jackson:0.11.5')
implementation 'com.sedmelluq:lavaplayer:1.3.77'
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.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'
@ -89,17 +85,3 @@ 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"
],
"commitMessageSuffix": "[skip ci]"
"commitMessagePrefix": ":arrow_up:"
}

View File

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

View File

@ -1,21 +0,0 @@
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,33 +2,34 @@ 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";
// 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"));
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()));
}
}

View File

@ -29,6 +29,7 @@ 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,4 +66,9 @@ public class GuildService {
return roles;
}
public String getInviteLink(){
return MainBot.jda.setRequiredScopes("applications.commands").getInviteUrl(Permission.getPermissions(1644971949399L));
}
}

View File

@ -7,6 +7,9 @@ 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;
@ -32,11 +35,14 @@ 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, () -> {
@ -47,4 +53,14 @@ 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

@ -0,0 +1,24 @@
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

@ -27,4 +27,19 @@ discord:
randomApiKey: ${RANDOM_API_KEY}
springdoc:
paths-to-match: /api/v2/**
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