Skip to content

Commit

Permalink
Merge pull request #7 from lsd-consulting/#4
Browse files Browse the repository at this point in the history
#4 Add automated releases and publishing
  • Loading branch information
lukasz-gryzbon authored Jan 16, 2022
2 parents 9a7c9d8 + b238c90 commit 029784e
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 44 deletions.
51 changes: 51 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

#
# This hook checks the commit message (header only) to ensure that the expected format is used.
#
# Commits with breaking changes should include 'BREAKING CHANGE: <some description>' in the commit body with a description (Note: this is not validated by the hook).
#

commit_regex='^((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-zA-Z0-9 /_,.-]+?\))?: .{1,79}\w|Merge .+|(fixup|squash)! .+)$'

error_msg='
----------------------------------------------------
ABORTING commit - Expecting a conventional commit message header:
<type>[(optional scope)]: <summary - MAX 80 chars>
----------------------------------------------------
Examples:
1.
fix(cache): Fix nasty caching bug (#123)
2.
feat: Enable awesome feature (#456)
3.
chore: Cleanup code to reduce maintenance cost
<newline>
BREAKING CHANGE: Deprecated feature xyz finally removed
<newline>
[optional footer]
----------------------------------------------------
Accepted Types:
build - for changes that affect the build or external dependencies
chore - for general maintenance changes
ci - for changes related to the ci pipeline
docs - for documentation changes
feat - for features [* triggers a MINOR release when pushed]
fix - for fixes [* triggers a PATCH release when pushed]
perf - for performance related changes
refactor - for refactoring
revert - for revert commits
style - for style changes
test - for adding or updating tests
----------------------------------------------------
Exceptions:
fixup! ...
squash! ...
Merge ...
'

if ! grep -iqE "${commit_regex}" "$1"; then
echo "${error_msg}" >&2
exit 1
fi
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will build a Java project with Gradle then perform an automated release
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
# https://github.com/marketplace/actions/action-for-semantic-release

name: CI
on: [ push, pull_request ]
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Build with Gradle
run: ./gradlew build
- uses: actions/upload-artifact@v2
with:
name: build-directory
path: build
- uses: codecov/codecov-action@v1
with:
files: build/reports/jacoco/test/jacocoTestReport.xml
verbose: true
release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to Sonatype
if: steps.semantic.outputs.new_release_published == 'true'
env:
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.SONATYPE_USERNAME }}
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.SONATYPE_PASSWORD }}
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
run: |
./gradlew publishToSonatype closeAndReleaseStagingRepository
25 changes: 0 additions & 25 deletions .github/workflows/macos-build.yml

This file was deleted.

16 changes: 16 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Nightly Build
on:
schedule:
- cron: '0 2 * * *' # run at 2 AM UTC
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Build with Gradle
run: ./gradlew build
9 changes: 9 additions & 0 deletions .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# See:
# https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#configuration
# https://github.com/marketplace/actions/action-for-semantic-release

branches: ["master", "main"]
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/github"
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![semantic-release](https://img.shields.io/badge/semantic-release-e10079.svg?logo=semantic-release)](https://github.com/semantic-release/semantic-release)

# lsd-distributed-generator-ui
![GitHub](https://img.shields.io/github/license/lsd-consulting/lsd-distributed-generator-ui)
[![Build](https://github.com/lsd-consulting/lsd-distributed-generator-ui/actions/workflows/macos-build.yml/badge.svg)](https://github.com/lsd-consulting/lsd-distributed-generator-ui/actions/workflows/macos-build.yml)
Expand Down
17 changes: 13 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@ plugins {
java
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("pl.allegro.tech.build.axion-release") version "1.13.4"
id("com.palantir.git-version") version "0.12.3"
}

nexusPublishing.repositories.sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}

tasks.create("installGitHooks") {
shouldRunAfter("clean")
println("-- Configuring git to use .githooks --")
project.exec {
commandLine("git", "config", "core.hooksPath", ".githooks")
}
}

// TODO Not sure all this is needed here or only in the file one level below
val gitVersion: groovy.lang.Closure<String> by extra
version = gitVersion().replace(Regex("^v"), "")
group = "io.github.lsd-consulting"
rootProject.version = scmVersion.version
println("Build Version = ${project.version}")

configurations {
compileOnly {
Expand All @@ -28,7 +37,7 @@ configurations {
}

allprojects {
group = "io.github.lsd-consulting"
group = rootProject.group
version = rootProject.version

apply(plugin = "io.spring.dependency-management")
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
8 changes: 8 additions & 0 deletions hooks.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

task installGitHooks() {
shouldRunAfter("clean")
println "-- Configuring git to use .githooks --"
project.exec {
commandLine('git', 'config', 'core.hooksPath', '.githooks')
}
}
11 changes: 0 additions & 11 deletions release.sh

This file was deleted.

16 changes: 13 additions & 3 deletions service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id("java-library")
id("signing")
id("jacoco")
id("pl.allegro.tech.build.axion-release")
id("com.palantir.git-version")
}

//////////////////////////
Expand Down Expand Up @@ -155,7 +155,8 @@ publishing {
create<MavenPublication>("mavenJava") {
groupId = "$group"
artifactId = "lsd-distributed-generator-ui"
version = scmVersion.version
version = rootProject.version.toString()


artifact(project.tasks.bootJar)

Expand Down Expand Up @@ -202,5 +203,14 @@ publishing {
}

signing {
sign(publishing.publications["mavenJava"])
project.findProperty("signingKey")?.let {
// Use in-memory ascii-armored keys
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(tasks["stuffZip"])
sign(publishing.publications["mavenJava"])
} ?: run {
sign(publishing.publications["mavenJava"])
}
}

0 comments on commit 029784e

Please sign in to comment.