Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECWID-155655 Add a new section with sanitized version for ecwid-api-client's local testing #449

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ jobs:
cache: 'gradle'

- name: Build, run tests and upload dev snapshot to Maven Central with Gradle
run: ./gradlew devSnapshot printDevSnapshotReleaseNote
run: |
./gradlew devSnapshot printDevSnapshotReleaseNote printSanitizedVersion
cat sanitized_version.md >> $GITHUB_STEP_SUMMARY
env:
STORE_ID: ${{ secrets.STORE_ID }}
API_TOKEN: ${{ secrets.API_TOKEN }}
Expand All @@ -34,6 +36,7 @@ jobs:
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
GITHUB_HEAD_REF: ${{ github.head_ref }}
GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha }}

- name: Upload artifacts with checks results
uses: actions/upload-artifact@v3
Expand Down
27 changes: 25 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ tasks.register(Tasks.PRINT_DEV_SNAPSHOT_RELEASE_NOTE_TASK_NAME) {
dependsOn(tasks.getByName("devSnapshot"))
}

tasks.register(Tasks.PRINT_SUMMARY_SANITIZED_TASK_NAME) {
doLast {
printSanitizedVersion(project.sanitizeVersion())
}
}

detekt {
allRules = false
basePath = "$projectDir"
Expand Down Expand Up @@ -210,15 +216,16 @@ nexusPublishing {
// <major>.<minor>.<patch>-dev.#+<branchname>.<hash> (local branch)
// <major>.<minor>.<patch>-dev.#+<hash> (github pull request)
// to:
// <major>.<minor>.<patch>-dev+<branchname>-SNAPSHOT
// <major>.<minor>.<patch>-dev+<branchname>_<hash>-SNAPSHOT
fun Project.sanitizeVersion(): String {
val version = version.toString()
return if (project.isSnapshotVersion()) {
val githubHeadRef = settingsProvider.githubHeadRef
val githubHeadSHA = settingsProvider.githubHeadSHA?.take(Consts.MAX_HEAD_SHA_LENGTH)
if (githubHeadRef != null) {
// github pull request
version
.replace(Regex("-dev\\.\\d+\\+[a-f0-9]+$"), "-dev+$githubHeadRef-SNAPSHOT")
.replace(Regex("-dev\\.\\d+\\+[a-f0-9]+$"), "-dev+${githubHeadRef}_$githubHeadSHA-SNAPSHOT")
} else {
// local branch
version
Expand Down Expand Up @@ -273,6 +280,16 @@ fun printDevSnapshotReleaseNote(groupId: String, artifactId: String, sanitizedVe
println()
}

fun printSanitizedVersion(sanitizedVersion: String) {
val markdownMessage = """
|## Sanitized Version
|
|**Version:** $sanitizedVersion
|
""".trimMargin()
File("sanitized_version.md").writeText(markdownMessage)
}

class SettingsProvider {

val gpgSigningKey: String?
Expand All @@ -290,6 +307,9 @@ class SettingsProvider {
val githubHeadRef: String?
get() = System.getenv(GITHUB_HEAD_REF_PROPERTY)

val githubHeadSHA: String?
get() = System.getenv(GITHUB_HEAD_SHA_PROPERTY)

fun validateGPGSecrets() = require(
value = !gpgSigningKey.isNullOrBlank() && !gpgSigningPassword.isNullOrBlank(),
lazyMessage = {
Expand All @@ -310,6 +330,7 @@ class SettingsProvider {
private const val OSSRH_USERNAME_PROPERTY = "OSSRH_USERNAME"
private const val OSSRH_PASSWORD_PROPERTY = "OSSRH_PASSWORD"
private const val GITHUB_HEAD_REF_PROPERTY = "GITHUB_HEAD_REF"
private const val GITHUB_HEAD_SHA_PROPERTY = "GITHUB_HEAD_SHA"
}
}

Expand Down Expand Up @@ -339,9 +360,11 @@ object PublicationSettings {
object Consts {
const val SLOW_TESTS_LOGGING_THRESHOLD_MS = 30_000L
const val MAX_TEST_RETRIES_COUNT = 3
const val MAX_HEAD_SHA_LENGTH = 8
}

object Tasks {
const val PRINT_FINAL_RELEASE_NOTE_TASK_NAME = "printFinalReleaseNote"
const val PRINT_DEV_SNAPSHOT_RELEASE_NOTE_TASK_NAME = "printDevSnapshotReleaseNote"
const val PRINT_SUMMARY_SANITIZED_TASK_NAME = "printDevSanitizedVersion"
}
Loading