Skip to content

Commit

Permalink
Merge pull request #599 from hexagonkt/develop
Browse files Browse the repository at this point in the history
Chores
  • Loading branch information
jaguililla committed Jan 14, 2023
2 parents 8643759 + 647df4a commit 5dd9824
Show file tree
Hide file tree
Showing 112 changed files with 454 additions and 245 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ on:
- cron: "59 23 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
with:
exempt-issue-labels: pinned
include-only-assigned: true
days-before-pr-close: -1
stale-pr-message: This PR is stale because it has been open 60 days with no activity.
stale-issue-message:
"This issue is stale because it has been open 60 days with no activity. Remove stale
label or comment or this will be closed in 7 days."
close-issue-message:
"This issue was closed because it has been stalled for 7 days with no activity."

build:
strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build_site:
name: Build Site
permissions: read-all
uses: hexagonkt/hexagon/.github/workflows/site.yml@develop
uses: hexagonkt/hexagon/.github/workflows/site.yml@master

test_publishing:
name: Test Publishing
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ jobs:
run: |
export REMOTE="https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git"
git remote set-url origin "$REMOTE"
git config --global user.email "juanjoaguililla@gmail.com"
git config --global user.name "jaguililla"
git config --global user.name "$GITHUB_ACTOR"
git clone "$REMOTE" --branch gh-pages build/gh-pages
./gradlew --info build
./gradlew --info -x build buildSite
Expand All @@ -60,8 +59,7 @@ jobs:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
run: |
./gradlew --info --no-daemon -x test release
run: ./gradlew --info --no-daemon -x test release

- name: Publish Site
run: |
Expand Down
68 changes: 28 additions & 40 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You can contribute code or documentation to the toolkit. This document will guid
process or picking a task and building the code.

## Make a Question
You can use the repository's [Discussions tab] to ask questions or resolve problems.
You can use the repository's [Discussions tab][discussion] to ask questions or resolve problems.

You can also ask any question, make suggestions or complaints at the project's
[Slack channel][Slack]. You can also be up-to-date of project's news following [@hexagon_kt] on
Expand All @@ -30,7 +30,7 @@ Create a new issue using the [enhancement template] to file an improvement.
2. Claim an issue you want to work in with a comment, after that I can assign it to you and move it
to the `Working` column. If you want to contribute to a non tagged (or a not existing) tasks:
write a comment, and we'll discuss the scope of the feature.
3. New features should be discussed within a post in the [GitHub ideas discussions][discussion]
3. New features should be discussed within a post in the [GitHub ideas discussions][ideas]
before actual coding. You may do a PR directly, but you take the risk of it being not suitable
and discarded.
4. For code, file names, tags and branches use either camel case or snake case only. I.e.: avoid `-`
Expand All @@ -41,20 +41,16 @@ Create a new issue using the [enhancement template] to file an improvement.
you.
6. Packages must have the same folder structure as in Java (to avoid problems with tools and Java
module definition).
7. Follow the commit rules defined at the [commit template].
8. Bug format: when filing bugs please comply with the [bug template] requirements.
9. A feature requests should follow the [enhancement template] rules.
7. Follow the commit rules defined at the [commit guidelines].

[Organization Board]: https://github.com/orgs/hexagonkt/projects/2
[help wanted]: https://github.com/hexagonkt/hexagon/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22
[pull request template]: https://github.com/hexagonkt/hexagon/blob/master/.github/pull_request_template.md
[pull request template]: https://github.com/hexagonkt/.github/blob/master/pull_request_template.md
[IntelliJ]: https://www.jetbrains.com/idea
[Editor Config]: https://editorconfig.org
[Kotlin Coding Conventions]: https://kotlinlang.org/docs/reference/coding-conventions.html
[commit template]: https://github.com/hexagonkt/hexagon/blob/master/.github/commit_template.txt
[bug template]: https://github.com/hexagonkt/hexagon/blob/master/.github/ISSUE_TEMPLATE/bug.md
[enhancement template]: https://github.com/hexagonkt/hexagon/blob/master/.github/ISSUE_TEMPLATE/enhancement.md
[discussion]: https://github.com/hexagonkt/hexagon/discussions/categories/ideas
[commit guidelines]: https://github.com/hexagonkt/.github/blob/master/commits.md
[ideas]: https://github.com/hexagonkt/hexagon/discussions/categories/ideas

## Project Structure
The Hexagon project is composed of several modules. Most of the modules publish libraries for their
Expand Down Expand Up @@ -85,27 +81,21 @@ cd hexagon
The binaries are located in the `/build` directory of each module. The documentation site is in
`/site/build`.

