Skip to content

Commit

Permalink
Merge branch 'Nolij:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysdh540 authored May 17, 2024
2 parents 5ea26b0 + 18965d7 commit b304064
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 14 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: build
on: [ push ]

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
- name: :build
run: ./gradlew build -x test --stacktrace
- name: :test
run: ./gradlew test --stacktrace
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ZSON
path: "**/zson-*.jar"
38 changes: 38 additions & 0 deletions .github/workflows/dco.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "DCO Assistant"
on:
issue_comment:
types: [created]
pull_request_target:
types: [opened, closed, synchronize]

permissions:
actions: write
contents: write
pull-requests: write
statuses: write

jobs:
DCO:
runs-on: ubuntu-latest
steps:
- name: "DCO Assistant"
if: (
github.event.comment.body == 'recheck' ||
github.event.comment.body == 'I have read and hereby affirm the entire contents of the Developer Certificate of Origin.'
) || github.event_name == 'pull_request_target'
uses: cla-assistant/github-action@v2.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path-to-signatures: "signatures.json"
path-to-document: "https://github.com/Nolij/ZSON/blob/dco/DCO.txt"
branch: "dco"
create-file-commit-message: "Create DCO signature list"
signed-commit-message: "Add $contributorName to the DCO signature list"
custom-notsigned-prcomment:
"Before we can merge your submission, we require that you read and affirm the contents of the
[Developer Certificate of Origin](https://github.com/Nolij/ZSON/blob/dco/DCO.txt) by adding a comment containing the below text.
Otherwise, please close this PR."
custom-pr-sign-comment: "I have read and hereby affirm the entire contents of the Developer Certificate of Origin."
custom-allsigned-prcomment: "All contributors have read and affirmed the entire contents of the Developer Certificate of Origin."
use-dco-flag: true
26 changes: 26 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: pull_request
on: [ pull_request ]

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY_PR }}
cache-read-only: true
- name: :build
run: ./gradlew build -x test --stacktrace
- name: :test
run: ./gradlew test --stacktrace
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: ZSON
path: "**/zson-*.jar"
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: release
on: [ workflow_dispatch ]

jobs:
publish:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
cache-read-only: true
- name: :release
run: ./gradlew githubRelease -Prelease_channel=RELEASE
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GRGIT_USER: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env groovy

pipeline {
agent any

tools {
jdk "jdk-21"
}

stages {
stage("Setup") {
steps {
sh "chmod +x gradlew"
}
}

stage(":publish") {
steps {
sh "./gradlew publish -Pexternal_publish=true"
}
}
}
}
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# IMPORTANT LICENSE NOTICE

