Skip to content

Commit

Permalink
feat: setup release-please (#19)
Browse files Browse the repository at this point in the history
BEGIN_COMMIT_OVERRIDE
feat: setup release-please

feat(notifications): add Pushbullet support
feat(notifications): add Pushover support
fix: move some logging to debug
chore: introduce NewType for extra type-safety
END_COMMIT_OVERRIDE
  • Loading branch information
hugo-vrijswijk authored Jul 27, 2023
1 parent 0a0d1ac commit 15b5826
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 40 deletions.
56 changes: 34 additions & 22 deletions .github/workflows/package.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
name: Package
name: release

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
release:
types: [published]
branches:
- main

permissions:
contents: write
pull-requests: write
packages: write


jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: simple
package-name: tgtg
version-file: resources/version.txt
package:
permissions:
contents: write
packages: write
needs: [release-please]
if: ${{ needs.release-please.outputs.release_created }}
runs-on: ${{ matrix.OS }}
env:
REGISTRY: ghcr.io
Expand All @@ -21,7 +34,6 @@ jobs:
matrix:
OS: ["ubuntu-latest", "windows-latest", "macos-latest"]
include:
# Replace "example" with the name your binary
- os: macOS-latest
uploaded_filename: tgtg-x86_64-apple-darwin
local_path: artifacts/tgtg-x86_64-apple-darwin
Expand Down Expand Up @@ -54,24 +66,13 @@ jobs:
power: true
jvm: "temurin:17"
- name: Package app
run: scala-cli package . -o "${{ matrix.local_path }}" --native-image ${{ matrix.OS != 'macos-latest' && '--graalvm-args --static' || '' }}
run: scala-cli package . -o "${{ matrix.local_path }}" --native-image -- -H:IncludeResources=version.txt ${{ matrix.OS != 'macos-latest' && '--static' || '' }}
- name: Compress artifact
if: ${{ matrix.OS == 'ubuntu-latest' }}
uses: crazy-max/ghaction-upx@v2
with:
args: --best
files: ${{ matrix.local_path }}
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.uploaded_filename }}
path: ${{ matrix.local_path }}
if-no-files-found: error
retention-days: 2
- name: Upload release
if: github.event_name == 'release'
uses: softprops/action-gh-release@v1
with:
files: ${{ matrix.local_path }}
- name: Build and push Docker image
if: matrix.OS == 'ubuntu-latest'
uses: docker/build-push-action@v4
Expand All @@ -81,3 +82,14 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.uploaded_filename }}
path: ${{ matrix.local_path }}
if-no-files-found: error
retention-days: 2
- name: Upload release artifacts
uses: softprops/action-gh-release@v1
with:
files: ${{ matrix.local_path }}
fail_on_unmatched_files: true
11 changes: 6 additions & 5 deletions Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import tgtg.notification.{Message, Title}

import scala.concurrent.duration.*

val version = sys.env
.get("GITHUB_REF")
.collect:
case s"refs/tags/$tag" => tag
.getOrElse("dev")
val version = new String(
getClass()
.getClassLoader()
.getResourceAsStream("version.txt")
.readAllBytes()
).trim()

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

Expand Down
23 changes: 10 additions & 13 deletions notification/NotifyService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ object NotifyService:
/** Create a simple [[NotifyService]] that sends a HTTP request with a JSON body
*/
def simple[T: Encoder](name: String, uri: Uri, http: Backend[IO], headers: Header*)(
messageFn: Notification => T
)(using Logger[IO]) =
new NotifyService:
def sendNotification(title: Title, message: Message): IO[Unit] = basicRequest
.post(uri)
.headers(headers*)
.responseGetRight
.body(messageFn((title, message)))
.send(http)
.logTimed(s"$name notification")
.void
messageFn: (Title, Message) => T
)(using Logger[IO]): NotifyService = (title: Title, message: Message) =>
basicRequest
.post(uri)
.headers(headers*)
.responseGetRight
.body(messageFn(title, message))
.send(http)
.logTimed(s"$name notification")
.void
end NotifyService

object Title extends NewType[String]
Expand All @@ -35,8 +34,6 @@ type Title = Title.Type
object Message extends NewType[String]
type Message = Message.Type

type Notification = (Title, Message)

enum NotifyConfig:
case Gotify(token: ApiToken, url: Uri)
case Pushbullet(token: ApiToken)
Expand Down
2 changes: 2 additions & 0 deletions project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
//> using option -Wunused:all
//> using option -Wvalue-discard
//> using option -deprecation

//> using resourceDir ./resources
1 change: 1 addition & 0 deletions resources/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.2.1

0 comments on commit 15b5826

Please sign in to comment.