From 760a1a4cf65963c1888fdebd062ce14104da0ea4 Mon Sep 17 00:00:00 2001 From: Guillermo Calvo Date: Tue, 13 Feb 2024 20:23:18 +0100 Subject: [PATCH] Refactor build and release pipelines --- .github/workflows/build.yml | 45 +++++++++++++++++++---------------- .github/workflows/release.yml | 11 +++++---- build.gradle | 7 ------ 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3f86ff5..afd93dd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ on: jobs: build: - name: Build on JDK${{ matrix.jdk }} + name: Build ${{ github.ref_name }} on JDK${{ matrix.jdk }} runs-on: ubuntu-latest strategy: @@ -27,14 +27,14 @@ jobs: # SHALLOW CLONE # ================================ - name: Shallow clone - if: ${{ matrix.jdk != 21 }} + if: ${{ matrix.jdk != 21 || github.event_name != 'push' }} uses: actions/checkout@v4 # ================================ # CHECKOUT # ================================ - name: Checkout git branch - if: ${{ matrix.jdk == 21 }} + if: ${{ matrix.jdk == 21 && github.event_name == 'push' }} uses: actions/checkout@v4 with: # Fetch all history for all tags and branches (recommended by SonarQube) @@ -50,25 +50,16 @@ jobs: java-package: jdk java-version: ${{ matrix.jdk }} - # ================================ - # CACHE SONARCLOUD PACKAGES - # ================================ - - name: Cache SonarCloud packages - uses: actions/cache@v4 - with: - key: ${{ runner.os }}-sonar - path: | - ~/.sonar/cache - restore-keys: | - ${{ runner.os }}-sonar - # ================================ # SETUP GRADLE # ================================ - name: Setup Gradle uses: gradle/actions/setup-gradle@v3 with: - cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} + build-scan-publish: true + build-scan-terms-of-service-url: https://gradle.com/terms-of-service + build-scan-terms-of-service-agree: yes + cache-read-only: ${{ github.event_name != 'push' }} # ================================ # BUILD @@ -76,7 +67,7 @@ jobs: - name: Build uses: gradle/actions/setup-gradle@v3 with: - arguments: build -x check --info --scan + arguments: build -x check --info # ================================ # CHECK @@ -84,23 +75,37 @@ jobs: - name: Check uses: gradle/actions/setup-gradle@v3 with: - arguments: check --info --scan + arguments: check --info # ================================ # COMPATIBILITY REPORT # ================================ - name: Compatibility report + if: ${{ matrix.jdk == 21 }} run: cat ./api-compatibility/build/report.txt >> $GITHUB_STEP_SUMMARY + # ================================ + # CACHE SONARCLOUD PACKAGES + # ================================ + - name: Cache SonarCloud packages + if: ${{ matrix.jdk == 21 && github.event_name == 'push' }} + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-sonar + path: | + ~/.sonar/cache + restore-keys: | + ${{ runner.os }}-sonar + # ================================ # ANALYZE # ================================ - name: Analyze - if: ${{ matrix.jdk == 21 }} + if: ${{ matrix.jdk == 21 && github.event_name == 'push' }} env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: https://sonarcloud.io SONAR_ORGANIZATION: leakyabstractions uses: gradle/actions/setup-gradle@v3 with: - arguments: sonarqube --info --scan + arguments: sonarqube --info diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45790a3..529569d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,15 +9,15 @@ on: jobs: build: - name: Publish + name: Publish release version ${{ github.ref_name }} runs-on: ubuntu-latest steps: # ================================ - # CHECKOUT + # SHALLOW CLONE # ================================ - - name: Checkout git tag + - name: Shallow clone uses: actions/checkout@v4 # ================================ @@ -50,4 +50,7 @@ jobs: ORG_GRADLE_PROJECT_sonatypeStagingProfileId: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} uses: gradle/actions/setup-gradle@v3 with: - arguments: publish -Prelease --info --scan + build-scan-publish: true + build-scan-terms-of-service-url: https://gradle.com/terms-of-service + build-scan-terms-of-service-agree: yes + arguments: publish -Prelease --info diff --git a/build.gradle b/build.gradle index c912927..e0654f9 100644 --- a/build.gradle +++ b/build.gradle @@ -20,13 +20,6 @@ if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePass } } -if (hasProperty('buildScan')) { - buildScan { - termsOfServiceUrl = 'https://gradle.com/terms-of-service' - termsOfServiceAgree = 'yes' - } -} - /** * Print project property by key * - Usage: `./gradlew -q printProperty -Pkey=description`