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

Migration to new package in Maven Central #1744

Merged
merged 31 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5f2d767
Migration to new package in Maven Central
nulls Sep 22, 2023
6b19f26
updated PublishingConfiguration.kt
nulls Sep 22, 2023
7a8405d
changed branch to test deploy
nulls Sep 22, 2023
42d7c61
Merge branch 'master' into feature/maven-central-release#1712
nulls Sep 25, 2023
72c3b76
added maven local
nulls Sep 25, 2023
6e0ab8d
Merge branch 'master' into feature/maven-central-release#1712
nulls Sep 25, 2023
cbd8cc3
Merge remote-tracking branch 'origin/feature/maven-central-release#17…
nulls Sep 25, 2023
a3fa9c0
restored plugin in each component
nulls Sep 25, 2023
73d1cb8
small fixes
nulls Sep 25, 2023
8457081
removed deprecated buildDir
nulls Sep 25, 2023
05e99e7
Merge remote-tracking branch 'origin/master' into feature/maven-centr…
nulls Sep 25, 2023
4f2d830
small changes
nulls Sep 25, 2023
855549d
upgraded dokka
nulls Sep 25, 2023
b36e174
cleanup
nulls Sep 25, 2023
adadb5e
Merge remote-tracking branch 'origin/master' into feature/maven-centr…
nulls Sep 25, 2023
42a6c43
disabled javadoc for gradle plugin (we use dokka)
nulls Sep 26, 2023
5351401
diktatFix
nulls Sep 26, 2023
d615944
enabled for now publishing snapshots + diktatFix
nulls Sep 26, 2023
ad2aefc
Merge remote-tracking branch 'origin/master' into feature/maven-centr…
nulls Sep 26, 2023
ee784e3
fixed url for github repository
nulls Sep 26, 2023
8e6dde5
fixed snapshot build
nulls Sep 26, 2023
3f06488
cleanup
nulls Sep 26, 2023
6c06fe1
signing after evaluate
nulls Sep 26, 2023
10e916e
removed workflow_dispatch
nulls Sep 26, 2023
46c09fe
small fixes taken from kompiledb
nulls Sep 26, 2023
e265cc1
maven publishing for gradle plugin
nulls Sep 26, 2023
94fdf3f
added maven publishing for diktat-cli
nulls Sep 26, 2023
23a3ec6
disabled default publishing
nulls Sep 26, 2023
efdf2a3
additional dependency to dokkaJar in gradle plugin
nulls Sep 26, 2023
72e7baf
added using snapshot version
nulls Sep 26, 2023
33d423d
fixed diktat_snapshot.yml
nulls Sep 26, 2023
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
32 changes: 30 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ concurrency:
group: ${{ github.ref == 'refs/heads/master' && format('{0}-{1}', github.workflow, github.sha) || format('{0}-{1}', github.workflow, github.ref) }}
cancel-in-progress: true

env:
GRADLE_OPTS: -Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.welcome=never
GPG_SEC: ${{ secrets.PGP_SEC }}
GPG_PASSWORD: ${{ secrets.PGP_PASSWORD }}
OSSRH_USERNAME: ${{ secrets.SONATYPE_USER }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build_and_test_with_code_coverage:
name: Build, test and upload code coverage
Expand Down Expand Up @@ -233,6 +241,7 @@ jobs:
contents: write
pull-requests: write
statuses: write
packages: write

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -305,6 +314,27 @@ jobs:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

- name: 'Publish a snapshot to GitHub'
id: publish-github
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref == 'refs/heads/master' }}
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
-Preckon.stage=snapshot
publishAllPublicationsToGitHubRepository

- name: 'Publish a snapshot to Maven Central'
id: publish-sonatype
if: ${{ github.event_name == 'push' && github.ref_type == 'branch' && github.ref == 'refs/heads/master' }}
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
arguments: |
-Preckon.stage=snapshot
publishToSonatype
closeAndReleaseSonatypeStagingRepository

