diff --git a/.github/workflows/package.yml b/.github/workflows/release.yml similarity index 76% rename from .github/workflows/package.yml rename to .github/workflows/release.yml index d8802b0..63a5d25 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/Main.scala b/Main.scala index 236ef93..abdf52d 100644 --- a/Main.scala +++ b/Main.scala @@ -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): diff --git a/notification/NotifyService.scala b/notification/NotifyService.scala index 9716815..635e52b 100644 --- a/notification/NotifyService.scala +++ b/notification/NotifyService.scala @@ -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] @@ -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) diff --git a/project.scala b/project.scala index 6b8a174..7229d04 100644 --- a/project.scala +++ b/project.scala @@ -19,3 +19,5 @@ //> using option -Wunused:all //> using option -Wvalue-discard //> using option -deprecation + +//> using resourceDir ./resources diff --git a/resources/version.txt b/resources/version.txt new file mode 100644 index 0000000..22c08f7 --- /dev/null +++ b/resources/version.txt @@ -0,0 +1 @@ +v0.2.1