By using this project in any form, you hereby give your "express assent" for the terms of the license of this
project (see [License](#license)), and acknowledge that I (the author of this project) have fulfilled my obligation
under the license to "make a reasonable effort under the circumstances to obtain the express assent of recipients to
the terms of this License".

# ZSON

a tiny JSON5 parsing library for Java 8, with a focus on simplicity and minimizing size.
A tiny JSON5 parsing library for Java 8, with a focus on simplicity and minimizing size.

## License

This project is licensed under OSL-3.0. For more information, see [LICENSE](LICENSE).
133 changes: 123 additions & 10 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,88 @@
import java.time.ZonedDateTime

plugins {
idea
java
`maven-publish`
id("idea")
id("java")
id("maven-publish")
id("org.ajoberstar.grgit")
id("com.github.breadmoirai.github-release")
}

operator fun String.invoke(): String = rootProject.properties[this] as? String ?: error("Property $this not found")

group = "maven_group"()
version = "project_version"()
base.archivesName = rootProject.name.lowercase()
base.archivesName = "project_name"()

enum class ReleaseChannel(val suffix: String? = null) {
DEV_BUILD("dev"),
RELEASE,
}

val headDateTime: ZonedDateTime = grgit.head().dateTime

val branchName = grgit.branch.current().name!!
val releaseTagPrefix = "release/"

val releaseTags = grgit.tag.list()
.filter { tag -> tag.name.startsWith(releaseTagPrefix) }
.sortedWith { tag1, tag2 ->
if (tag1.commit.dateTime == tag2.commit.dateTime)
if (tag1.name.length != tag2.name.length)
return@sortedWith tag1.name.length.compareTo(tag2.name.length)
else
return@sortedWith tag1.name.compareTo(tag2.name)
else
return@sortedWith tag2.commit.dateTime.compareTo(tag1.commit.dateTime)
}
.dropWhile { tag -> tag.commit.dateTime > headDateTime }

val isExternalCI = (rootProject.properties["external_publish"] as String?).toBoolean()
val isRelease = rootProject.hasProperty("release_channel") || isExternalCI
val releaseIncrement = if (isExternalCI) 0 else 1
val releaseChannel: ReleaseChannel =
if (isExternalCI) {
val tagName = releaseTags.first().name
val suffix = """\-(\w+)\.\d+$""".toRegex().find(tagName)?.groupValues?.get(1)
if (suffix != null)
ReleaseChannel.values().find { channel -> channel.suffix == suffix }!!
else
ReleaseChannel.RELEASE
} else {
if (isRelease)
ReleaseChannel.valueOf("release_channel"())
else
ReleaseChannel.DEV_BUILD
}

println("Release Channel: $releaseChannel")

val minorVersion = "project_version"()
val minorTagPrefix = "${releaseTagPrefix}${minorVersion}."

val patchHistory = releaseTags
.map { tag -> tag.name }
.filter { name -> name.startsWith(minorTagPrefix) }
.map { name -> name.substring(minorTagPrefix.length) }

val maxPatch = patchHistory.maxOfOrNull { it.substringBefore('-').toInt() }
val patch =
maxPatch?.plus(
if (patchHistory.contains(maxPatch.toString()))
releaseIncrement
else
0
) ?: 0
var patchAndSuffix = patch.toString()

if (releaseChannel.suffix != null) {
patchAndSuffix += "-${releaseChannel.suffix}"
}

val versionString = "${minorVersion}.${patchAndSuffix}"
val versionTagName = "${releaseTagPrefix}${versionString}"

version = versionString
println("ZSON Version: $versionString")

repositories {
mavenCentral()
Expand All @@ -23,9 +97,30 @@ dependencies {
}

tasks.jar {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true

from(rootProject.file("LICENSE")) {
rename { "${it}_${rootProject.name}" }
}
}

val sourcesJar = tasks.register<Jar>("sourcesJar") {
group = "build"

archiveClassifier = "sources"
isPreserveFileTimestamps = false
isReproducibleFileOrder = true

from(rootProject.file("LICENSE")) {
rename { "${it}_${rootProject.name}" }
}

from(sourceSets.main.get().allSource) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE }
}

tasks.assemble {
dependsOn(tasks.jar, sourcesJar)
}

tasks.test {
Expand All @@ -45,14 +140,32 @@ tasks.withType<JavaCompile> {
}
}

githubRelease {
setToken(providers.environmentVariable("GITHUB_TOKEN"))
setTagName(versionTagName)
setTargetCommitish("master")
setReleaseName(versionString)
setReleaseAssets(tasks.jar.get().archiveFile, sourcesJar.get().archiveFile)
}

tasks.githubRelease {
dependsOn(tasks.assemble, tasks.check)
}

publishing {
repositories {
if (!System.getenv("local_maven_url").isNullOrEmpty())
maven(System.getenv("local_maven_url"))
}

publications {
create<MavenPublication>("mavenJava") {
create<MavenPublication>("project_name"()) {
artifact(tasks.jar)
artifactId = base.archivesName.get()
artifact(sourcesJar)
}
}
repositories {
mavenLocal()
}
}

tasks.withType<AbstractPublishToMaven> {
dependsOn(tasks.assemble, tasks.check)
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ org.gradle.configuration-cache = false

maven_group = dev.nolij
project_version = 0.1
project_name = zson

# Dependencies
# https://central.sonatype.com/artifact/com.pkware.jabel/jabel-javac-plugin
Expand Down
17 changes: 15 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
pluginManagement {
repositories {
gradlePluginPortal {
content {
excludeGroup("org.apache.logging.log4j")
}
}
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.5.0"
id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0")
id("org.ajoberstar.grgit") version("5.2.2") apply(false)
id("com.github.breadmoirai.github-release") version("2.4.1") apply(false)
}
rootProject.name = "ZSON"

rootProject.name = "zson"

3 changes: 2 additions & 1 deletion src/test/java/ZsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public void testRead() {
assertEquals(Double.POSITIVE_INFINITY, map.get("inf").value);
assertEquals(Double.NEGATIVE_INFINITY, map.get("neginf").value);
assertTrue(Double.isNaN((Double) map.get("nan").value));
assertEquals("wow look \na multiline string", map.get("multiline-string").value);
// TODO: re-enable after fixing multi-line strings
// assertEquals("wow look \na multiline string", map.get("multiline-string").value);
}

@Test
Expand Down

0 comments on commit b304064

Please sign in to comment.