Skip to content

Commit

Permalink
upgrade to scala3 and migrate to fs2.io for file handling
Browse files Browse the repository at this point in the history
  • Loading branch information
softinio committed Apr 27, 2024
1 parent 3c809e9 commit ecad081
Show file tree
Hide file tree
Showing 19 changed files with 226 additions and 184 deletions.
113 changes: 58 additions & 55 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,123 +15,126 @@ on:
tags: [v*]

env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_CREDENTIAL_HOST: ${{ secrets.SONATYPE_CREDENTIAL_HOST }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


concurrency:
group: ${{ github.workflow }} @ ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.12]
scala: [3]
java: [corretto@21]
project: [rootJVM]
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download Java (corretto@21)
id: download-java-corretto-21
if: matrix.java == 'corretto@21'
uses: typelevel/download-java@v1
with:
distribution: corretto
java-version: 21

- name: Setup Java (corretto@21)
id: setup-java-corretto-21
if: matrix.java == 'corretto@21'
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: jdkfile
distribution: corretto
java-version: 21
jdkFile: ${{ steps.download-java-corretto-21.outputs.jdkFile }}
cache: sbt

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
- name: sbt update
if: matrix.java == 'corretto@21' && steps.setup-java-corretto-21.outputs.cache-hit == 'false'
run: sbt +update

- name: Check that workflows are up to date
run: sbt githubWorkflowCheck

- name: Check headers and formatting
if: matrix.java == 'corretto@21'
if: matrix.java == 'corretto@21' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: Test
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'corretto@21'
if: matrix.java == 'corretto@21' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'corretto@21'
if: matrix.java == 'corretto@21' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

site:
name: Generate Site
dependency-submission:
name: Submit Dependencies
if: github.event_name != 'pull_request'
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.12]
java: [corretto@21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download Java (corretto@21)
id: download-java-corretto-21
- name: Setup Java (corretto@21)
id: setup-java-corretto-21
if: matrix.java == 'corretto@21'
uses: typelevel/download-java@v1
uses: actions/setup-java@v4
with:
distribution: corretto
java-version: 21
cache: sbt

- name: sbt update
if: matrix.java == 'corretto@21' && steps.setup-java-corretto-21.outputs.cache-hit == 'false'
run: sbt +update

- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: rootjs_3 docs_3 rootjvm_3 rootnative_3
configs-ignore: test scala-tool scala-doc-tool test-internal

site:
name: Generate Site
strategy:
matrix:
os: [ubuntu-latest]
java: [corretto@21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (corretto@21)
id: setup-java-corretto-21
if: matrix.java == 'corretto@21'
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: jdkfile
distribution: corretto
java-version: 21
jdkFile: ${{ steps.download-java-corretto-21.outputs.jdkFile }}
cache: sbt

- name: Cache sbt
uses: actions/cache@v2
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
~/AppData/Local/Coursier/Cache/v1
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
- name: sbt update
if: matrix.java == 'corretto@21' && steps.setup-java-corretto-21.outputs.cache-hit == 'false'
run: sbt +update

- name: Generate site
run: sbt '++ ${{ matrix.scala }}' docs/tlSite
run: sbt docs/tlSite

- name: Publish site
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v3.8.0
uses: peaceiris/actions-gh-pages@v3.9.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: site/target/docs/site
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 3.4.3
runner.dialect = scala213
runner.dialect = scala3
35 changes: 17 additions & 18 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ThisBuild / tlBaseVersion := "0.1" // your current series x.y

ThisBuild / organization := "com.softinio"
ThisBuild / organizationName := "Salar Rahmanian"
ThisBuild / startYear := Some(2023)
ThisBuild / startYear := Some(2024)
ThisBuild / licenses := Seq(License.Apache2)
ThisBuild / developers := List(
// your GitHub handle and name
Expand All @@ -25,11 +25,9 @@ ThisBuild / tlSitePublishBranch := Some("main")

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.corretto("21"))

val Scala213 = "2.13.12"
ThisBuild / crossScalaVersions := Seq(Scala213)
ThisBuild / scalaVersion := Scala213 // the default Scala

addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.0")
val Scala3 = "3.3.3"
ThisBuild / crossScalaVersions := Seq(Scala3)
ThisBuild / scalaVersion := Scala3 // the default Scala

lazy val root = tlCrossRootProject.aggregate(core)

Expand All @@ -40,27 +38,28 @@ lazy val core = crossProject(JVMPlatform)
name := "scalanews",
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "2.10.0",
"org.typelevel" %% "cats-effect" % "3.5.2",
"io.github.akiomik" %% "cats-nio-file" % "1.10.0",
"org.typelevel" %% "cats-effect" % "3.5.4",
"com.monovore" %% "decline-effect" % "2.4.1",
"com.github.pureconfig" %% "pureconfig" % "0.17.4",
"com.github.pureconfig" %% "pureconfig-cats-effect" % "0.17.4",
"org.http4s" %% "http4s-ember-client" % "0.23.24",
"org.http4s" %% "http4s-dsl" % "0.23.24",
"com.github.pureconfig" %% "pureconfig-core" % "0.17.6",
"com.github.pureconfig" %% "pureconfig-cats-effect" % "0.17.6",
"org.http4s" %% "http4s-ember-client" % "0.23.26",
"org.http4s" %% "http4s-dsl" % "0.23.26",
"co.fs2" %% "fs2-core" % "3.10.2",
"co.fs2" %% "fs2-io" % "3.10.2",
"com.rometools" % "rome" % "2.1.0",
"org.scalameta" %% "munit" % "0.7.29" % Test,
"org.typelevel" %% "munit-cats-effect-3" % "1.0.7" % Test
"org.scalameta" %% "munit" % "1.0.0-RC1" % Test,
"org.typelevel" %% "munit-cats-effect" % "2.0.0-M5" % Test
),
Compile / mainClass := Some("com.softinio.scalanews.Main"),
nativeImageVersion := "21.0.1",
nativeImageVersion := "21.0.2",
nativeImageJvm := "graalvm-java21",
nativeImageOptions += "--no-fallback",
nativeImageOptions += "--enable-url-protocols=http",
nativeImageOptions += "--enable-url-protocols=https",
nativeImageOutput := file(".") / "scalanews",
nativeImageReady := { () => println("SBT Finished creating image.") },
resolvers +=
"Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
nativeImageReady := { () => println("SBT Finished creating image.") }
// resolvers +=
// "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
)
.enablePlugins(NativeImagePlugin)

