From 455139c2ce49e98939c6976f021ba7f581180ba1 Mon Sep 17 00:00:00 2001 From: Pat Garrity Date: Sun, 14 Apr 2024 21:01:41 -0500 Subject: [PATCH] (norelease) Documentation, license, builds, etc. --- .forgejo/workflows/pull_request.yaml | 66 ++++++++++++++++++++++ .forgejo/workflows/release.yaml | 83 ++++++++++++++++++++++++++++ README.md | 14 ++++- build.sbt | 2 +- project/plugins.sbt | 4 +- src/main/scala/gs/blob/v0/Blob.scala | 32 +++++++++++ 6 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 .forgejo/workflows/pull_request.yaml create mode 100644 .forgejo/workflows/release.yaml create mode 100644 src/main/scala/gs/blob/v0/Blob.scala diff --git a/.forgejo/workflows/pull_request.yaml b/.forgejo/workflows/pull_request.yaml new file mode 100644 index 0000000..bba274a --- /dev/null +++ b/.forgejo/workflows/pull_request.yaml @@ -0,0 +1,66 @@ +on: + pull_request: + types: [opened, synchronize, reopened] + +defaults: + run: + shell: bash + +jobs: + library_snapshot: + runs-on: docker + container: + image: registry.garrity.co:8443/gs/ci-scala:latest + name: 'Build and Test Library Snapshot' + env: + GS_MAVEN_USER: ${{ vars.GS_MAVEN_USER }} + GS_MAVEN_TOKEN: ${{ secrets.GS_MAVEN_TOKEN }} + steps: + - uses: actions/checkout@v4 + name: 'Checkout Repository' + with: + fetch-depth: 0 + - name: 'Pre-Commit' + run: | + pre-commit install + pre-commit run --all-files + - name: 'Prepare Versioned Build' + run: | + latest_git_tag="$(git describe --tags --abbrev=0 || echo 'No Tags')" + latest_commit_message="$(git show -s --format=%s HEAD)" + if [[ "$latest_commit_message" == *"(major)"* ]]; then + export GS_RELEASE_TYPE="major" + elif [[ "$latest_commit_message" == *"(minor)"* ]]; then + export GS_RELEASE_TYPE="minor" + elif [[ "$latest_commit_message" == *"(patch)"* ]]; then + export GS_RELEASE_TYPE="patch" + elif [[ "$latest_commit_message" == *"(docs)"* ]]; then + export GS_RELEASE_TYPE="norelease" + elif [[ "$latest_commit_message" == *"(norelease)"* ]]; then + export GS_RELEASE_TYPE="norelease" + else + export GS_RELEASE_TYPE="norelease" + fi + echo "GS_RELEASE_TYPE=$GS_RELEASE_TYPE" >> $GITHUB_ENV + echo "Previous Git Tag: $latest_git_tag" + echo "Latest Commit: $latest_commit_message ($GS_RELEASE_TYPE) (SNAPSHOT)" + if [ "$GS_RELEASE_TYPE" = "norelease" ]; then + sbtn -Dsnapshot=true -Drelease="patch" semVerInfo + else + sbtn -Dsnapshot=true -Drelease="$GS_RELEASE_TYPE" semVerInfo + fi + - name: 'Unit Tests and Code Coverage' + run: | + sbtn clean + sbtn coverage + sbtn test + sbtn coverageReport + - name: 'Publish Snapshot' + run: | + echo "Testing env var propagation = ${{ env.GS_RELEASE_TYPE }}" + if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then + echo "Skipping publish due to GS_RELEASE_TYPE=norelease" + else + sbtn clean + sbtn publish + fi diff --git a/.forgejo/workflows/release.yaml b/.forgejo/workflows/release.yaml new file mode 100644 index 0000000..8351605 --- /dev/null +++ b/.forgejo/workflows/release.yaml @@ -0,0 +1,83 @@ +on: + push: + branches: + - main + +defaults: + run: + shell: bash + +jobs: + library_release: + runs-on: docker + container: + image: registry.garrity.co:8443/gs/ci-scala:latest + name: 'Build and Release Library' + env: + GS_MAVEN_USER: ${{ vars.GS_MAVEN_USER }} + GS_MAVEN_TOKEN: ${{ secrets.GS_MAVEN_TOKEN }} + steps: + - uses: actions/checkout@v4 + name: 'Checkout Repository' + with: + fetch-depth: 0 + - name: 'Pre-Commit' + run: | + pre-commit install + pre-commit run --all-files + - name: 'Prepare Versioned Build' + run: | + latest_git_tag="$(git describe --tags --abbrev=0 || echo 'No Tags')" + latest_commit_message="$(git show -s --format=%s HEAD)" + if [[ "$latest_commit_message" == *"(major)"* ]]; then + export GS_RELEASE_TYPE="major" + elif [[ "$latest_commit_message" == *"(minor)"* ]]; then + export GS_RELEASE_TYPE="minor" + elif [[ "$latest_commit_message" == *"(patch)"* ]]; then + export GS_RELEASE_TYPE="patch" + elif [[ "$latest_commit_message" == *"(docs)"* ]]; then + export GS_RELEASE_TYPE="norelease" + elif [[ "$latest_commit_message" == *"(norelease)"* ]]; then + export GS_RELEASE_TYPE="norelease" + else + export GS_RELEASE_TYPE="norelease" + fi + + echo "GS_RELEASE_TYPE=$GS_RELEASE_TYPE" >> $GITHUB_ENV + echo "Previous Git Tag: $latest_git_tag" + echo "Latest Commit: $latest_commit_message" + echo "Selected Release Type: '$GS_RELEASE_TYPE'" + + if [ "$GS_RELEASE_TYPE" = "norelease" ]; then + echo "Skipping all versioning for 'norelease' commit." + else + sbtn -Drelease="$GS_RELEASE_TYPE" semVerInfo + fi + - name: 'Unit Tests and Code Coverage' + run: | + if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then + echo "Skipping build/test for 'norelease' commit." + else + sbtn clean + sbtn coverage + sbtn test + sbtn coverageReport + fi + - name: 'Publish Release' + run: | + if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then + echo "Skipping publish for 'norelease' commit." + else + sbtn clean + sbtn semVerWriteVersionToFile + sbtn publish + fi + - name: 'Create Git Tag' + run: | + if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then + echo "Skipping Git tag for 'norelease' commit." + else + selected_version="$(cat .version)" + git tag "$selected_version" + git push origin "$selected_version" + fi diff --git a/README.md b/README.md index 7ae938a..dfb93f9 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ # gs-blob -[License (Apache 2.0)](./LICENSE) +[GS Open Source](https://garrity.co/oss.html) | +[License (MIT)](./LICENSE) Blob data type for Scala 3. - [Usage](#usage) + - [Dependency](#dependency) +- [Donate](#donate) ## Usage +### Dependency + This artifact is available in the Garrity Software Maven repository. ```scala @@ -15,5 +20,10 @@ externalResolvers += "Garrity Software Releases" at "https://maven.garrity.co/releases" val GsBlob: ModuleID = - "gs" %% "gs-blob-v0" % "0.1.0" + "gs" %% "gs-blob-v0" % "$VERSION" ``` + +## Donate + +Enjoy this project or want to help me achieve my [goals](https://garrity.co)? +Consider [Donating to Pat on Ko-fi](https://ko-fi.com/gspfm). diff --git a/build.sbt b/build.sbt index 9b7f872..6d6715a 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,4 @@ -val scala3: String = "3.4.0" +val scala3: String = "3.4.1" ThisBuild / scalaVersion := scala3 ThisBuild / versionScheme := Some("semver-spec") diff --git a/project/plugins.sbt b/project/plugins.sbt index 78b59cb..e897854 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -29,5 +29,5 @@ externalResolvers := Seq( ) addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11") -addSbtPlugin("gs" % "sbt-garrity-software" % "0.2.0") -addSbtPlugin("gs" % "sbt-gs-semver" % "0.2.2") +addSbtPlugin("gs" % "sbt-garrity-software" % "0.3.0") +addSbtPlugin("gs" % "sbt-gs-semver" % "0.3.0") diff --git a/src/main/scala/gs/blob/v0/Blob.scala b/src/main/scala/gs/blob/v0/Blob.scala new file mode 100644 index 0000000..889ed20 --- /dev/null +++ b/src/main/scala/gs/blob/v0/Blob.scala @@ -0,0 +1,32 @@ +package gs.blob.v0 + +import java.util.Base64 + +opaque type Blob = Array[Byte] + +object Blob: + + private val Hex: String = "0123456789abcdef"; + + def apply(data: Array[Byte]): Blob = data + + given CanEqual[Blob, Blob] = CanEqual.derived + + extension (blob: Blob) + def toByteArray(): Array[Byte] = blob + + def toBase64(): String = Base64.getEncoder().encodeToString(blob) + + // TODO: Hex library + def toHex(): String = + var index = 0 + val ch: Array[Char] = new Array(blob.length * 2) + blob.foreach { byte => + ch(index) = Hex.charAt((byte & 0xf0) >> 4) + ch(index + 1) = Hex.charAt(byte & 0x0f) + index = index + 2 + } + + new String(ch) + +end Blob