From b187844a59d86624821bda0527ee74200d188ccd Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 00:55:16 -0300 Subject: [PATCH 01/11] build(configs): change build for new ci configurations --- build.gradle.kts | 79 +++++++++++++++++++++++------------------------ gradle.properties | 5 ++- settings.gradle | 1 - 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 561d678..367b7a6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,18 +6,45 @@ plugins { } group = "io.github.vfmunhoz" -version = "1.0.0" - -val snapshotVersion: String = - if(project.hasProperty("snapshotVersion")) project.findProperty("snapshotVersion").toString() - else "true" +version = "1.0.0-SNAPSHOT" +val sonatypeReleaseRepo: String by project +val sonatypeSnapshotRepo: String by project val sonatypeUsername: String? = System.getenv("SONATYPE_USERNAME") val sonatypePassword: String? = System.getenv("SONATYPE_PASSWORD") -val repositoryId: String? = System.getenv("SONATYPE_REPOSITORY_ID") +val sonatypeRepositoryId: String? = System.getenv("SONATYPE_REPOSITORY_ID") + +val gpgPrivateKey: String? = System.getenv("GPG_PRIVATE_KEY") +val gpgPrivatePassword: String? = System.getenv("GPG_PRIVATE_PASSWORD") val dokkaOutputDir = "$buildDir/dokka" +repositories { + mavenCentral() +} + +dependencies { + implementation(kotlin("stdlib")) + implementation(kotlin("reflect")) + + compileOnly("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+") + + testImplementation(kotlin("test")) + testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+") + + dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.5.0") +} + +tasks.test { + useJUnitPlatform() +} + +// Suppressing test compile warnings since we intentionally +// cause an overflow on arithmetic operation for integer types. +tasks.compileTestKotlin { + kotlinOptions.suppressWarnings = true +} + tasks.getByName("dokkaHtml") { outputDirectory.set(file(dokkaOutputDir)) } @@ -37,14 +64,10 @@ val sourcesJar = tasks.register("sourcesJar") { from(sourceSets.getByName("main").allSource) } -repositories { - mavenCentral() -} - signing { useInMemoryPgpKeys( - System.getenv("GPG_PRIVATE_KEY"), - System.getenv("GPG_PRIVATE_PASSWORD") + gpgPrivateKey, + gpgPrivatePassword ) sign(publishing.publications) @@ -55,14 +78,10 @@ publishing { maven { name = "oss" - val releasesRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/") + val repoUri = if (version.toString().endsWith("SNAPSHOT")) { sonatypeSnapshotRepo } + else { sonatypeReleaseRepo } - if(snapshotVersion == "false" && version.toString().endsWith("SNAPSHOT")) { - throw Exception("To publish the release the version must not end with -SNAPSHOT") - } - - url = if (snapshotVersion == "true") snapshotsRepoUrl else releasesRepoUrl + url = uri(repoUri) credentials { username = sonatypeUsername @@ -108,25 +127,3 @@ publishing { } } } - -dependencies { - implementation(kotlin("stdlib")) - implementation(kotlin("reflect")) - - compileOnly("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+") - - testImplementation(kotlin("test")) - testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.12.+") - - dokkaHtmlPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.5.0") -} - -tasks.test { - useJUnitPlatform() -} - -// Suppressing test compile warnings since we intentionally -// cause an overflow on arithmetic operation for integer types. -tasks.compileTestKotlin { - kotlinOptions.suppressWarnings = true -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 29e08e8..73eb2d3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,4 @@ -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official + +sonatypeReleaseRepo="https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" +sonatypeSnapshotRepo="https://s01.oss.sonatype.org/content/repositories/snapshots/" diff --git a/settings.gradle b/settings.gradle index 7f1f205..4f39fa5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ rootProject.name = 'kotlin-protected-types' - From 3556218e0ff92c17b1225236a40ebe02463611c2 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:05:35 -0300 Subject: [PATCH 02/11] ci(configs): change github actions to a better workflow --- .github/workflows/{wip.yml => feature-branch.yml} | 10 ++-------- .github/workflows/{snapshot.yml => feature-merged.yml} | 5 ++--- .github/workflows/release.yml | 5 ++--- 3 files changed, 6 insertions(+), 14 deletions(-) rename .github/workflows/{wip.yml => feature-branch.yml} (63%) rename .github/workflows/{snapshot.yml => feature-merged.yml} (92%) diff --git a/.github/workflows/wip.yml b/.github/workflows/feature-branch.yml similarity index 63% rename from .github/workflows/wip.yml rename to .github/workflows/feature-branch.yml index c67ba77..c1ef73b 100644 --- a/.github/workflows/wip.yml +++ b/.github/workflows/feature-branch.yml @@ -1,4 +1,4 @@ -name: Push workflow +name: On push to a feature branch on: push: @@ -9,7 +9,7 @@ on: - '**.adoc' - '**/.gitignore' - './github/**' - - '!./github/workflow/snapshot.yml' + - '!./github/workflow/feature-branch.yml' pull_request: branches: - '*' @@ -29,9 +29,3 @@ jobs: run: chmod +x gradlew - name: Build run: ./gradlew build - env: - SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} - SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} - GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} - GPG_PRIVATE_PASSWORD: ${{ secrets.GPG_PRIVATE_PASSWORD }} - diff --git a/.github/workflows/snapshot.yml b/.github/workflows/feature-merged.yml similarity index 92% rename from .github/workflows/snapshot.yml rename to .github/workflows/feature-merged.yml index 1cf191c..bf02f66 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/feature-merged.yml @@ -1,4 +1,4 @@ -name: Snapshot workflow +name: On merge into main on: push: @@ -9,7 +9,7 @@ on: - '**.adoc' - '**/.gitignore' - './github/**' - - '!./github/workflow/snapshot.yml' + - '!./github/workflow/feature-merged.yml' jobs: snapshot: @@ -31,4 +31,3 @@ jobs: SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} GPG_PRIVATE_PASSWORD: ${{ secrets.GPG_PRIVATE_PASSWORD }} - diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5d6e72c..489e987 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Release workflow +name: After release published on: release: @@ -18,10 +18,9 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build and publish to maven central - run: ./gradlew publishAllPublicationsToOss -PsnapshotVersion=false + run: ./gradlew publishAllPublicationsToOss env: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} GPG_PRIVATE_PASSWORD: ${{ secrets.GPG_PRIVATE_PASSWORD }} - From 7d25ee57cc8808f4a5c21df101d47a9e58e29c69 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:17:49 -0300 Subject: [PATCH 03/11] ci(configs): add sv4git configuration on feature-branch action --- .github/workflows/feature-branch.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index c1ef73b..90f5c82 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -18,8 +18,27 @@ jobs: snapshot: runs-on: ubuntu-latest steps: + - name: Install packages + run: | + sudo apt update + sudo apt install -y git - name: Checkout uses: actions/checkout@v2 + - name: Get sv4git + run: | + wget -O /tmp/sv4git.zip https://github.com/bvieira/sv4git/releases/download/v2.4.0/git-sv_2.4.0_linux_amd64.tar.gz + cd /usr/local/bin + tar xzf /tmp/sv4git.zip + chmod +x git-sv + - name: Get Version + id: get_version + run: | + VERSION="$(git sv next-version)" + if [[ "${{ github.ref }}" != refs/tags/* ]]; then + VERSION="$VERSION-SNAPSHOT-$(git rev-parse --short HEAD)" + fi + echo "VERSION=$VERSION" + echo "::set-output name=version::$VERSION" - name: Set up JDK 11 uses: actions/setup-java@v2 with: @@ -28,4 +47,4 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build - run: ./gradlew build + run: ./gradlew build -Pversion=$version From d648efec5340f7f179c31f012e9745fcc2f33150 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:19:45 -0300 Subject: [PATCH 04/11] ci(configs): fix miss configuration for feature branch action --- .github/workflows/feature-branch.yml | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index 90f5c82..3ede5fd 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -19,26 +19,26 @@ jobs: runs-on: ubuntu-latest steps: - name: Install packages - run: | - sudo apt update - sudo apt install -y git + run: | + sudo apt update + sudo apt install -y git - name: Checkout uses: actions/checkout@v2 - name: Get sv4git - run: | - wget -O /tmp/sv4git.zip https://github.com/bvieira/sv4git/releases/download/v2.4.0/git-sv_2.4.0_linux_amd64.tar.gz - cd /usr/local/bin - tar xzf /tmp/sv4git.zip - chmod +x git-sv + run: | + wget -O /tmp/sv4git.zip https://github.com/bvieira/sv4git/releases/download/v2.4.0/git-sv_2.4.0_linux_amd64.tar.gz + cd /usr/local/bin + tar xzf /tmp/sv4git.zip + chmod +x git-sv - name: Get Version - id: get_version - run: | - VERSION="$(git sv next-version)" - if [[ "${{ github.ref }}" != refs/tags/* ]]; then - VERSION="$VERSION-SNAPSHOT-$(git rev-parse --short HEAD)" - fi - echo "VERSION=$VERSION" - echo "::set-output name=version::$VERSION" + id: get_version + run: | + VERSION="$(git sv next-version)" + if [[ "${{ github.ref }}" != refs/tags/* ]]; then + VERSION="$VERSION-SNAPSHOT-$(git rev-parse --short HEAD)" + fi + echo "VERSION=$VERSION" + echo "::set-output name=version::$VERSION" - name: Set up JDK 11 uses: actions/setup-java@v2 with: From 1a85e16653ab0a451f9b38159ef49b55adf816d1 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:29:43 -0300 Subject: [PATCH 05/11] ci(configs): change version variable on feature-branch steps --- .github/workflows/feature-branch.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index 3ede5fd..2ba38a3 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -33,10 +33,7 @@ jobs: - name: Get Version id: get_version run: | - VERSION="$(git sv next-version)" - if [[ "${{ github.ref }}" != refs/tags/* ]]; then - VERSION="$VERSION-SNAPSHOT-$(git rev-parse --short HEAD)" - fi + VERSION="$(git sv next-version)-SNAPSHOT-$(git rev-parse --short HEAD)" echo "VERSION=$VERSION" echo "::set-output name=version::$VERSION" - name: Set up JDK 11 @@ -47,4 +44,4 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build - run: ./gradlew build -Pversion=$version + run: ./gradlew build -Pversion=${{steps.vars.outputs.version}} From 2e30ac83c6c11a547c976bd33198a206dfa21fe8 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:49:49 -0300 Subject: [PATCH 06/11] ci(configs): change version var for feature-branch action --- .github/workflows/feature-branch.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index 2ba38a3..b13ba3a 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -31,7 +31,7 @@ jobs: tar xzf /tmp/sv4git.zip chmod +x git-sv - name: Get Version - id: get_version + id: getVersion run: | VERSION="$(git sv next-version)-SNAPSHOT-$(git rev-parse --short HEAD)" echo "VERSION=$VERSION" @@ -44,4 +44,6 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build - run: ./gradlew build -Pversion=${{steps.vars.outputs.version}} + run: | + echo "building version ${steps.getVersion.outputs.version} + ./gradlew build -Pversion=${{steps.getVersion.outputs.version}} From 76d4987c857a38ae47932167732ed7acb55e63c9 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:51:32 -0300 Subject: [PATCH 07/11] ci(configs): add missing token --- .github/workflows/feature-branch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index b13ba3a..e1326c9 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -45,5 +45,5 @@ jobs: run: chmod +x gradlew - name: Build run: | - echo "building version ${steps.getVersion.outputs.version} + echo "building version ${steps.getVersion.outputs.version}" ./gradlew build -Pversion=${{steps.getVersion.outputs.version}} From 9bf3ad4f10bc262dedfc9a7b73927c5d5d316868 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:53:16 -0300 Subject: [PATCH 08/11] ci(configs): change version parameter on feature-branch flow --- .github/workflows/feature-branch.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index e1326c9..0a2862d 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -44,6 +44,4 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build - run: | - echo "building version ${steps.getVersion.outputs.version}" - ./gradlew build -Pversion=${{steps.getVersion.outputs.version}} + run: ./gradlew build -Pversion=${{steps.getVersion.outputs.version}} From 2d485023e981c43dedeed89463d01f239a82bcd5 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 01:57:38 -0300 Subject: [PATCH 09/11] ci(configs): add depth configuration for checkout on feature branch action --- .github/workflows/feature-branch.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index 0a2862d..e84d6d4 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -24,6 +24,8 @@ jobs: sudo apt install -y git - name: Checkout uses: actions/checkout@v2 + with: + fetch-depth: 0 - name: Get sv4git run: | wget -O /tmp/sv4git.zip https://github.com/bvieira/sv4git/releases/download/v2.4.0/git-sv_2.4.0_linux_amd64.tar.gz From 2af7b9b1abae715a4e21c7f0e7aff38576dadf3f Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 02:15:10 -0300 Subject: [PATCH 10/11] ci(configs): change actions for merge on main branch --- .github/workflows/feature-branch.yml | 4 ++-- .github/workflows/feature-merged.yml | 22 ++++++++++++++++++++-- build.gradle.kts | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml index e84d6d4..c0b2c00 100644 --- a/.github/workflows/feature-branch.yml +++ b/.github/workflows/feature-branch.yml @@ -33,7 +33,7 @@ jobs: tar xzf /tmp/sv4git.zip chmod +x git-sv - name: Get Version - id: getVersion + id: get-version run: | VERSION="$(git sv next-version)-SNAPSHOT-$(git rev-parse --short HEAD)" echo "VERSION=$VERSION" @@ -46,4 +46,4 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build - run: ./gradlew build -Pversion=${{steps.getVersion.outputs.version}} + run: ./gradlew build -Pversion=${{steps.get-version.outputs.version}} diff --git a/.github/workflows/feature-merged.yml b/.github/workflows/feature-merged.yml index bf02f66..2d164e3 100644 --- a/.github/workflows/feature-merged.yml +++ b/.github/workflows/feature-merged.yml @@ -3,7 +3,7 @@ name: On merge into main on: push: branches: - - 'snapshot/*' + - 'main' paths-ignore: - '**.md' - '**.adoc' @@ -15,8 +15,26 @@ jobs: snapshot: runs-on: ubuntu-latest steps: + - name: Install packages + run: | + sudo apt update + sudo apt install -y git - name: Checkout uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Get sv4git + run: | + wget -O /tmp/sv4git.zip https://github.com/bvieira/sv4git/releases/download/v2.4.0/git-sv_2.4.0_linux_amd64.tar.gz + cd /usr/local/bin + tar xzf /tmp/sv4git.zip + chmod +x git-sv + - name: Get Version + id: get-version + run: | + VERSION="$(git sv next-version)-SNAPSHOT-$(git rev-parse --short HEAD)" + echo "VERSION=$VERSION" + echo "::set-output name=version::$VERSION" - name: Set up JDK 11 uses: actions/setup-java@v2 with: @@ -25,7 +43,7 @@ jobs: - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Build and publish to maven central snapshots - run: ./gradlew publishAllPublicationsToOss -PsnapshotVersion=true + run: ./gradlew publishAllPublicationsToOss -Pversion=${{steps.get-version.outputs.version}} env: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} diff --git a/build.gradle.kts b/build.gradle.kts index 367b7a6..2cf19f0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "io.github.vfmunhoz" -version = "1.0.0-SNAPSHOT" +version = "0.0.1-SNAPSHOT" val sonatypeReleaseRepo: String by project val sonatypeSnapshotRepo: String by project From dc30a8dc9ac9c1f3fc8a0aabe796696840208cd0 Mon Sep 17 00:00:00 2001 From: Vinicius Montes Munhoz Date: Sat, 4 Sep 2021 15:16:45 -0300 Subject: [PATCH 11/11] build(configs): change oss url logic to fix publishing snapshots to official repo --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 2cf19f0..a7788fd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -78,7 +78,7 @@ publishing { maven { name = "oss" - val repoUri = if (version.toString().endsWith("SNAPSHOT")) { sonatypeSnapshotRepo } + val repoUri = if (version.toString().contains("SNAPSHOT")) { sonatypeSnapshotRepo } else { sonatypeReleaseRepo } url = uri(repoUri)