Expand Down
39 changes: 22 additions & 17 deletions core/src/main/scala/com/softinio/scalanews/Bloggers.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Salar Rahmanian
* Copyright 2024 Salar Rahmanian
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,11 +16,10 @@

package com.softinio.scalanews

import java.nio.file.Paths
import java.nio.file.StandardOpenOption
import java.util.Date
import cats.effect._
import cats.nio.file.Files
import fs2.io.file._
import fs2.Stream
import com.rometools.rome.feed.synd.SyndEntry

import scala.jdk.CollectionConverters._
Expand All @@ -29,17 +28,17 @@ import com.softinio.scalanews.algebra.Blog

object Bloggers {
private val nextMarkdownFilePath =
Paths.get("next/next.md")
Path("next/next.md")
private val directoryMarkdownFilePath =
Paths.get("docs/Resources/Blog_Directory.md")
Path("docs/Resources/Blog_Directory.md")
private val blogsToSkipByUrl = List(
"petr-zapletal.medium.com",
"sudarshankasar.medium.com"
)
def generateDirectory(bloggerList: List[Blog]): IO[String] = {
IO.blocking {
val header = """
|# Blog Directory
|# Blog Directory
|A Directory of bloggers producing Scala related content with links to their rss feed when available.
Expand Down Expand Up @@ -177,11 +176,14 @@ object Bloggers {
exists <- Files[IO].exists(directoryMarkdownFilePath)
_ <- if (exists) Files[IO].delete(directoryMarkdownFilePath) else IO.unit
directory <- generateDirectory(bloggerList)
_ <- Files[IO].write(
directoryMarkdownFilePath,
directory.getBytes(),
StandardOpenOption.CREATE_NEW
)
_ <- fs2.Stream
.emits(List(directory))
.through(fs2.text.utf8.encode)
.through(
Files[IO].writeAll(directoryMarkdownFilePath, Flags(Flag.CreateNew))
)
.compile
.drain
} yield ExitCode.Success
}

Expand All @@ -194,11 +196,14 @@ object Bloggers {
_ <- if (exists) Files[IO].delete(nextMarkdownFilePath) else IO.unit
articleList <- createBlogList(startDate, endDate)
news <- generateNews(articleList)
_ <- Files[IO].write(
nextMarkdownFilePath,
news.getBytes(),
StandardOpenOption.CREATE_NEW
)
_ <- fs2.Stream
.emits(List(news))
.through(fs2.text.utf8.encode)
.through(
Files[IO].writeAll(directoryMarkdownFilePath, Flags(Flag.CreateNew))
)
.compile
.drain
} yield ExitCode.Success
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Salar Rahmanian
* Copyright 2024 Salar Rahmanian
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,10 +17,8 @@
package com.softinio.scalanews

import pureconfig._
import pureconfig.generic.auto._
import pureconfig.module.catseffect.syntax._
import cats.effect.IO

import com.softinio.scalanews.algebra.Configuration

object ConfigLoader {
Expand Down
Loading

0 comments on commit ecad081

Please sign in to comment.