To work more comfortable, you can define some useful aliases like:

```bash
alias gw='./gradlew'
```

Other useful Gradle commands (assuming `alias gw='./gradlew'`) are:

* Help: `gw help`
* Tasks: `gw tasks`
* Module Tasks: `gw [module:]tasks [--all]`
* Task details: `gw help --task <task>`
* Package: `gw clean assemble`
* Build: `gw build`
* Rebuild: `gw clean build`
* Documentation: `gw javadoc`
* Test: `gw test`
* Run: `gw ${MODULE}:run`
* Profile Build: `gw ${TASK} --profile`
* Project Dependencies: `gw dependencyReport` or `gw htmlDependencyReport`
* Project Tasks: `gw taskReport`
Other useful Gradle commands are:

* Help: `./gradlew help`
* Tasks: `./gradlew tasks`
* Module Tasks: `./gradlew [module:]tasks [--all]`
* Task details: `./gradlew help --task <task>`
* Package: `./gradlew clean assemble`
* Build: `./gradlew build`
* Rebuild: `./gradlew clean build`
* Documentation: `./gradlew javadoc`
* Test: `./gradlew test`
* Run: `./gradlew ${MODULE}:run`
* Profile Build: `./gradlew ${TASK} --profile`
* Project Dependencies: `./gradlew dependencyReport` or `./gradlew htmlDependencyReport`
* Project Tasks: `./gradlew taskReport`

