Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/gradle/jvm-2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
urielsalis authored Sep 28, 2024
2 parents 0b77514 + 0570e1c commit 2d90f49
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 83 deletions.
117 changes: 38 additions & 79 deletions .github/workflows/push-build-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Build and deploy

permissions:
id-token: write # Require write permission to Fetch an OIDC token.

on:
push:
branches: [ master ]
Expand All @@ -8,87 +11,43 @@ on:

jobs:
build:

name: Build and deploy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Build with Gradle
run: ./gradlew clean installDist
- name: Upload new libraries
uses: urielsalis/rsync-deploy@master
env:
DEPLOY_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_PORT: 50022
FOLDER: "build/install/arisa-kt/lib"
ARGS: "-avhW --delete"
SERVER_IP: localhost
USERNAME: arisakt
SERVER_DESTINATION: /home/arisakt/arisa-kt
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
- name: Upload new binaries
uses: urielsalis/rsync-deploy@master
env:
DEPLOY_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_PORT: 50022
FOLDER: "build/install/arisa-kt/bin"
ARGS: "-avhW --delete"
SERVER_IP: localhost
USERNAME: arisakt
SERVER_DESTINATION: /home/arisakt/arisa-kt
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
- name: Upload new configuration
uses: urielsalis/rsync-deploy@master
env:
DEPLOY_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SERVER_PORT: 50022
FOLDER: "config"
ARGS: "-avhW --delete --exclude='local.yml'"
SERVER_IP: localhost
USERNAME: arisakt
SERVER_DESTINATION: /home/arisakt/arisa-kt
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
- name: Run internal deploy script
uses: urielsalis/azure-bastion-ssh-action@master
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
RESOURCE_ID: ${{ secrets.RESOURCE_ID }}
RESOURCE_GROUP: ${{ secrets.RESOURCE_GROUP }}
TENANT_ID: ${{ secrets.TENANT_ID }}
BASTION_NAME: ${{ secrets.BASTION_NAME }}
with:
host: localhost
port: 50022
user: arisakt
key: ${{ secrets.SSH_PRIVATE_KEY }}
command: |
/usr/bin/screen -ls | /bin/egrep 'Detached|Attached' | /usr/bin/cut -d. -f1 | /usr/bin/awk '{print $1}' | /usr/bin/xargs /bin/kill
sleep 1
cd arisa-kt
/usr/bin/screen -d -m bash -c '/home/arisakt/arisa-kt/bin/arisa-kt; exec sh'
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

args: "-tt"
- name: Build with Gradle
run: ./gradlew clean installDist

- name: Deploy
uses: mojira/deploy@main
with:
azure_client_id: ${{ secrets.AZURE_CLIENT_ID }}
azure_tenant_id: ${{ secrets.AZURE_TENANT_ID }}
azure_subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
bastion_name: ${{ secrets.BASTION_NAME }}
resource_group: ${{ secrets.RESOURCE_GROUP }}
resource_id: ${{ secrets.RESOURCE_ID }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
username: arisakt
artifact_paths: |
build/install/arisa-kt/lib
build/install/arisa-kt/bin
config/config.yml
artifact_destination: /home/arisakt/arisa-kt
script: |
/usr/bin/screen -ls | /bin/egrep 'Detached|Attached' | /usr/bin/cut -d. -f1 | /usr/bin/awk '{print $1}' | /usr/bin/xargs /bin/kill
sleep 1
cd arisa-kt
/usr/bin/screen -d -m bash -c '/home/arisakt/arisa-kt/bin/arisa-kt; exec sh'
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ListUserActivityCommand(
is Either.Left ->
throw CommandExceptions.CANNOT_QUERY_USER_ACTIVITY
.create(sanitizedUserName, jql)
.initCause(either.a)
.apply { addSuppressed(either.a) }

is Either.Right -> either.b
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class RemoveContentCommand(
is Either.Left ->
throw CommandExceptions.CANNOT_QUERY_USER_ACTIVITY
.create(sanitizedUserName, jql)
.initCause(either.a)
.apply { addSuppressed(either.a) }

is Either.Right -> either.b
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package io.github.mojira.arisa.modules.commands

import arrow.core.Either
import arrow.core.extensions.fx
import arrow.core.left
import com.mojang.brigadier.exceptions.CommandSyntaxException
import io.github.mojira.arisa.utils.mockIssue
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
Expand Down Expand Up @@ -72,7 +76,23 @@ class ListUserActivityCommandTest : StringSpec({
comment.shouldNotBeNull()
commentRestriction shouldBe "staff"

// Should contain sanitized user name
comment shouldStartWith "No unrestricted comments from user \"user?Name\" were found."
val expectedSanitizedUser = "user?Name"
comment shouldStartWith "No unrestricted comments from user \"$expectedSanitizedUser\" were found."
}

"should throw with suppressed exception when querying activity fails" {
val searchException = Exception("test exception")
val command = ListUserActivityCommand { _, _ ->
searchException.left()
}

val issue = mockIssue()
val user = "user\nName"
val exception = shouldThrow<CommandSyntaxException> {
command(issue, user)
}
val expectedSanitizedUser = "user?Name"
exception.message shouldStartWith "Could not query activity of user \"$expectedSanitizedUser\". Query string: "
exception.suppressed.shouldContainExactly(searchException)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package io.github.mojira.arisa.modules.commands

import arrow.core.left
import arrow.core.right
import com.mojang.brigadier.exceptions.CommandSyntaxException
import io.github.mojira.arisa.utils.mockIssue
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.booleans.shouldBeTrue
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldStartWith
import io.mockk.mockk
import net.rcarz.jiraclient.Issue

Expand Down Expand Up @@ -178,4 +182,22 @@ class RemoveContentCommandTest : StringSpec({
// Should contain sanitized user name
comment shouldContain "evil?User"
}

"should throw with suppressed exception when querying activity fails" {
val searchException = Exception("test exception")
val command = RemoveContentCommand(
searchIssues = { _, _ -> searchException.left() },
getIssue = { throw AssertionError("not needed for test") },
execute = { throw AssertionError("not needed for test") }
)

val issue = mockIssue()
val user = "user\nName"
val exception = shouldThrow<CommandSyntaxException> {
command(issue, user)
}
val expectedSanitizedUser = "user?Name"
exception.message shouldStartWith "Could not query activity of user \"$expectedSanitizedUser\". Query string: "
exception.suppressed.shouldContainExactly(searchException)
}
})

0 comments on commit 2d90f49

Please sign in to comment.