build(conditions): Use github app only with main branch #106
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a Java project with Gradle | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle | |
name: Java CI with Gradle | |
on: | |
push: | |
branches: | |
- master | |
- feature/* | |
- fix/* | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} | |
permissions: | |
contents: write | |
issues: write | |
pull-requests: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate a token | |
id: generate_token | |
if: github.ref == 'refs/heads/master' | |
uses: tibdex/github-app-token@v2 | |
with: | |
app_id: ${{ secrets.APP_ID_ADMIN_GITHUB }} | |
private_key: ${{ secrets.APP_PRIVATE_KEY_ADMIN_GITHUB }} | |
- uses: actions/checkout@v4 | |
if: github.ref == 'refs/heads/master' | |
with: | |
token: ${{ steps.generate_token.outputs.token }} | |
- uses: actions/checkout@v4 | |
if: github.ref != 'refs/heads/master' | |
- name: Verify Conventional Commits | |
uses: amannn/action-semantic-pull-request@v5 | |
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up NodeJS | |
if: github.ref == 'refs/heads/master' | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: '.nvmrc' | |
- name: Set up Semantic Release | |
if: github.ref == 'refs/heads/master' | |
run: npm -g install @semantic-release/git [email protected] | |
- name: Semantic Release | |
if: github.ref == 'refs/heads/master' | |
run: npx [email protected] | |
env: | |
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew clean build -x test -x check | |
# - name: Scan generated project dependencies | |
# run: ./gradlew dependencyCheckAggregate | |
- name: Execute jacocoTestReport | |
run: ./gradlew test generateMergedReport | |
- name: copy the reportTest to codeCoverage | |
run: cp build/reports/jacoco/generateMergedReport/generateMergedReport.xml jacoco.xml || echo "Code coverage failed" | |
- name: Push codeCoverage to Codecov | |
if: endsWith(github.REF, '/master') == true | |
run: bash <(curl -s https://codecov.io/bash) | |
- name: Run sonar | |
if: endsWith(github.REF, '/master') == true | |
run: ./gradlew sonar --stacktrace | |
-Dsonar.login=${{ secrets.SONAR_TOKEN }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |