Skip to content

Refactor/some improvements #289

Refactor/some improvements

Refactor/some improvements #289

Workflow file for this run

name: build-release
on:
push:
branches: [ main ]
tags: [ 'v*' ]
paths-ignore:
- '.github/ISSUE_TEMPLATE/**'
- '.github/*.yml'
- '*.md'
- 'LICENSE'
pull_request:
types: [ opened, synchronize, reopened, closed ]
branches: [ main ]
env:
ENABLE_TEST: true
ENABLE_SONAR: true
ENABLE_GH_MAVEN: false
JAVA_DIST: 'temurin'
JAVA_VERSION: '17'
jobs:
context:
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.context.outputs.branch }}
shouldBuild: ${{ steps.context.outputs.decision_build }}
shouldPublish: ${{ steps.context.outputs.decision_publish }}
isRelease: ${{ steps.context.outputs.isTag }}
version: ${{ steps.context.outputs.version }}
commitId: ${{ steps.context.outputs.shortCommitId }}
semanticVersion: ${{ steps.dynamic_prop.outputs.semanticVersion }}
steps:
- uses: actions/[email protected]
with:
token: ${{ secrets.BEEIO_CI_TOKEN }}
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
with:
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
git_push_gpgsign: false
gpg_private_key: ${{ secrets.OSS_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OSS_GPG_PASSPHARSE }}
- name: Project context
id: context
uses: zero88/[email protected]
with:
mustSign: true
nextVerMode: PATCH
- name: Query dynamic properties
id: dynamic_prop
shell: bash
run: |
[[ "${{ steps.context.outputs.isTag }}" == "true" ]] && sv="" || sv=$(grep semanticVersion gradle.properties | cut -d'=' -f2)
echo semanticVersion=$sv >> $GITHUB_OUTPUT
build:
runs-on: ubuntu-latest
needs: context
if: needs.context.outputs.shouldBuild == 'true'
steps:
- uses: actions/[email protected]
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
if: needs.context.outputs.shouldPublish == 'true'
with:
git_user_signingkey: true
gpg_private_key: ${{ secrets.CI_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.CI_GPG_PASSPHARSE }}
- name: Set up JDK
uses: actions/[email protected]
with:
distribution: ${{ env.JAVA_DIST }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
- name: Build
run: |
./gradlew clean build -x test \
-Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-PbuildBy="GitHub Action" -PbuildHash=${{ needs.context.outputs.commitId }}
- name: Publish Sonatype OSSRH
if: needs.context.outputs.shouldPublish == 'true' && needs.context.outputs.isRelease != 'true'
run: |
args=( -Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-Pnexus.username=${{ secrets.OSS_NEXUS_USER }} \
-Pnexus.password=${{ secrets.OSS_NEXUS_TOKEN }} )
./gradlew publish "${args[@]}"
analysis:
runs-on: ubuntu-latest
needs: context
if: needs.context.outputs.shouldBuild == 'true'
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/[email protected]
with:
distribution: ${{ env.JAVA_DIST }}
java-version: ${{ env.JAVA_VERSION }}
cache: 'gradle'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar-qwe
restore-keys: ${{ runner.os }}-sonar-qwe
- name: Generate jOOQ
run: ./generateJooq.sh
- name: Test
if: env.ENABLE_TEST == 'true'
run: ./gradlew test jacocoTestReport -PjacocoHtml=false
- name: SonarQube
if: needs.context.outputs.shouldPublish == 'true' && env.ENABLE_SONAR == 'true'
run: |
./gradlew sonarqube --info -x test \
-Dsonar.branch.name=${{ needs.context.outputs.branch }} \
-Dorg.gradle.jvmargs="-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.OSS_SONARQUBE_TOKEN }}
release:
runs-on: ubuntu-latest
needs: [ build, context ]
if: needs.context.outputs.isRelease == 'true'
steps:
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.context.outputs.branch }}
release_name: Release ${{ needs.context.outputs.branch }}
draft: false
prerelease: false
promote:
name: Promote Sonatype OSSRH
runs-on: ubuntu-latest
needs: [ build, context ]
if: needs.context.outputs.isRelease == 'true'
steps:
- uses: actions/[email protected]
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
git_user_signingkey: true
gpg_private_key: ${{ secrets.OSS_GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.OSS_GPG_PASSPHARSE }}
- name: Publish Sonatype OSSRH
run: |
args=( -Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-PbuildBy="GitHub Action" -PbuildHash=${{ needs.context.outputs.commitId }} \
-Psigning.gnupg.homeDir=/home/runner/.gnupg \
-Psigning.gnupg.keyName=${{ steps.import_gpg.outputs.keyid }} \
-Psigning.gnupg.passphrase=${{ secrets.OSS_GPG_PASSPHARSE }} \
-Pnexus.username=${{ secrets.OSS_NEXUS_USER }} \
-Pnexus.password=${{ secrets.OSS_NEXUS_TOKEN }} )
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository -Prelease "${args[@]}"
- name: Publish GitHub Package
if: env.ENABLE_GH_MAVEN == 'true'
run: |
args=( -Pversion=${{ needs.context.outputs.version }} \
-PsemanticVersion=${{ needs.context.outputs.semanticVersion }} \
-PbuildBy="GitHub Action" -PbuildHash=${{ needs.context.outputs.commitId }} \
-Psigning.gnupg.homeDir=/home/runner/.gnupg \
-Psigning.gnupg.keyName=${{ steps.import_gpg.outputs.keyid }} \
-Psigning.gnupg.passphrase=${{ secrets.OSS_GPG_PASSPHARSE }} \
-Pnexus.username=${{ github.repository_owner }} \
-Pnexus.password=${{ secrets.BEEIO_CI_TOKEN }} )
args+=( -Pgithub )
./gradlew publishMavenPublicationToMavenRepository -Prelease "${args[@]}"