Skip to content

Commit

Permalink
Add native package
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-vrijswijk committed Apr 15, 2024
1 parent 8254eb7 commit ad4185b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 13 deletions.
35 changes: 28 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,38 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.OS }}
strategy:
matrix:
OS: [ubuntu-latest, macos-latest]
include:
- os: macos-latest
path: tgtg-x86_64-apple-darwin
- os: ubuntu-latest
path: tgtg-x86_64-pc-linux
steps:
- uses: actions/checkout@v4
- name: Install libidn2-dev libcurl3-dev
if: matrix.OS == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install libidn2-dev libcurl3-dev
- uses: coursier/cache-action@v6
- uses: VirtusLab/scala-cli-setup@v1
with:
power: true
jvm: "temurin:21"
- name: Check formatting
run: scala-cli fmt --check
- name: Compile JVM
run: scala-cli compile . --platform jvm
- name: Compile JS
run: scala-cli compile . --platform js
# - name: Check formatting
# run: scala-cli fmt --check
# - name: Compile JVM
# run: scala-cli compile . --platform jvm
# - name: Compile JVM
# run: scala-cli compile . --platform js
- name: package native
run: scala-cli package . --native -o artifacts/${{ matrix.path }}
- uses: actions/upload-artifact@v3
with:
name: "tgtg"
path: "artifacts/${{ matrix.path }}"
if-no-files-found: error
retention-days: 2
7 changes: 1 addition & 6 deletions Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ import tgtg.notification.{Message, Title}

import scala.concurrent.duration.*

val version = new String(
classOf[Main]
.getClassLoader()
.getResourceAsStream("version.txt")
.readAllBytes()
).trim()
val version = "dev"

object Main extends CommandIOApp("tgtg", "TooGoodToGo notifier for your favourite stores", version = version):

Expand Down
19 changes: 19 additions & 0 deletions http/CatsCurlBackend.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//> using target.platform native
package sttp.client4.curl.cats

import cats.effect.kernel.Async
import sttp.client4.Backend
import sttp.client4.curl.AbstractCurlBackend
import sttp.client4.impl.cats.CatsMonadAsyncError
import sttp.client4.wrappers.FollowRedirectsBackend
import sttp.client4.curl.internal.*
import sttp.client4.curl.*
import sttp.client4.curl.internal.CurlApi.*

class CatsCurlBackend[F[_]: Async](verbose: Boolean)
extends AbstractCurlBackend(new CatsMonadAsyncError[F], verbose)
with Backend[F]:
override def performCurl(c: CurlHandle): F[CurlCode.CurlCode] = monad.blocking(c.perform)

object CatsCurlBackend:
def apply[F[_]: Async](verbose: Boolean = false): Backend[F] = FollowRedirectsBackend(new CatsCurlBackend[F](verbose))
8 changes: 8 additions & 0 deletions http/HttpNative.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//> using target.platform native
package tgtg.http

import cats.effect.{IO, Resource}
import sttp.client4.curl.cats.CatsCurlBackend
import sttp.client4.Backend

def httpBackend: Resource[IO, Backend[IO]] = Resource.pure(CatsCurlBackend())

0 comments on commit ad4185b

Please sign in to comment.