Skip to content

feat(hackerrank): IBM HackerRank Assessment 2026 #7

feat(hackerrank): IBM HackerRank Assessment 2026

feat(hackerrank): IBM HackerRank Assessment 2026 #7

Workflow file for this run

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: CI
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed]
workflow_dispatch:
branches: [ 'main', 'develop', 'feature/**', 'hotfix/**', 'bugfix/**' ]
permissions:
contents: write
packages: write
statuses: write # To report GitHub Actions status checks
actions: write # Needed for detection of GitHub Actions environment.
id-token: write # Needed for provenance signing and ID.
pull-requests: write
jobs:
build:
name: Build with Maven
runs-on: ubuntu-latest
steps:
- name: Get PR event name
run: echo "The event type is ${{ github.event.action }}"
- name: Get branch name
run: echo "Branch name is ${{ github.head_ref }}"
- name: Checkout sources
uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: 21
distribution: 'temurin'
cache: maven
architecture: x64
- name: Build, Package and Test
run: mvn -B clean install
- name: Upload build reports
uses: actions/upload-artifact@v4
if: always()
with:
name: maven-build-reports
path: '**/target/reports/'
compression-level: 9
# - name: Generate PMD reports
# uses: pmd/pmd-github-action@v2
# id: pmd
# with:
# version: '7.16.0'
# sourcePath: 'src/main/java'
# rulesets: 'rulesets/java/quickstart.xml,ruleset.xml'
# analyzeModifiedFilesOnly: false
#
# - name: Fail build if there are violations
# if: steps.pmd.outputs.violations != 0
# run: exit 1
#
# - name: Upload SARIF file if there are no violations
# if: steps.pmd.outputs.violations == 0
# uses: github/codeql-action/upload-sarif@v3
# with:
# sarif_file: pmd-report.sarif
coverage:
name: JaCoCo Code Coverage Gate
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout sources
uses: actions/checkout@v5
with:
clean: 'true'
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '21'
cache: maven
architecture: x64
- name: Generate Coverage Report
run: |
mvn -B clean install test --file pom.xml
- name: Add coverage to PR
id: jacoco
uses: madrapps/jacoco-report@v1.7.2
with:
paths: ${{ github.workspace }}/target/site/jacoco/jacoco.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 75
min-coverage-changed-files: 70
title: Code Coverage
comment-type: 'pr_comment'
- name: Save Coverage To Environment Variable
run: |
echo "TOTAL_COVERAGE=${{ steps.jacoco.outputs.coverage-overall }}" >> $GITHUB_ENV
echo "CHANGED_FILES_COVERAGE=${{ steps.jacoco.outputs.coverage-changed-files }}" >> $GITHUB_ENV
- name: Print & Check Coverage Info
run: |
import os
import sys
total_coverage = os.environ["TOTAL_COVERAGE"]
changed_files_coverage = os.environ["CHANGED_FILES_COVERAGE"]
print(f"Total Coverage: {total_coverage}")
print(f"Changed Files Coverage: {changed_files_coverage}")
if float(total_coverage) < 75 or float(changed_files_coverage) < 70:
print("Insufficient Coverage!")
sys.exit(-1) # Cause Status Check Failure due to noncompliant coverage
sys.exit(0)
shell: python