mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-05 22:55:58 +00:00
parent
647e892cfa
commit
193b81bf7d
@ -247,7 +247,13 @@ object JoexAppImpl {
|
|||||||
.withTask(
|
.withTask(
|
||||||
JobTask.json(
|
JobTask.json(
|
||||||
UpdateCheckTask.taskName,
|
UpdateCheckTask.taskName,
|
||||||
UpdateCheckTask[F](cfg.updateCheck, cfg.sendMail, javaEmil, updateCheck),
|
UpdateCheckTask[F](
|
||||||
|
cfg.updateCheck,
|
||||||
|
cfg.sendMail,
|
||||||
|
javaEmil,
|
||||||
|
updateCheck,
|
||||||
|
ThisVersion.default
|
||||||
|
),
|
||||||
UpdateCheckTask.onCancel[F]
|
UpdateCheckTask.onCancel[F]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -24,10 +24,11 @@ object MakeMail {
|
|||||||
sendCfg: MailSendConfig,
|
sendCfg: MailSendConfig,
|
||||||
cfg: UpdateCheckConfig,
|
cfg: UpdateCheckConfig,
|
||||||
smtpCfg: RUserEmail,
|
smtpCfg: RUserEmail,
|
||||||
latestRelease: UpdateCheck.Release
|
latestRelease: UpdateCheck.Release,
|
||||||
|
thisVersion: ThisVersion
|
||||||
): Mail[F] = {
|
): Mail[F] = {
|
||||||
|
|
||||||
val templateCtx = TemplateCtx(latestRelease)
|
val templateCtx = TemplateCtx(latestRelease, thisVersion)
|
||||||
val md = templateCtx.render(cfg.body)
|
val md = templateCtx.render(cfg.body)
|
||||||
val subj = templateCtx.render(cfg.subject)
|
val subj = templateCtx.render(cfg.subject)
|
||||||
|
|
||||||
@ -49,8 +50,8 @@ object MakeMail {
|
|||||||
releasedAt: String
|
releasedAt: String
|
||||||
)
|
)
|
||||||
object TemplateCtx {
|
object TemplateCtx {
|
||||||
def apply(release: UpdateCheck.Release): TemplateCtx =
|
def apply(release: UpdateCheck.Release, thisVersion: ThisVersion): TemplateCtx =
|
||||||
TemplateCtx(UpdateCheck.currentVersion, release.version, release.published_at)
|
TemplateCtx(thisVersion.get, release.version, release.published_at)
|
||||||
|
|
||||||
implicit val yamuscaConverter: ValueConverter[TemplateCtx] =
|
implicit val yamuscaConverter: ValueConverter[TemplateCtx] =
|
||||||
ValueConverter.deriveConverter[TemplateCtx]
|
ValueConverter.deriveConverter[TemplateCtx]
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Docspell Contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package docspell.joex.updatecheck
|
||||||
|
|
||||||
|
import docspell.joex.BuildInfo
|
||||||
|
|
||||||
|
trait ThisVersion {
|
||||||
|
def get: String
|
||||||
|
}
|
||||||
|
|
||||||
|
object ThisVersion {
|
||||||
|
def default: ThisVersion =
|
||||||
|
constant(BuildInfo.version)
|
||||||
|
|
||||||
|
def constant(value: String): ThisVersion = new ThisVersion {
|
||||||
|
override def get: String = value
|
||||||
|
}
|
||||||
|
}
|
@ -8,8 +8,6 @@ package docspell.joex.updatecheck
|
|||||||
|
|
||||||
import cats.effect._
|
import cats.effect._
|
||||||
|
|
||||||
import docspell.joex.BuildInfo
|
|
||||||
|
|
||||||
import io.circe.Decoder
|
import io.circe.Decoder
|
||||||
import io.circe.generic.semiauto._
|
import io.circe.generic.semiauto._
|
||||||
import org.http4s.circe.CirceEntityDecoder._
|
import org.http4s.circe.CirceEntityDecoder._
|
||||||
@ -24,9 +22,6 @@ trait UpdateCheck[F[_]] {
|
|||||||
|
|
||||||
object UpdateCheck {
|
object UpdateCheck {
|
||||||
|
|
||||||
val currentVersion: String =
|
|
||||||
BuildInfo.version
|
|
||||||
|
|
||||||
final case class Release(
|
final case class Release(
|
||||||
html_url: String,
|
html_url: String,
|
||||||
id: Int,
|
id: Int,
|
||||||
@ -36,13 +31,14 @@ object UpdateCheck {
|
|||||||
published_at: String
|
published_at: String
|
||||||
) {
|
) {
|
||||||
|
|
||||||
def version: String = tag_name
|
def version: String = tag_name.replaceFirst("v", "")
|
||||||
|
|
||||||
def isCurrent: Boolean = {
|
/** Checks if `thisVersion` is either a SNAPSHOT version or the same as this release.
|
||||||
val version = BuildInfo.version
|
*/
|
||||||
version.endsWith("SNAPSHOT") || version == tag_name
|
def matchesVersion(tv: ThisVersion): Boolean = {
|
||||||
|
val myVersion = tv.get
|
||||||
|
myVersion.endsWith("SNAPSHOT") || myVersion == version
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object Release {
|
object Release {
|
||||||
|
@ -45,13 +45,14 @@ object UpdateCheckTask {
|
|||||||
cfg: UpdateCheckConfig,
|
cfg: UpdateCheckConfig,
|
||||||
sendCfg: MailSendConfig,
|
sendCfg: MailSendConfig,
|
||||||
emil: Emil[F],
|
emil: Emil[F],
|
||||||
updateCheck: UpdateCheck[F]
|
updateCheck: UpdateCheck[F],
|
||||||
|
thisVersion: ThisVersion
|
||||||
): Task[F, Args, Unit] =
|
): Task[F, Args, Unit] =
|
||||||
if (cfg.enabled)
|
if (cfg.enabled)
|
||||||
Task { ctx =>
|
Task { ctx =>
|
||||||
for {
|
for {
|
||||||
_ <- ctx.logger.info(
|
_ <- ctx.logger.info(
|
||||||
s"Check for updates. Current version is: ${UpdateCheck.currentVersion}"
|
s"Check for updates. Current version is: ${thisVersion.get}"
|
||||||
)
|
)
|
||||||
_ <- ctx.logger.debug(
|
_ <- ctx.logger.debug(
|
||||||
s"Get SMTP connection for ${cfg.senderAccount.asString} and ${cfg.smtpId}"
|
s"Get SMTP connection for ${cfg.senderAccount.asString} and ${cfg.smtpId}"
|
||||||
@ -67,7 +68,7 @@ object UpdateCheckTask {
|
|||||||
)
|
)
|
||||||
else ().pure[F]
|
else ().pure[F]
|
||||||
_ <-
|
_ <-
|
||||||
if (latest.isCurrent && !cfg.testRun)
|
if (latest.matchesVersion(thisVersion) && !cfg.testRun)
|
||||||
ctx.logger.info(
|
ctx.logger.info(
|
||||||
s"Latest release is ${latest.version}, which is the current one. Everything uptodate."
|
s"Latest release is ${latest.version}, which is the current one. Everything uptodate."
|
||||||
)
|
)
|
||||||
@ -75,7 +76,7 @@ object UpdateCheckTask {
|
|||||||
ctx.logger.info(
|
ctx.logger.info(
|
||||||
s"Sending mail about new release: ${latest.tag_name}"
|
s"Sending mail about new release: ${latest.tag_name}"
|
||||||
) *> emil(smtpCfg.toMailConfig).send(
|
) *> emil(smtpCfg.toMailConfig).send(
|
||||||
MakeMail(sendCfg, cfg, smtpCfg, latest)
|
MakeMail(sendCfg, cfg, smtpCfg, latest, thisVersion)
|
||||||
)
|
)
|
||||||
} yield ()
|
} yield ()
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2020 Docspell Contributors
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package docspell.joex.updatecheck
|
||||||
|
|
||||||
|
import io.circe.{parser => jsonParser}
|
||||||
|
import munit._
|
||||||
|
|
||||||
|
class UpdateCheckTest extends FunSuite {
|
||||||
|
|
||||||
|
val testRelease =
|
||||||
|
UpdateCheck.Release(
|
||||||
|
"https://github.com/eikek/docspell/releases/tag/v0.26.0",
|
||||||
|
99899888,
|
||||||
|
"v0.26.0",
|
||||||
|
"Docspell 0.26.0",
|
||||||
|
"2021-08-28T10:02:01Z",
|
||||||
|
"2021-08-28T10:30:38Z"
|
||||||
|
)
|
||||||
|
|
||||||
|
test("parse example response") {
|
||||||
|
val release =
|
||||||
|
jsonParser
|
||||||
|
.parse(UpdateCheckTest.exampleResponsePartial)
|
||||||
|
.flatMap(_.as[UpdateCheck.Release])
|
||||||
|
.getOrElse(sys.error("Could not parse test response"))
|
||||||
|
|
||||||
|
assertEquals(release.version, "0.26.0")
|
||||||
|
assertEquals(release, testRelease)
|
||||||
|
}
|
||||||
|
|
||||||
|
test("snapshot is matches") {
|
||||||
|
val thisVersion = ThisVersion.constant("0.24.0-SNAPSHOT")
|
||||||
|
assert(testRelease.matchesVersion(thisVersion))
|
||||||
|
}
|
||||||
|
|
||||||
|
test("newer version does not match ") {
|
||||||
|
val thisVersion = ThisVersion.constant("0.25.0")
|
||||||
|
assert(!testRelease.matchesVersion(thisVersion))
|
||||||
|
}
|
||||||
|
|
||||||
|
test("same version matches") {
|
||||||
|
val thisVersion = ThisVersion.constant("0.26.0")
|
||||||
|
assert(testRelease.matchesVersion(thisVersion))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
object UpdateCheckTest {
|
||||||
|
|
||||||
|
val exampleResponsePartial = """
|
||||||
|
|{
|
||||||
|
| "url": "https://api.github.com/repos/eikek/docspell/releases/99899888",
|
||||||
|
| "assets_url": "https://api.github.com/repos/eikek/docspell/releases/99899888/assets",
|
||||||
|
| "upload_url": "https://uploads.github.com/repos/eikek/docspell/releases/99899888/assets{?name,label}",
|
||||||
|
| "html_url": "https://github.com/eikek/docspell/releases/tag/v0.26.0",
|
||||||
|
| "id": 99899888,
|
||||||
|
| "node_id": "MDc6UmVsZWFzZTQ4NjEwNTY2",
|
||||||
|
| "tag_name": "v0.26.0",
|
||||||
|
| "target_commitish": "master",
|
||||||
|
| "name": "Docspell 0.26.0",
|
||||||
|
| "draft": false,
|
||||||
|
| "prerelease": false,
|
||||||
|
| "created_at": "2021-08-28T10:02:01Z",
|
||||||
|
| "published_at": "2021-08-28T10:30:38Z",
|
||||||
|
| "assets": [
|
||||||
|
| {
|
||||||
|
| "url": "https://api.github.com/repos/eikek/docspell/releases/assets/43494218",
|
||||||
|
| "id": 43494218,
|
||||||
|
| "node_id": "MDEyOlJlbGVhc2VBc3NldDQzNDk0MjE4",
|
||||||
|
| "name": "docspell-joex-0.26.0.zip",
|
||||||
|
| "label": "",
|
||||||
|
| "content_type": "application/zip",
|
||||||
|
| "state": "uploaded",
|
||||||
|
| "size": 328163415,
|
||||||
|
| "download_count": 24,
|
||||||
|
| "created_at": "2021-08-28T10:16:24Z",
|
||||||
|
| "updated_at": "2021-08-28T10:16:36Z",
|
||||||
|
| "browser_download_url": "https://github.com/eikek/docspell/releases/download/v0.26.0/docspell-joex-0.26.0.zip"
|
||||||
|
| },
|
||||||
|
| {
|
||||||
|
| "url": "https://api.github.com/repos/eikek/docspell/releases/assets/43494232",
|
||||||
|
| "id": 43494232,
|
||||||
|
| "node_id": "MDEyOlJlbGVhc2VBc3NldDQzNDk0MjMy",
|
||||||
|
| "name": "docspell-joex_0.26.0_all.deb",
|
||||||
|
| "label": "",
|
||||||
|
| "content_type": "application/vnd.debian.binary-package",
|
||||||
|
| "state": "uploaded",
|
||||||
|
| "size": 337991872,
|
||||||
|
| "download_count": 8,
|
||||||
|
| "created_at": "2021-08-28T10:16:37Z",
|
||||||
|
| "updated_at": "2021-08-28T10:16:53Z",
|
||||||
|
| "browser_download_url": "https://github.com/eikek/docspell/releases/download/v0.26.0/docspell-joex_0.26.0_all.deb"
|
||||||
|
| }
|
||||||
|
| ],
|
||||||
|
| "tarball_url": "https://api.github.com/repos/eikek/docspell/tarball/v0.26.0",
|
||||||
|
| "zipball_url": "https://api.github.com/repos/eikek/docspell/zipball/v0.26.0"
|
||||||
|
|}
|
||||||
|
|""".stripMargin
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user