Skip to content

Commit

Permalink
Fix bug where discord intents break JDA library
Browse files Browse the repository at this point in the history
  • Loading branch information
shayaantx committed Nov 9, 2020
1 parent 35c0c9a commit f541d5f
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 53 deletions.
169 changes: 120 additions & 49 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM centos:7
RUN yum update clean all
RUN yum -y install java-1.8.0-openjdk-devel.x86_64
RUN yum -y install maven
RUN yum -y install git
RUN adduser jenkins
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
""";
Expand All @@ -21,46 +22,109 @@ def getChangelistDescription() {
}

def getNextVersion() {
def latestVersion = readFile "${env.WORKSPACE}/version.txt"
def latestVersion = readFile "${env.WORKSPACE}/src/main/resources/version.txt"
print "version=" + latestVersion;
def (major, minor, patch) = latestVersion.tokenize('.').collect { it.toInteger() };
print "major=" + major + ",minor=" + minor + ",patch=" + patch;
print "next version: major=" + major + ",minor=" + minor + ",patch=" + (patch + 1);
return "${major}.${minor}.${patch + 1}";
}

node {
try {
// whether or not to deploy to github & dockerhub
def deploy;
// the version being built/released
def tag;
// the docker image
def image;

def email;
withCredentials([string(credentialsId: 'botdarr-email', variable: 'botdarr_email')]) {
email = "${botdarr_email}";
}

def username;
withCredentials([string(credentialsId: 'botdarr-username', variable: 'botdarr_username')]) {
username = "${botdarr_username}";
}

pipeline {
agent any
stages {
stage("Checkout") {
checkout([$class: 'GitSCM', branches: [[name: '**']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'github', url: 'https://github.com/shayaantx/botdar.git']]])
steps {
script {
checkout([$class: 'GitSCM', branches: [[name: '**']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'github', url: "https://github.com/${username}/botdar.git"]]])
env.GIT_COMMIT_MSG = sh (script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true).trim()
deploy = !env.GIT_COMMIT_MSG.startsWith("Update version to") && env.BRANCH_NAME == "development";
}
}
}

stage('Prepare docker') {
fileOperations([fileCreateOperation(fileContent: "${dockerFileContents}", fileName: './Dockerfile')]);
steps {
script {
fileOperations([fileCreateOperation(fileContent: "${dockerFileContents}", fileName: './Dockerfile')]);
tag = getNextVersion();
image = docker.build("botdarr-image", "-f ./Dockerfile .");
}
}
}

def tag = getNextVersion();
def image = docker.build("botdarr-image", "-f ./Dockerfile .");
image.inside('-u root') {
stage('Build') {
sh './mvnw --no-transfer-progress compile'
stage('Build') {
steps {
script {
image.inside('-u root') {
sh './mvnw --no-transfer-progress compile'
}
}
}

stage("Test") {
sh './mvnw --no-transfer-progress test'
}
stage('Test') {
steps {
script {
image.inside('-u root') {
sh './mvnw --no-transfer-progress test'
}
}
}

stage("Package") {
fileOperations([fileCreateOperation(fileContent: "version=${tag}", fileName: './src/main/resources/version.txt')]);
sh './mvnw --no-transfer-progress package -DskipTests'
}
stage('Package') {
steps {
script {
image.inside('-u root') {
sh "echo ${tag} > ./src/main/resources/version.txt"
sh './mvnw --no-transfer-progress package -DskipTests'
archiveArtifacts 'target/botdarr-release.jar'
}
}
}

stage("Archive") {
archiveArtifacts 'target/botdarr-release.jar'
}

stage('Update version') {
when {
expression {
return deploy
}
}

if (env.BRANCH_NAME == "development") {
//don't upload for PR's
stage('Create/Upload Release') {
steps {
sshagent(['jenkins-ssh-key-github']) {
sh "git remote set-url origin [email protected]:${username}/botdarr.git"
sh "git config --global user.name ${username}"
sh "git config --global user.email ${email}"
sh "ssh -oStrictHostKeyChecking=no ${username}@github.com || true"
sh "git add src/main/resources/version.txt"
sh "git commit -m \"Update version to ${tag}\""
sh "git push origin HEAD:${env.BRANCH_NAME}"
}
}
}

stage('Create/Upload Release') {
when {
expression {
return deploy
}
}
steps {
script {
withCredentials([string(credentialsId: 'git-token', variable: 'token')]) {
def description = getChangelistDescription();
print "description=" + description;
Expand All @@ -72,35 +136,42 @@ node {
}
}
}

stage('Upload to dockerhub') {
when {
expression {
return deploy
}
}
steps {
script {
def dockerFileImage = """
FROM centos:7
RUN yum update; yum clean all; yum -y install java-1.8.0-openjdk-devel.x86_64;
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
ENV PATH=$PATH:$JAVA_HOME/bin
if (env.BRANCH_NAME == "development") {
//don't upload for PR's
stage('Upload to dockerhub') {
def dockerFileImage = """
FROM centos:7
RUN yum update; yum clean all; yum -y install java-1.8.0-openjdk-devel.x86_64;
ENV JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
ENV PATH=$PATH:$JAVA_HOME/bin
RUN mkdir -p /home/botdarr
ADD target/botdarr-release.jar /home/botdarr
RUN mkdir -p /home/botdarr
ADD target/botdarr-release.jar /home/botdarr
WORKDIR /home/botdarr
RUN java -version
WORKDIR /home/botdarr
RUN java -version
ENTRYPOINT ["java", "-jar", "botdarr-release.jar"]
""";
fileOperations([fileCreateOperation(fileContent: "${dockerFileImage}", fileName: './DockerfileUpload')]);
def releaseTag = "latest";
def imageWithReleaseTag = docker.build("shayaantx/botdarr:${releaseTag}", "-f ./DockerfileUpload .");
withDockerRegistry(credentialsId: 'docker-credentials') {
imageWithReleaseTag.push();
ENTRYPOINT ["java", "-jar", "botdarr-release.jar"]
""";
fileOperations([fileCreateOperation(fileContent: "${dockerFileImage}", fileName: './DockerfileUpload')]);
def releaseTag = "latest";
def imageWithReleaseTag = docker.build("${username}/botdarr:${releaseTag}", "-f ./DockerfileUpload .");
withDockerRegistry(credentialsId: 'docker-credentials') {
imageWithReleaseTag.push();
}
}
}
}
} finally {
stage("Cleanup") {
deleteDir();
}
post {
always {
deleteDir()
}
}
}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.0.0_39</version>
<version>4.2.0_168</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand Down Expand Up @@ -97,7 +97,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/botdarr/clients/ChatClientType.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public void init() throws Exception {
ChatClientResponseBuilder<DiscordResponse> responseChatClientResponseBuilder = new DiscordResponseBuilder();
ApisAndCommandConfig config = buildConfig(responseChatClientResponseBuilder);

JDA jda = new JDABuilder(Config.getProperty(Config.Constants.DISCORD_TOKEN)).addEventListeners(new ListenerAdapter() {

JDA jda = JDABuilder.createDefault((Config.getProperty(Config.Constants.DISCORD_TOKEN))).addEventListeners(new ListenerAdapter() {
@Override
public void onGenericEvent(@Nonnull GenericEvent event) {
super.onGenericEvent(event);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.5
1 change: 0 additions & 1 deletion version.txt

This file was deleted.

0 comments on commit f541d5f

Please sign in to comment.