diff --git a/.github/workflows/feature-branch.yml b/.github/workflows/feature-branch.yml new file mode 100644 index 0000000..c0b2c00 --- /dev/null +++ b/.github/workflows/feature-branch.yml @@ -0,0 +1,49 @@ +name: On push to a feature branch + +on: + push: + branches: + - '*' + paths-ignore: + - '**.md' + - '**.adoc' + - '**/.gitignore' + - './github/**' + - '!./github/workflow/feature-branch.yml' + pull_request: + branches: + - '*' + +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: + java-version: '11' + distribution: 'adopt' + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build + run: ./gradlew build -Pversion=${{steps.get-version.outputs.version}} diff --git a/.github/workflows/feature-merged.yml b/.github/workflows/feature-merged.yml new file mode 100644 index 0000000..2d164e3 --- /dev/null +++ b/.github/workflows/feature-merged.yml @@ -0,0 +1,51 @@ +name: On merge into main + +on: + push: + branches: + - 'main' + paths-ignore: + - '**.md' + - '**.adoc' + - '**/.gitignore' + - './github/**' + - '!./github/workflow/feature-merged.yml' + +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: + java-version: '11' + distribution: 'adopt' + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build and publish to maven central snapshots + run: ./gradlew publishAllPublicationsToOss -Pversion=${{steps.get-version.outputs.version}} + 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/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 }} - diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml deleted file mode 100644 index 1cf191c..0000000 --- a/.github/workflows/snapshot.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Snapshot workflow - -on: - push: - branches: - - 'snapshot/*' - paths-ignore: - - '**.md' - - '**.adoc' - - '**/.gitignore' - - './github/**' - - '!./github/workflow/snapshot.yml' - -jobs: - snapshot: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - java-version: '11' - distribution: 'adopt' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Build and publish to maven central snapshots - run: ./gradlew publishAllPublicationsToOss -PsnapshotVersion=true - 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/wip.yml b/.github/workflows/wip.yml deleted file mode 100644 index c67ba77..0000000 --- a/.github/workflows/wip.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Push workflow - -on: - push: - branches: - - '*' - paths-ignore: - - '**.md' - - '**.adoc' - - '**/.gitignore' - - './github/**' - - '!./github/workflow/snapshot.yml' - pull_request: - branches: - - '*' - -jobs: - snapshot: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - java-version: '11' - distribution: 'adopt' - - name: Grant execute permission for gradlew - 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/build.gradle.kts b/build.gradle.kts index 561d678..a7788fd 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 = "0.0.1-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().contains("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' -