diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..fca139e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,25 @@ +name: Build + +on: + pull_request: + branches: [ main, master ] + +jobs: + build: + runs-on: ubuntu-latest + environment: snapshot + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: 'gradle' + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + cache-read-only: false + gradle-home-cache-cleanup: true + - name: Build + run: ./gradlew build \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..da07d48 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,64 @@ +name: Publish + +on: + push: + branches: [ main, master ] + +jobs: + publish: + runs-on: ubuntu-latest + environment: production + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: '8' + distribution: 'temurin' + cache: 'gradle' + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + - name: Set release version + run: | + # Remove -SNAPSHOT from version + sed -i 's/\(version "[0-9.]*\)-SNAPSHOT"/\1"/' build.gradle + - name: Publish package + env: + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + run: | + ./gradlew build uploadArchives + - name: Bump version + id: bump_version + run: | + # Get current version without SNAPSHOT + CURRENT_VERSION=$(grep "version" build.gradle | sed 's/version "\(.*\)"/\1/') + + # Split into parts + IFS='.' read -ra VERSION_PARTS <<< "$CURRENT_VERSION" + + # Increment patch version + NEXT_PATCH=$((VERSION_PARTS[2] + 1)) + + # Create new version + NEXT_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$NEXT_PATCH-SNAPSHOT" + + # Update build.gradle + sed -i "s/version \".*\"/version \"$NEXT_VERSION\"/" build.gradle + + # Make the new version available to other steps + echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT + - name: Commit version bump + env: + NEXT_VERSION: ${{ steps.bump_version.outputs.next_version }} + BRANCH_NAME: github_actions + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add --all + git commit -m "Prepare version $NEXT_VERSION for development [skip ci]" + git pull --rebase origin $BRANCH_NAME + git push origin HEAD:$BRANCH_NAME \ No newline at end of file diff --git a/.gitignore b/.gitignore index b75596a..71ffd03 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ .idea/ out/ build/ -.DS_Store \ No newline at end of file +.DS_Store +secring.gpg +.vscode \ No newline at end of file diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..3fbb92b --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +java temurin-8.0.392+8 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 24a6ec7..b73439b 100644 --- a/build.gradle +++ b/build.gradle @@ -29,25 +29,51 @@ task sourcesJar(type: Jar) { from sourceSets.main.allSource } +test { + testLogging { + events "passed", "skipped", "failed" + exceptionFormat "full" + showStandardStreams = true + } +} + artifacts { archives jar, javadocJar, sourcesJar } +def getSonatypeUsername() { + return System.getenv('SONATYPE_USERNAME') +} + +def getSonatypePassword() { + return System.getenv('SONATYPE_PASSWORD') +} + +def hasCredentials() { + def result = getSonatypeUsername() != null && getSonatypePassword() != null + if (!result) { + println "Cannot publish package since Sonatype credentials are not set. Please set SONATYPE_USERNAME and SONATYPE_PASSWORD environment variables." + } + return result +} + signing { + required { gradle.taskGraph.hasTask("uploadArchives") } + useInMemoryPgpKeys(System.getenv('SIGNING_KEY'), System.getenv('SIGNING_PASSWORD')) sign configurations.archives } uploadArchives { repositories { mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + beforeDeployment { deployment -> signing.signPom(deployment) } repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { - authentication(userName: sonatypeUsername, password: sonatypePassword) + authentication(userName: getSonatypeUsername(), password: getSonatypePassword()) } snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { - authentication(userName: sonatypeUsername, password: sonatypePassword) + authentication(userName: getSonatypeUsername(), password: getSonatypePassword()) } pom.project { @@ -80,4 +106,5 @@ uploadArchives { } } } + onlyIf { hasCredentials() } }