Compare commits
No commits in common. "main" and "0.1.1" have entirely different histories.
9 changed files with 32 additions and 126 deletions
|
@ -34,21 +34,12 @@ jobs:
|
||||||
export GS_RELEASE_TYPE="minor"
|
export GS_RELEASE_TYPE="minor"
|
||||||
elif [[ "$latest_commit_message" == *"(patch)"* ]]; then
|
elif [[ "$latest_commit_message" == *"(patch)"* ]]; then
|
||||||
export GS_RELEASE_TYPE="patch"
|
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
|
else
|
||||||
export GS_RELEASE_TYPE="norelease"
|
export GS_RELEASE_TYPE="patch"
|
||||||
fi
|
fi
|
||||||
echo "GS_RELEASE_TYPE=$GS_RELEASE_TYPE" >> $GITHUB_ENV
|
|
||||||
echo "Previous Git Tag: $latest_git_tag"
|
echo "Previous Git Tag: $latest_git_tag"
|
||||||
echo "Latest Commit: $latest_commit_message ($GS_RELEASE_TYPE) (SNAPSHOT)"
|
echo "Latest Commit: $latest_commit_message ($GS_RELEASE_TYPE) (SNAPSHOT)"
|
||||||
if [ "$GS_RELEASE_TYPE" = "norelease" ]; then
|
sbtn -Dsnapshot=true -Drelease="$GS_RELEASE_TYPE" semVerInfo
|
||||||
sbtn -Dsnapshot=true -Drelease="patch" semVerInfo
|
|
||||||
else
|
|
||||||
sbtn -Dsnapshot=true -Drelease="$GS_RELEASE_TYPE" semVerInfo
|
|
||||||
fi
|
|
||||||
- name: 'Unit Tests and Code Coverage'
|
- name: 'Unit Tests and Code Coverage'
|
||||||
run: |
|
run: |
|
||||||
sbtn clean
|
sbtn clean
|
||||||
|
@ -57,12 +48,5 @@ jobs:
|
||||||
sbtn coverageReport
|
sbtn coverageReport
|
||||||
- name: 'Publish Snapshot'
|
- name: 'Publish Snapshot'
|
||||||
run: |
|
run: |
|
||||||
echo "Testing env var propagation = ${{ env.GS_RELEASE_TYPE }}"
|
sbtn clean
|
||||||
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
sbtn publish
|
||||||
echo "Skipping publish due to GS_RELEASE_TYPE=norelease"
|
|
||||||
else
|
|
||||||
sbtn coverageOff
|
|
||||||
sbtn clean
|
|
||||||
sbtn compile
|
|
||||||
sbtn publish
|
|
||||||
fi
|
|
||||||
|
|
|
@ -35,50 +35,26 @@ jobs:
|
||||||
export GS_RELEASE_TYPE="minor"
|
export GS_RELEASE_TYPE="minor"
|
||||||
elif [[ "$latest_commit_message" == *"(patch)"* ]]; then
|
elif [[ "$latest_commit_message" == *"(patch)"* ]]; then
|
||||||
export GS_RELEASE_TYPE="patch"
|
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
|
else
|
||||||
export GS_RELEASE_TYPE="norelease"
|
export GS_RELEASE_TYPE="patch"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "GS_RELEASE_TYPE=$GS_RELEASE_TYPE" >> $GITHUB_ENV
|
|
||||||
echo "Previous Git Tag: $latest_git_tag"
|
echo "Previous Git Tag: $latest_git_tag"
|
||||||
echo "Latest Commit: $latest_commit_message"
|
echo "Latest Commit: $latest_commit_message"
|
||||||
echo "Selected Release Type: '$GS_RELEASE_TYPE'"
|
echo "Selected Release Type: '$GS_RELEASE_TYPE'"
|
||||||
|
sbtn -Drelease="$GS_RELEASE_TYPE" semVerInfo
|
||||||
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'
|
- name: 'Unit Tests and Code Coverage'
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
sbtn clean
|
||||||
echo "Skipping build/test for 'norelease' commit."
|
sbtn coverage
|
||||||
else
|
sbtn test
|
||||||
sbtn clean
|
sbtn coverageReport
|
||||||
sbtn coverage
|
|
||||||
sbtn test
|
|
||||||
sbtn coverageReport
|
|
||||||
fi
|
|
||||||
- name: 'Publish Release'
|
- name: 'Publish Release'
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
sbtn clean
|
||||||
echo "Skipping publish for 'norelease' commit."
|
sbtn semVerWriteVersionToFile
|
||||||
else
|
sbtn publish
|
||||||
sbtn coverageOff
|
|
||||||
sbtn clean
|
|
||||||
sbtn semVerWriteVersionToFile
|
|
||||||
sbtn publish
|
|
||||||
fi
|
|
||||||
- name: 'Create Git Tag'
|
- name: 'Create Git Tag'
|
||||||
run: |
|
run: |
|
||||||
if [ "${{ env.GS_RELEASE_TYPE }}" = "norelease" ]; then
|
selected_version="$(cat .version)"
|
||||||
echo "Skipping Git tag for 'norelease' commit."
|
git tag "$selected_version"
|
||||||
else
|
git push origin "$selected_version"
|
||||||
selected_version="$(cat .version)"
|
|
||||||
git tag "$selected_version"
|
|
||||||
git push origin "$selected_version"
|
|
||||||
fi
|
|
||||||
|
|
59
README.md
59
README.md
|
@ -1,72 +1,19 @@
|
||||||
# gs-hex
|
# gs-hex
|
||||||
|
|
||||||
[GS Open Source](https://garrity.co/oss.html) |
|
[License (Apache 2.0)](./LICENSE)
|
||||||
[License (MIT)](./LICENSE)
|
|
||||||
|
|
||||||
Hexadecimal conversions for Scala 3. Provides support for standard types.
|
Hexadecimal conversions for Scala 3. Provides support for standard types.
|
||||||
|
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Dependency](#dependency)
|
|
||||||
- [Byte Array Conversion](#byte-array-conversion)
|
|
||||||
- [Type Classes](#type-classes)
|
|
||||||
- [Donate](#donate)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Dependency
|
|
||||||
|
|
||||||
This artifact is available in the Garrity Software Maven repository.
|
This artifact is available in the Garrity Software Maven repository.
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
externalResolvers +=
|
externalResolvers +=
|
||||||
"Garrity Software Releases" at "https://maven.garrity.co/gs"
|
"Garrity Software Releases" at "https://maven.garrity.co/releases"
|
||||||
|
|
||||||
val GsHex: ModuleID =
|
val GsHex: ModuleID =
|
||||||
"gs" %% "gs-hex-v0" % "$VERSION"
|
"gs" %% "gs-hex-v0" % "0.1.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Byte Array Conversion
|
|
||||||
|
|
||||||
This library is based on two functions: `Hex.toHexString(Array[Byte])` and
|
|
||||||
`Hex.fromHexString(String)`.
|
|
||||||
|
|
||||||
```scala
|
|
||||||
import gs.hex.v0.Hex
|
|
||||||
|
|
||||||
val data: Array[Byte] = ???
|
|
||||||
val encoded: String = Hex.toHexString(data)
|
|
||||||
val decoded: Option[Array[Byte]] = Hex.fromHexString(encoded)
|
|
||||||
```
|
|
||||||
|
|
||||||
### Type Classes
|
|
||||||
|
|
||||||
This library provides `HexEncode[A]` and `HexDecode[A]` for encoding and
|
|
||||||
decoding arbitrary types as Hexadecimal strings. The types `Array[Byte]`,
|
|
||||||
`String`, `Boolean`, `Int` and `Long` are supported by default.
|
|
||||||
|
|
||||||
#### Example Type Class Implementations
|
|
||||||
|
|
||||||
```scala
|
|
||||||
given HexEncode[Array[Byte]] = new HexEncode[Array[Byte]] {
|
|
||||||
def toHexString(data: Array[Byte]): String = Hex.toHexString(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
given HexDecode[Array[Byte]] = new HexDecode[Array[Byte]] {
|
|
||||||
def fromHexString(data: String): Option[Array[Byte]] = Hex.fromHexString(data)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Example Type Class Usage
|
|
||||||
|
|
||||||
```scala
|
|
||||||
def encode[A](data: A)(using HexEncode[A]): String =
|
|
||||||
Hex.toHexString(dataToBytes(data))
|
|
||||||
|
|
||||||
def decode[A](data: String)(using HexDecode[A]): Option[A] =
|
|
||||||
Hex.fromHexString(data).map(dataFromBytes)
|
|
||||||
```
|
|
||||||
|
|
||||||
## 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).
|
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
val scala3: String = "3.5.1"
|
val scala3: String = "3.4.1"
|
||||||
|
|
||||||
externalResolvers := Seq(
|
|
||||||
"Garrity Software Mirror" at "https://maven.garrity.co/releases",
|
|
||||||
"Garrity Software Releases" at "https://maven.garrity.co/gs"
|
|
||||||
)
|
|
||||||
|
|
||||||
ThisBuild / scalaVersion := scala3
|
ThisBuild / scalaVersion := scala3
|
||||||
ThisBuild / versionScheme := Some("semver-spec")
|
ThisBuild / versionScheme := Some("semver-spec")
|
||||||
|
@ -19,7 +14,7 @@ val sharedSettings = Seq(
|
||||||
|
|
||||||
lazy val testSettings = Seq(
|
lazy val testSettings = Seq(
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"org.scalameta" %% "munit" % "1.0.1" % Test
|
"org.scalameta" %% "munit" % "1.0.0-M10" % Test
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
sbt.version=1.10.2
|
sbt.version=1.9.9
|
||||||
|
|
|
@ -28,6 +28,6 @@ externalResolvers := Seq(
|
||||||
"Garrity Software Releases" at "https://maven.garrity.co/gs"
|
"Garrity Software Releases" at "https://maven.garrity.co/gs"
|
||||||
)
|
)
|
||||||
|
|
||||||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.1.0")
|
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
|
||||||
addSbtPlugin("gs" % "sbt-garrity-software" % "0.4.0")
|
addSbtPlugin("gs" % "sbt-garrity-software" % "0.3.0")
|
||||||
addSbtPlugin("gs" % "sbt-gs-semver" % "0.3.0")
|
addSbtPlugin("gs" % "sbt-gs-semver" % "0.3.0")
|
||||||
|
|
|
@ -13,6 +13,8 @@ trait HexDecode[A]:
|
||||||
*/
|
*/
|
||||||
def fromHexString(data: String): Option[A]
|
def fromHexString(data: String): Option[A]
|
||||||
|
|
||||||
|
extension (data: String) def fromHex(): Option[A] = fromHexString(data)
|
||||||
|
|
||||||
object HexDecode:
|
object HexDecode:
|
||||||
|
|
||||||
/** Retrieve the [[HexDecode]] instance for the given type.
|
/** Retrieve the [[HexDecode]] instance for the given type.
|
||||||
|
|
|
@ -12,6 +12,8 @@ trait HexEncode[A]:
|
||||||
*/
|
*/
|
||||||
def toHexString(data: A): String
|
def toHexString(data: A): String
|
||||||
|
|
||||||
|
extension (data: A) def toHex(): String = toHexString(data)
|
||||||
|
|
||||||
object HexEncode:
|
object HexEncode:
|
||||||
|
|
||||||
/** Retrieve the [[HexEncode]] instance for the given type.
|
/** Retrieve the [[HexEncode]] instance for the given type.
|
||||||
|
|
|
@ -89,15 +89,15 @@ class EncodeDecodeTests extends munit.FunSuite:
|
||||||
data: A
|
data: A
|
||||||
)(
|
)(
|
||||||
using
|
using
|
||||||
H: HexEncode[A]
|
HexEncode[A]
|
||||||
): String = H.toHexString(data)
|
): String = data.toHex()
|
||||||
|
|
||||||
private def decode[A](
|
private def decode[A](
|
||||||
data: String
|
data: String
|
||||||
)(
|
)(
|
||||||
using
|
using
|
||||||
H: HexDecode[A]
|
HexDecode[A]
|
||||||
): Option[A] = H.fromHexString(data)
|
): Option[A] = data.fromHex()
|
||||||
|
|
||||||
private def randomByteArray(): Array[Byte] =
|
private def randomByteArray(): Array[Byte] =
|
||||||
val length = Rng.nextInt(MaxLength) + MinLength
|
val length = Rng.nextInt(MaxLength) + MinLength
|
||||||
|
|
Loading…
Add table
Reference in a new issue