It is recommended that you create a Git pre-push script to check the code before pushing it. As
this command will be executed before pushing code to the repository (saving you time fixing
Expand All @@ -128,19 +118,17 @@ If you want to generate the documentation site, check the Hexagon's site module
8. Update example projects inside the organization
9. Create a changelog to announce the release
10. Publish changelog on:
* Dev.to
* Kotlin Slack
* Reddit
* Twitter
* Kotlin Weekly Newsletter
* LinkedIn
* Dev.to
* Kotlin Slack
* Reddit
* Twitter
* Kotlin Weekly Newsletter
* LinkedIn

[Nexus Repository Manager]: https://oss.sonatype.org

### Changelog commands
Commit messages can be filtered by types (check [commit_template.txt]) for details.

[commit_template.txt]: /.github/commit_template.txt
Commit messages can be filtered by types (check the [commit guidelines]) for details.

```bash
git log 1.2.0...1.3.0 \
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/hexagonkt/core/Glob.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hexagonkt.core

import java.lang.IllegalArgumentException
import kotlin.IllegalArgumentException
import java.util.regex.PatternSyntaxException

/**
Expand Down
56 changes: 0 additions & 56 deletions core/src/main/kotlin/com/hexagonkt/core/Helpers.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hexagonkt.core

import com.hexagonkt.core.logging.Logger
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
Expand All @@ -21,8 +20,6 @@ import java.util.concurrent.TimeUnit.SECONDS
*/
var disableChecks: Boolean = Jvm.systemFlag("DISABLE_CHECKS")

private val logger: Logger by lazy { Logger("com.hexagonkt.core.Helpers") }

/**
* Print receiver to stdout. Convenient utility to debug variables quickly.
*
Expand All @@ -47,59 +44,6 @@ fun properties(url: URL): Map<String, String> =
.mapKeys { it.key as String }
.mapValues { it.value as String }

// NETWORK /////////////////////////////////////////////////////////////////////////////////////////
/** Internet address used to bind services to all local network interfaces. */
val allInterfaces: InetAddress = inetAddress(0, 0, 0, 0)

/** Internet address used to bind services to the loopback interface. */
val loopbackInterface: InetAddress = inetAddress(127, 0, 0, 1)

/**
* Syntactic sugar to create an Internet address.
*
* @param bytes Bytes used in the address.
* @return The Internet address corresponding with the supplied bytes.
*/
fun inetAddress(vararg bytes: Byte): InetAddress =
InetAddress.getByAddress(bytes)

/**
* Return a random free port (not used by any other local process).
*
* @return Random free port number.
*/
fun freePort(): Int =
ServerSocket(0).use { it.localPort }

/**
* Check if a port is already opened.
*
* @param port Port number to check.
* @return True if the port is open, false otherwise.
*/
fun isPortOpened(port: Int): Boolean =
try {
Socket("localhost", port).use { it.isConnected }
}
catch (e: Exception) {
logger.debug { "Checked port: $port is already open" }
false
}

fun URL.responseCode(): Int =
try {
(openConnection() as HttpURLConnection).responseCode
}
catch (e: java.lang.Exception) {
400
}

fun URL.responseSuccessful(): Boolean =
responseCode() in 200 until 300

fun URL.responseFound(): Boolean =
responseCode().let { it in 200 until 500 && it != 404 }

// PROCESSES ///////////////////////////////////////////////////////////////////////////////////////
/**
* Execute a lambda until no exception is thrown or a number of times is reached.
Expand Down
89 changes: 89 additions & 0 deletions core/src/main/kotlin/com/hexagonkt/core/Network.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.hexagonkt.core

import com.hexagonkt.core.logging.Logger
import java.io.File
import java.net.*
import java.util.*

private val logger: Logger by lazy { Logger("com.hexagonkt.core.Helpers") }

/** Internet address used to bind services to all local network interfaces. */
val allInterfaces: InetAddress = inetAddress(0, 0, 0, 0)

/** Internet address used to bind services to the loopback interface. */
val loopbackInterface: InetAddress = inetAddress(127, 0, 0, 1)

/**
* Syntactic sugar to create an Internet address.
*
* @param bytes Bytes used in the address.
* @return The Internet address corresponding with the supplied bytes.
*/
fun inetAddress(vararg bytes: Byte): InetAddress =
InetAddress.getByAddress(bytes)

/**
* Return a random free port (not used by any other local process).
*
* @return Random free port number.
*/
fun freePort(): Int =
ServerSocket(0).use { it.localPort }

/**
* Check if a port is already opened.
*
* @param port Port number to check.
* @return True if the port is open, false otherwise.
*/
fun isPortOpened(port: Int): Boolean =
try {
Socket("localhost", port).use { it.isConnected }
}
catch (e: Exception) {
logger.debug { "Checked port: $port is already open" }
false
}

fun URL.responseCode(): Int =
try {
(openConnection() as HttpURLConnection).responseCode
}
catch (e: java.lang.Exception) {
400
}

fun URL.responseSuccessful(): Boolean =
responseCode() in 200 until 300

fun URL.responseFound(): Boolean =
responseCode().let { it in 200 until 500 && it != 404 }

// TODO Review the next functions, not all cases are covered
fun URL.exists(): Boolean =
when (protocol) {
"http" -> responseSuccessful()
"https" -> responseSuccessful()
"file" -> File(file).let { it.exists() && !it.isDirectory }
"classpath" -> try { openConnection(); true } catch (_: Exception) { false }
else -> false
}

fun URL.firstVariant(vararg suffixes: String): URL {
val extension = file.substringAfter('.').println()
val fileName = file.removeSuffix(".$extension").println()

suffixes.forEach {
val u = URL("$protocol:$fileName$it.$extension".println())
if (u.exists())
return u
}

return this
}

fun URL.localized(locale: Locale): URL {
val language = locale.language
val country = locale.country
return firstVariant("_${language}_$country", "_${language}")
}
2 changes: 1 addition & 1 deletion core/src/main/kotlin/com/hexagonkt/core/Strings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.hexagonkt.core

import java.io.ByteArrayInputStream
import java.io.InputStream
import java.lang.IllegalArgumentException
import kotlin.IllegalArgumentException
import java.lang.System.getProperty
import java.net.InetAddress
import java.net.URI
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/com/hexagonkt/core/AnsiTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hexagonkt.core

import com.hexagonkt.core.logging.Logger
import org.junit.jupiter.api.Test
import kotlin.test.Test

internal class AnsiTest {

Expand Down
4 changes: 2 additions & 2 deletions core/src/test/kotlin/com/hexagonkt/core/ChecksTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hexagonkt.core

import org.junit.jupiter.api.Test
import java.lang.IllegalArgumentException
import kotlin.test.Test
import kotlin.IllegalArgumentException
import java.net.URL
import java.time.LocalDate
import kotlin.test.assertEquals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.hexagonkt.core
import com.hexagonkt.core.logging.LoggingLevel
import com.hexagonkt.core.logging.LoggingManager
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import kotlin.test.Test
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS
import java.net.MalformedURLException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hexagonkt.core

import org.junit.jupiter.api.Test
import kotlin.test.Test

internal class CodedExceptionTest {

Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/com/hexagonkt/core/DataTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hexagonkt.core

import org.junit.jupiter.api.Test
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertFalse
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/kotlin/com/hexagonkt/core/DatesTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hexagonkt.core

import org.junit.jupiter.api.Test
import kotlin.test.Test
import java.time.*
import java.time.Month.*
import java.util.Calendar
Expand Down

0 comments on commit 5dd9824

Please sign in to comment.