report:
name: Publish JUnit test results
if: ${{ always() }}
Expand Down Expand Up @@ -332,7 +362,6 @@ jobs:
with:
check_name: JUnit Tests (${{ runner.os }}, EnricoMi/publish-unit-test-result-action@v2)
junit_files: |
**/target/*-reports/TEST-*.xml
**/build/test-results/*/TEST-*.xml

- name: JUnit Tests (EnricoMi/publish-unit-test-result-action@v2, Windows or Mac OS X)
Expand All @@ -341,5 +370,4 @@ jobs:
with:
check_name: JUnit Tests (${{ runner.os }}, EnricoMi/publish-unit-test-result-action@v2)
junit_files: |
**/target/*-reports/TEST-*.xml
**/build/test-results/*/TEST-*.xml
22 changes: 1 addition & 21 deletions .github/workflows/diktat_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,13 @@ jobs:
:generateLibsForDiktatSnapshot
-x detekt
-x test
# FixMe: return after 2.0.0
# -x diktatCheck

- name: 'Copy files and set flags'
run: |
echo "DIKTAT_SNAPSHOT=1" >> $GITHUB_ENV
mv gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.txt gradle/plugins/src/main/kotlin/com/saveourtool/diktat/buildutils/diktat-convention-configuration.gradle.kts
-x diktatCheck

- name: 'Override <gradle/libs.versions.toml>'
run: |
mv gradle/libs.versions.toml gradle/libs.versions.toml_current
mv build/diktat-snapshot/libs.versions.toml_snapshot gradle/libs.versions.toml

# FixMe: remove after 2.0.0
- name: 'Small hack to inject implementation and to run diktat properly from snapshot'
run: |
#!/bin/bash
file_path=gradle/plugins/build.gradle.kts
string_to_insert='
dependencies {
implementation(libs.diktat.gradle.plugin) {
exclude("io.github.detekt.sarif4k", "sarif4k")
}
}'

echo $string_to_insert >> $file_path

# copied from .github/workflows/diktat.yml
- uses: gradle/gradle-build-action@v2
with:
Expand Down
127 changes: 43 additions & 84 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,60 @@ on:
tags:
- 'v*'

env:
GRADLE_OPTS: -Dorg.gradle.daemon=true -Dorg.gradle.parallel=true -Dorg.gradle.welcome=never
GPG_SEC: ${{ secrets.PGP_SEC }}
GPG_PASSWORD: ${{ secrets.PGP_PASSWORD }}
OSSRH_USERNAME: ${{ secrets.SONATYPE_USER }}
OSSRH_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build release
release:
name: 'Release'
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 11
- uses: actions/checkout@v3
with:
# Fetch Git tags, so that semantic version can be calculated.
# Alternatively, run `git fetch --prune --unshallow --tags` as the
# next step, see
# https://github.com/actions/checkout/issues/206#issuecomment-607496604.
fetch-depth: 0

- name: 'Set up Java'
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
- name: Cache local Maven repository
uses: actions/cache@v3
distribution: temurin

- name: 'Publish a release to GitHub'
id: publish-github
uses: gradle/gradle-build-action@v2
with:
path: ~/.m2/repository
key: maven-build-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-build-
- name: Setup environment
env:
DIKTAT_GPG_PUB: ${{ secrets.DIKTAT_PGP_PUB }}
DIKTAT_GPG_SEC: ${{ secrets.DIKTAT_PGP_SEC }}
# Note: maven-help-plugin requires non-interactive mode (do not add -B flag).
run: |
previous_version=$(printf 'VERSION=${diktat-check.version}\n0\n' | mvn help:evaluate | grep '^VERSION' | cut -d= -f2)
echo "PREVIOUS_VERSION=$previous_version" >> $GITHUB_ENV
echo "RELEASE_VERSION=${GITHUB_REF#'refs/tags/v'}" >> $GITHUB_ENV
echo "$DIKTAT_GPG_PUB" > ~/diktat.pubring.gpg
echo "$DIKTAT_GPG_SEC" > ~/diktat.secring.gpg
gpg --import ~/diktat.pubring.gpg
gpg --batch --import ~/diktat.secring.gpg # --batch suppresses intercatively asking passphrase
- name: Set version
run: mvn -B versions:set -DnewVersion=${{ env.RELEASE_VERSION }} versions:commit
- name: Create settings.xml
uses: whelk-io/maven-settings-xml-action@v21
gradle-version: wrapper
arguments: |
publishAllPublicationsToGitHubRepository

- name: 'Publish a release to Maven Central'
id: publish-sonatype
uses: gradle/gradle-build-action@v2
with:
servers: |
[
{ "id": "ossrh", "username": "${{ secrets.SONATYPE_USER }}", "password": "${{ secrets.SONATYPE_PASSWORD }}" },
{ "id": "gpg.passphrase", "passphrase": "${{ secrets.DIKTAT_GPG_PASS }}" },
{ "id": "kotlin-maven-plugin-tools", "username": "${{github.actor}}", "password": "${{ secrets.GITHUB_TOKEN }}" }
]
- name: Deploy artifacts
run: mvn -B -Dstyle.color=always clean deploy -Prelease --projects '!diktat-ruleset'
- name: Build diktat.jar
run: mvn -B -Dstyle.color=always package --projects diktat-ruleset
- name: Create Github Release
id: create_release
gradle-version: wrapper
arguments: |
publishToSonatype
closeAndReleaseSonatypeStagingRepository

github_release:
needs: release
name: 'Github Release'
runs-on: ubuntu-latest
steps:
- name: 'Github Release'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ env.RELEASE_VERSION }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Upload assets to github releases
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./diktat-ruleset/target/diktat-${{ env.RELEASE_VERSION }}.jar
asset_name: diktat-${{ env.RELEASE_VERSION }}.jar
asset_content_type: application/zip
- name: Update versions in pom.xml and documentation, update examples
id: update-versions
run: |
mvn -B versions:set -DnextSnapshot=true -DprocessAllModules=true versions:commit
mvn versions:set-property -Dproperty=diktat-check.version -DnewVersion=${{ env.RELEASE_VERSION }}
sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" README.md || echo "File README.md hasn't been updated!"
for file in examples/{maven/pom.xml,gradle-groovy-dsl/build.gradle,{gradle-kotlin-dsl,gradle-kotlin-dsl-multiproject}/build.gradle.kts}
do
sed -i "s/$PREVIOUS_VERSION/$RELEASE_VERSION/g" $file || echo "File $file hasn't been updated!"
cp diktat-rules/src/main/resources/diktat-analysis.yml $(dirname $file)
done
next_snapshot_version=$(printf 'VERSION=${project.version}\n0\n' | mvn help:evaluate | grep '^VERSION' | cut -d= -f2)
# Update the version in `examples/maven/pom.xml`
# (which is not a part of the multi-module project).
for file in examples/maven/pom.xml
do
sed -i "s|\(<version>\)[[:digit:]]\(\.[[:digit:]]\)\+-SNAPSHOT\(</version>\)|\1${next_snapshot_version}\3|g" "${file}" || echo "File ${file} hasn't been updated (2nd sed pass)"
done
echo "version=$next_snapshot_version" > info/buildSrc/gradle.properties
- name: Create pull request
uses: peter-evans/create-pull-request@v5
with:
author: GitHub <[email protected]>
commit-message: Prepare next development iteration after release ${{ env.RELEASE_VERSION }}
branch: infra/diktat-version-update-to-${{ env.RELEASE_VERSION }}
title: Update versions in pom.xml and documentation after ${{ env.RELEASE_VERSION }} release
body: |
* Versions are updated in pom.xml, README.md and in examples
* Current project version is incremented to the next snapshot
base: master
28 changes: 17 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import com.saveourtool.diktat.buildutils.configureSigning
import org.jetbrains.kotlin.incremental.createDirectory
import java.nio.file.Files

Expand Down Expand Up @@ -26,10 +25,12 @@ talaiot {

project.description = "diKTat kotlin formatter and fixer"

configureSigning()

tasks.create("generateLibsForDiktatSnapshot") {
val dir = rootProject.buildDir.resolve("diktat-snapshot")
val dir = rootProject.layout
.buildDirectory
.dir("diktat-snapshot")
.get()
.asFile

val dependencies = setOf(
rootProject.project(":diktat-common"),
Expand Down Expand Up @@ -86,13 +87,15 @@ fun File.pathToMavenArtifact(project: Project): File = project.group.toString()
/**
* @return generated pom.xml for project dependency
*/
fun Project.pomFile(): File = buildDir.resolve("publications")
.let { publicationsDir ->
publicationsDir.resolve("pluginMaven")
.takeIf { it.exists() }
?: publicationsDir.resolve("maven")
fun Project.pomFile(): File = layout.buildDirectory
.dir("publications")
.map { publicationsDir ->
publicationsDir.dir("pluginMaven")
.takeIf { it.asFile.exists() }
?: publicationsDir.dir("maven")
}
.resolve("pom-default.xml")
.map { it.file("pom-default.xml").asFile }
.get()

/**
* @return file name of pom.xml for project
Expand All @@ -102,7 +105,10 @@ fun Project.pomFileName(): String = "$name-$version.pom"
/**
* @return generated artifact for project dependency
*/
fun Project.artifactFile(): File = buildDir.resolve("libs/${artifactFileName()}")
fun Project.artifactFile(): File = layout.buildDirectory
.dir("libs")
.map { it.file(artifactFileName()).asFile }
.get()

/**
* @return file name of artifact for project dependency
Expand Down
4 changes: 2 additions & 2 deletions diktat-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.saveourtool.diktat.buildutils.kotlin-jvm-configuration")
id("com.saveourtool.diktat.buildutils.code-quality-convention")
id("com.saveourtool.diktat.buildutils.publishing-signing-default-configuration")
id("com.saveourtool.diktat.buildutils.publishing-default-configuration")
alias(libs.plugins.kotlin.plugin.serialization)
}

Expand All @@ -13,7 +13,7 @@ dependencies {
}

val generateDiktatVersionFile by tasks.registering {
val outputDir = File("$buildDir/generated/src")
val outputDir = layout.buildDirectory.dir("generated/src").get().asFile
val versionsFile = outputDir.resolve("generated/DiktatVersion.kt")

val diktatVersion = version.toString()
Expand Down
25 changes: 22 additions & 3 deletions diktat-cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.jetbrains.kotlin.incremental.createDirectory

@Suppress("DSL_SCOPE_VIOLATION", "RUN_IN_SCRIPT") // https://github.com/gradle/gradle/issues/22797
plugins {
id("com.saveourtool.diktat.buildutils.kotlin-jvm-configuration")
id("com.saveourtool.diktat.buildutils.code-quality-convention")
id("com.saveourtool.diktat.buildutils.publishing-signing-default-configuration")
id("com.saveourtool.diktat.buildutils.publishing-configuration")
alias(libs.plugins.kotlin.plugin.serialization)
alias(libs.plugins.shadow)
}
Expand All @@ -27,9 +28,12 @@ dependencies {
testImplementation(libs.mockito)
}

val addLicenseTask = tasks.register("addLicense") {
val addLicenseTask: TaskProvider<Task> = tasks.register("addLicense") {
val licenseFile = rootProject.file("LICENSE")
val outputDir = File("$buildDir/generated/src")
val outputDir = layout.buildDirectory
.dir("generated/src")
.get()
.asFile

inputs.file(licenseFile)
outputs.dir(outputDir)
Expand Down Expand Up @@ -70,4 +74,19 @@ tasks {
build {
dependsOn(shadowJar)
}
test {
dependsOn(shadowJar)
}
}

publishing {
publications {
// it creates a publication for shadowJar
create<MavenPublication>("shadow") {
// https://github.com/johnrengelman/shadow/issues/417#issuecomment-830668442
project.extensions.configure<ShadowExtension> {
component(this@create)
}
}
}
}
2 changes: 1 addition & 1 deletion diktat-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
plugins {
id("com.saveourtool.diktat.buildutils.kotlin-jvm-configuration")
id("com.saveourtool.diktat.buildutils.code-quality-convention")
id("com.saveourtool.diktat.buildutils.publishing-signing-default-configuration")
id("com.saveourtool.diktat.buildutils.publishing-default-configuration")
alias(libs.plugins.kotlin.plugin.serialization)
}

Expand Down
Loading
Loading