From fe3b704b6a3596211700db9e7582044250d93f40 Mon Sep 17 00:00:00 2001 From: ariwk Date: Tue, 29 Oct 2024 15:50:46 +0100 Subject: [PATCH] ci: add sonar code coverage --- .github/workflows/maven-build.yml | 60 ++++++++++++++++++------------- .github/workflows/pr.yml | 2 +- CONTRIBUTING.md | 4 +-- pom.xml | 20 +++++++++-- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml index 10b1c2a..9c71792 100644 --- a/.github/workflows/maven-build.yml +++ b/.github/workflows/maven-build.yml @@ -3,6 +3,9 @@ name: maven-build on: push: branches: ['**/**'] + pull_request: + branches: [main] + types: [opened, synchronize, reopened, ready_for_review] jobs: build: runs-on: ubuntu-latest @@ -11,24 +14,33 @@ jobs: COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN }} COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE }} GITHUB_TOKEN: ${{ github.token }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} steps: - - name: Checkout + - name: 📄 Checkout the repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 + with: + fetch-depth: 0 - name: Set up JDK and Maven uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4 with: distribution: adopt java-version: 17 gpg-private-key: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PRIVATE_KEY }} - - name: Prepare Cache + - name: 📝 Get the project version + id: project_version + run: echo "project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT + - name: 📝 Store cache key + id: cache_key + run: echo "cache_key=${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }}-${{ github.sha }}" >> $GITHUB_OUTPUT + - name: 💾 Prepare cache using cache key id: prepare-cache uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4 with: path: | /home/runner/.m2 /home/runner/work - key: ${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }} - - name: Generate settings.xml + key: ${{ steps.cache_key.outputs.cache_key }} + - name: 🔘 Generate settings.xml for Maven uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22 with: servers: > @@ -58,21 +70,19 @@ jobs: } } ] - - name: Print settings.xml + - name: 🔘 Print settings.xml run: cat /home/runner/.m2/settings.xml - - name: Build with Maven - run: mvn --batch-mode clean package - - name: Store project version - id: project_version - run: echo "project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_OUTPUT - - name: Store cache key - id: cache_key - run: echo "cache_key=${{ runner.os }}-mvn-${{ hashFiles('**/pom.xml') }}" >> $GITHUB_OUTPUT + - name: 📦 Build with Maven for Pushes + if: github.event_name == 'push' + run: mvn --batch-mode clean package sonar:sonar -Dsonar.branch.name=${{ github.head_ref }} + - name: 📦 Build with Maven for PRs + if: github.event_name == 'pull_request' + run: mvn --batch-mode clean package sonar:sonar -Dsonar.pullrequest.base=${{ github.base_ref }} -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.key=${{ github.event.pull_request.number }} outputs: project_version: ${{ steps.project_version.outputs.project_version }} cache_key: ${{ steps.cache_key.outputs.cache_key }} - # deploy to Maven Central + # Deploy release to Maven Central deploy-maven-central: needs: build runs-on: ubuntu-latest @@ -82,13 +92,13 @@ jobs: COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_TOKEN }} COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PASSPHRASE }} steps: - - name: Set up JDK and Maven + - name: 🧱 Set up JDK and Maven uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4 with: distribution: adopt java-version: 17 gpg-private-key: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PRIVATE_KEY }} - - name: Restore Cache + - name: 💾 Restore cache using cache key id: restore-cache uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4 with: @@ -96,10 +106,10 @@ jobs: /home/runner/.m2 /home/runner/work key: ${{ needs.build.outputs.cache_key }} - - name: Publish to Maven Central + - name: 📦 Deploy artifacts to Maven Central run: mvn --batch-mode -Dmaven.test.skip=true deploy -P gpg-sign -P nexus-staging - # deploy to GitHub Packages + # Deploy release to GitHub Packages deploy-github-packages: needs: build runs-on: ubuntu-latest @@ -110,21 +120,21 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} steps: - - name: Set up JDK and Maven + - name: 🧱 Set up JDK and Maven uses: actions/setup-java@8df1039502a15bceb9433410b1a100fbe190c53b # v4 with: distribution: adopt java-version: 17 - - name: Cache - id: cache + - name: 💾 Restore cache using cache key + id: restore-cache uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4 with: path: | /home/runner/.m2 /home/runner/work key: ${{ needs.build.outputs.cache_key }} - - name: Publish to GitHub Packages + - name: 📦 Deploy artifacts to GitHub Packages run: mvn --batch-mode -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dmaven.source.skip=true deploy -P deploy-github-packages - - name: Upload assets - run: cd ${{github.workspace}} && gh release upload v${{ needs.build.outputs.project_version }} target/*-${{ needs.build.outputs.project_version }}.jar - shell: bash + - name: 📦 Upload assets to GitHub Release + run: |- + gh release upload v${{ needs.build.outputs.project_version }} target/*-${{ needs.build.outputs.project_version }}.jar diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8fd1c40..841ba18 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5 with: - cache: pip # caching pip dependencies + python-version: 3.x - run: pip install commitizen - name: Check commit messages run: cz check --rev-range origin/${GITHUB_BASE_REF}.. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 47759ce..86174c7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -76,11 +76,11 @@ Before you submit your Pull Request (PR) consider the following guidelines: is necessary because release notes are automatically generated from these messages. ```shell - git commit -a -S + git commit -a --gpg-sign ``` Note: The optional commit `-a` command line option will automatically "add" and "rm" edited files. - Note: The command line option `-S` generates a signed commit, which is required to make a contribution (See [Developer Certificate of Origin](./LICENSES/DCO.txt)) + Note: The command line option `-S/--gpg-sign` generates a signed commit, which is required to make a contribution (See [Developer Certificate of Origin](./LICENSES/DCO.txt)) * Push your branch to GitHub: diff --git a/pom.xml b/pom.xml index 3bc7f1b..1d82a33 100644 --- a/pom.xml +++ b/pom.xml @@ -23,14 +23,14 @@ SBB Polarion Team polarion-opensource@sbb.ch SBB AG - http://www.sbb.ch + https://www.sbb.ch scm:git:git://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator.git scm:git:ssh://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator.git - http://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator/tree/main + https://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator/tree/main @@ -56,7 +56,21 @@ 3.3.1 3.5.1 + + 0.8.12 + SchweizerischeBundesbahnen_${project.artifactId} + schweizerischebundesbahnen + ${project.artifactId} + https://sonarcloud.io + jacoco + reuseReports + java + ${project.basedir}/target/site/jacoco/jacoco.xml + true + true + 1.7.0 + true @@ -109,7 +123,7 @@ ossrh https://oss.sonatype.org/ - true + ${nexus-staging-maven-plugin.autoReleaseAfterClose}