|
| 1 | +name: CI/CD Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + tags: [ 'v*' ] |
| 7 | + pull_request: |
| 8 | + branches: [ main ] |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + actions: read |
| 13 | + checks: write |
| 14 | + security-events: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | +env: |
| 18 | + JAVA_VERSION: '17' |
| 19 | + MAVEN_OPTS: > |
| 20 | + -Dmaven.repo.local=.m2/repository |
| 21 | + -Xmx2048m |
| 22 | + -XX:+UseG1GC |
| 23 | + -Daether.connector.http.connectionMaxTtl=25 |
| 24 | + -Dmaven.artifact.threads=8 |
| 25 | +
|
| 26 | +concurrency: |
| 27 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 28 | + cancel-in-progress: true |
| 29 | + |
| 30 | +jobs: |
| 31 | + validate: |
| 32 | + name: Code Quality & Security |
| 33 | + runs-on: ubuntu-latest |
| 34 | + timeout-minutes: 20 |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Setup JDK |
| 43 | + uses: actions/setup-java@v4 |
| 44 | + with: |
| 45 | + java-version: ${{ env.JAVA_VERSION }} |
| 46 | + distribution: 'temurin' |
| 47 | + |
| 48 | + - name: Validate Project |
| 49 | + uses: nick-fields/retry@v3 |
| 50 | + with: |
| 51 | + timeout_minutes: 10 |
| 52 | + max_attempts: 2 |
| 53 | + retry_wait_seconds: 30 |
| 54 | + command: mvn clean validate compile -B --no-transfer-progress -DskipTests |
| 55 | + |
| 56 | + - name: Verify Dependencies |
| 57 | + run: | |
| 58 | + mvn dependency:analyze -B --no-transfer-progress -Pquality |
| 59 | + mvn dependency:tree -B --no-transfer-progress | tee dependency-tree.txt |
| 60 | +
|
| 61 | + - name: Code Style Check (Spotless) |
| 62 | + run: mvn spotless:check -B --no-transfer-progress |
| 63 | + |
| 64 | + - name: Security Analysis (SpotBugs) |
| 65 | + run: mvn spotbugs:check -B --no-transfer-progress |
| 66 | + |
| 67 | + - name: Upload Dependency Tree |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: dependency-analysis |
| 71 | + path: dependency-tree.txt |
| 72 | + retention-days: 7 |
| 73 | + |
| 74 | + test: |
| 75 | + name: Test Suite (Java ${{ matrix.java }}) |
| 76 | + runs-on: ubuntu-latest |
| 77 | + needs: validate |
| 78 | + timeout-minutes: 25 |
| 79 | + strategy: |
| 80 | + fail-fast: false |
| 81 | + matrix: |
| 82 | + java: [ 17, 21, 22 ] |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Setup JDK ${{ matrix.java }} |
| 89 | + uses: actions/setup-java@v4 |
| 90 | + with: |
| 91 | + java-version: ${{ matrix.java }} |
| 92 | + distribution: 'temurin' |
| 93 | + |
| 94 | + - name: Run Tests & Coverage Check |
| 95 | + uses: nick-fields/retry@v3 |
| 96 | + with: |
| 97 | + timeout_minutes: 20 |
| 98 | + max_attempts: 3 |
| 99 | + retry_wait_seconds: 30 |
| 100 | + command: mvn clean verify -B --no-transfer-progress -Djava.version=${{ matrix.java }} |
| 101 | + |
| 102 | + - name: List test report files |
| 103 | + if: always() && matrix.java == 17 |
| 104 | + run: | |
| 105 | + echo "Surefire reports:" |
| 106 | + ls -l target/surefire-reports || true |
| 107 | + echo "Failsafe reports:" |
| 108 | + ls -l target/failsafe-reports || true |
| 109 | + echo "JaCoCo reports:" |
| 110 | + ls -l target/site/jacoco* || true |
| 111 | +
|
| 112 | + - name: Upload coverage reports to Codecov |
| 113 | + if: matrix.java == 17 |
| 114 | + uses: codecov/codecov-action@v5 |
| 115 | + with: |
| 116 | + files: target/site/jacoco-merged/jacoco.xml,target/site/jacoco/jacoco.xml |
| 117 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 118 | + fail_ci_if_error: false |
| 119 | + |
| 120 | + - name: Upload Test Results |
| 121 | + uses: dorny/test-reporter@v1 |
| 122 | + if: always() && matrix.java == 17 |
| 123 | + with: |
| 124 | + name: Test Results (Java ${{ matrix.java }}) |
| 125 | + path: target/surefire-reports/TEST-*.xml,target/failsafe-reports/TEST-*.xml |
| 126 | + reporter: java-junit |
| 127 | + fail-on-error: false |
| 128 | + |
| 129 | + build: |
| 130 | + name: Build & Package |
| 131 | + runs-on: ubuntu-latest |
| 132 | + needs: [validate, test] |
| 133 | + timeout-minutes: 15 |
| 134 | + outputs: |
| 135 | + version: ${{ steps.version.outputs.version }} |
| 136 | + is-snapshot: ${{ steps.version.outputs.is-snapshot }} |
| 137 | + |
| 138 | + steps: |
| 139 | + - name: Checkout |
| 140 | + uses: actions/checkout@v4 |
| 141 | + |
| 142 | + - name: Setup JDK |
| 143 | + uses: actions/setup-java@v4 |
| 144 | + with: |
| 145 | + java-version: ${{ env.JAVA_VERSION }} |
| 146 | + distribution: 'temurin' |
| 147 | + |
| 148 | + - name: Extract Version |
| 149 | + id: version |
| 150 | + run: | |
| 151 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 152 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 153 | + echo "is-snapshot=$(echo $VERSION | grep -q SNAPSHOT && echo true || echo false)" >> $GITHUB_OUTPUT |
| 154 | +
|
| 155 | + - name: Build Package |
| 156 | + uses: nick-fields/retry@v3 |
| 157 | + with: |
| 158 | + timeout_minutes: 10 |
| 159 | + max_attempts: 2 |
| 160 | + retry_wait_seconds: 30 |
| 161 | + command: mvn clean package -B --no-transfer-progress -DskipTests |
| 162 | + |
| 163 | + - name: Generate Documentation |
| 164 | + run: mvn javadoc:javadoc -B --no-transfer-progress |
| 165 | + |
| 166 | + - name: Verify JAR Structure |
| 167 | + run: | |
| 168 | + jar -tf target/logdash-*.jar | head -20 |
| 169 | + echo "JAR size: $(du -h target/logdash-*.jar | cut -f1)" |
| 170 | +
|
| 171 | + - name: Upload Build Artifacts |
| 172 | + uses: actions/upload-artifact@v4 |
| 173 | + with: |
| 174 | + name: build-artifacts-${{ steps.version.outputs.version }} |
| 175 | + path: | |
| 176 | + target/*-${{ steps.version.outputs.version }}.jar |
| 177 | + !target/*-tests.jar |
| 178 | + !target/original-*.jar |
| 179 | + target/site/apidocs/** |
| 180 | + retention-days: ${{ steps.version.outputs.is-snapshot == 'true' && 7 || 90 }} |
| 181 | + |
| 182 | + security-scan: |
| 183 | + name: Security Scanning |
| 184 | + runs-on: ubuntu-latest |
| 185 | + needs: validate |
| 186 | + timeout-minutes: 15 |
| 187 | + if: > |
| 188 | + (github.event_name == 'push' && github.ref == 'refs/heads/main') || |
| 189 | + (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'security-scan')) || |
| 190 | + startsWith(github.ref, 'refs/tags/v') |
| 191 | +
|
| 192 | + steps: |
| 193 | + - name: Checkout |
| 194 | + uses: actions/checkout@v4 |
| 195 | + |
| 196 | + - name: Setup JDK |
| 197 | + uses: actions/setup-java@v4 |
| 198 | + with: |
| 199 | + java-version: ${{ env.JAVA_VERSION }} |
| 200 | + distribution: 'temurin' |
| 201 | + |
| 202 | + - name: Build for Security Scan |
| 203 | + run: mvn clean compile -B --no-transfer-progress -DskipTests |
| 204 | + |
| 205 | + - name: Run Trivy Scan |
| 206 | + uses: aquasecurity/trivy-action@master |
| 207 | + with: |
| 208 | + scan-type: 'fs' |
| 209 | + scan-ref: '.' |
| 210 | + format: 'sarif' |
| 211 | + output: 'trivy-results.sarif' |
| 212 | + |
| 213 | + - name: Upload SARIF |
| 214 | + uses: github/codeql-action/upload-sarif@v3 |
| 215 | + if: always() |
| 216 | + with: |
| 217 | + sarif_file: 'trivy-results.sarif' |
| 218 | + continue-on-error: true |
| 219 | + |
| 220 | + release: |
| 221 | + name: Release to GitHub Packages |
| 222 | + runs-on: ubuntu-latest |
| 223 | + needs: [build, security-scan] |
| 224 | + timeout-minutes: 15 |
| 225 | + if: startsWith(github.ref, 'refs/tags/v') |
| 226 | + |
| 227 | + permissions: |
| 228 | + contents: write |
| 229 | + packages: write |
| 230 | + |
| 231 | + steps: |
| 232 | + - name: Checkout |
| 233 | + uses: actions/checkout@v4 |
| 234 | + |
| 235 | + - name: Setup JDK |
| 236 | + uses: actions/setup-java@v4 |
| 237 | + with: |
| 238 | + java-version: ${{ env.JAVA_VERSION }} |
| 239 | + distribution: 'temurin' |
| 240 | + |
| 241 | + - name: Configure Maven Settings |
| 242 | + uses: whelk-io/maven-settings-xml-action@v22 |
| 243 | + with: |
| 244 | + servers: | |
| 245 | + [ |
| 246 | + { |
| 247 | + "id": "github", |
| 248 | + "username": "${env.GITHUB_ACTOR}", |
| 249 | + "password": "${env.GITHUB_TOKEN}" |
| 250 | + } |
| 251 | + ] |
| 252 | +
|
| 253 | + - name: Extract Version Info |
| 254 | + id: version |
| 255 | + run: | |
| 256 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 257 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 258 | + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 259 | + |
| 260 | + # Validate version matches tag |
| 261 | + if [[ "v$VERSION" != "${GITHUB_REF#refs/tags/}" ]]; then |
| 262 | + echo "::error::Version mismatch: POM version ($VERSION) doesn't match tag (${GITHUB_REF#refs/tags/})" |
| 263 | + exit 1 |
| 264 | + fi |
| 265 | +
|
| 266 | + - name: Build and Deploy to GitHub Packages |
| 267 | + run: | |
| 268 | + mvn clean deploy -B --no-transfer-progress \ |
| 269 | + -Prelease \ |
| 270 | + -DperformRelease=true \ |
| 271 | + -DskipTests=true |
| 272 | + env: |
| 273 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 274 | + |
| 275 | + - name: Download Build Artifacts |
| 276 | + uses: actions/download-artifact@v4 |
| 277 | + with: |
| 278 | + pattern: build-artifacts-* |
| 279 | + merge-multiple: true |
| 280 | + |
| 281 | + - name: Prepare Release Assets |
| 282 | + run: | |
| 283 | + mkdir -p release-assets |
| 284 | + cp target/logdash-${{ steps.version.outputs.version }}.jar release-assets/ |
| 285 | + cp target/logdash-${{ steps.version.outputs.version }}-sources.jar release-assets/ |
| 286 | + cp target/logdash-${{ steps.version.outputs.version }}-javadoc.jar release-assets/ |
| 287 | + |
| 288 | + # Create checksums |
| 289 | + cd release-assets |
| 290 | + sha256sum *.jar > checksums.sha256 |
| 291 | + cd .. |
| 292 | +
|
| 293 | + - name: Create GitHub Release |
| 294 | + uses: softprops/action-gh-release@v2 |
| 295 | + with: |
| 296 | + files: | |
| 297 | + release-assets/*.jar |
| 298 | + release-assets/checksums.sha256 |
| 299 | + generate_release_notes: true |
| 300 | + draft: false |
| 301 | + body: | |
| 302 | + # 🚀 Logdash Java SDK |
| 303 | + |
| 304 | + Official Java SDK for [Logdash.io](https://logdash.io) – Zero-configuration observability for developers. |
| 305 | + |
| 306 | + ## ✨ Features |
| 307 | + |
| 308 | + - **Zero Configuration**: Start logging and tracking metrics in seconds |
| 309 | + - **Real-time Dashboard**: Cloud-hosted interface with live data updates |
| 310 | + - **Structured Logging**: Multiple log levels with rich context support |
| 311 | + - **Custom Metrics**: Track counters, gauges, and business metrics |
| 312 | + - **Async & Fast**: Non-blocking, production-ready, framework-agnostic |
| 313 | + - **Java 17+ Compatible**: Works with Java 17, 21, 22+ |
| 314 | + |
| 315 | + ## 📦 Installation |
| 316 | + |
| 317 | + **Maven** |
| 318 | + ```xml |
| 319 | + <dependency> |
| 320 | + <groupId>io.logdash</groupId> |
| 321 | + <artifactId>logdash</artifactId> |
| 322 | + <version>${{ steps.version.outputs.version }}</version> |
| 323 | + </dependency> |
| 324 | + ``` |
| 325 | + |
| 326 | + **Gradle** |
| 327 | + ```gradle |
| 328 | + implementation 'io.logdash:logdash:${{ steps.version.outputs.version }}' |
| 329 | + ``` |
| 330 | + |
| 331 | + **Direct JAR Download:** |
| 332 | + [Download from GitHub Releases](https://github.com/logdash-io/java-sdk/releases) |
| 333 | + |
| 334 | + ## 🏁 Quick Start |
| 335 | + |
| 336 | + ```java |
| 337 | + var logdash = Logdash.builder() |
| 338 | + .apiKey("your-api-key") |
| 339 | + .build(); |
| 340 | + |
| 341 | + logdash.logger().info("Application started"); |
| 342 | + logdash.metrics().mutate("app_starts", 1); |
| 343 | + ``` |
| 344 | + |
| 345 | + ## ⚙️ Requirements |
| 346 | + |
| 347 | + - Java 17 or higher |
| 348 | + - Internet connection |
| 349 | + - Logdash API key ([get yours](https://logdash.io)) |
| 350 | + |
| 351 | + ## 📖 Documentation & Support |
| 352 | + |
| 353 | + - [Full Documentation](https://logdash.io/docs) |
| 354 | + - [Live Demo](https://logdash.io/demo-dashboard) |
| 355 | + - [GitHub Issues](https://github.com/logdash-io/java-sdk/issues) |
| 356 | + - [Discord Community](https://discord.gg/naftPW4Hxe) |
| 357 | + - [Email Support](mailto:contact@logdash.io) |
| 358 | + |
| 359 | + --- |
| 360 | + |
| 361 | + _See below for full release notes and change log._ |
| 362 | + |
| 363 | + - name: Notify Deployment Success |
| 364 | + run: | |
| 365 | + echo "✅ Successfully deployed logdash:${{ steps.version.outputs.version }} to GitHub Packages" |
| 366 | + echo "📦 Available at: https://github.com/logdash-io/java-sdk/packages" |
| 367 | +
|
| 368 | + notification: |
| 369 | + name: Notification |
| 370 | + runs-on: ubuntu-latest |
| 371 | + needs: [validate, test, build, security-scan] |
| 372 | + if: always() && github.ref == 'refs/heads/main' |
| 373 | + |
| 374 | + steps: |
| 375 | + - name: Check Workflow Status |
| 376 | + run: | |
| 377 | + if [[ "${{ needs.validate.result }}" == "failure" || "${{ needs.test.result }}" == "failure" || "${{ needs.build.result }}" == "failure" ]]; then |
| 378 | + echo "❌ Workflow failed on main branch" |
| 379 | + echo "::error::Critical job failed on main branch" |
| 380 | + else |
| 381 | + echo "✅ Workflow completed successfully" |
| 382 | + fi |
0 commit comments