Skip to content

Update commonslang.yml #10

Update commonslang.yml

Update commonslang.yml #10

Workflow file for this run

name: Build and Test
on:
push:
branches:
- github_action_java
pull_request:
branches:
- github_action_java
jobs:
build:
name: Build and Test
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository code
- name: Checkout Code
uses: actions/checkout@v3
# Step 2: Set up Java environment
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin' # Use Eclipse Temurin JDK
java-version: '17' # Update this version as per project requirements
# Step 3: Cache Maven dependencies
- name: Cache Maven dependencies
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# Step 4: Run Maven build
- name: Build with Maven
run: |
cd sample_source_code/JAVA/commons-lang
mvn clean install jacoco:report --batch-mode
# Step 5: Download and un-tar the BrowserStack CQ Scanner
- name: Download and Unpack BrowserStack CQ Scanner
run: |
curl https://v1.embold.io/nfs/CLI/browserstack-codequality-scanner.tar.gz -o browserstack-codequality-scanner-archive.tar.gz
tar xvf browserstack-codequality-scanner-archive.tar.gz
# Step 6: Run the BrowserStack CQ Scanner
# - name: Run Static Code Analysis
# env:
# EMBOLD_TOKEN: ${{ secrets.EMBOLD_TOKEN_DEMO_INST }}
# run: |
# ./browserstack-codequality-scanner/bin/embold-scanner analyse \
# -u https://demo.embold.io \
# -t $EMBOLD_TOKEN \
# -r e602c21b7e4d91f90b2914504eaeb8ae \
# -c sample_source_code/JAVA/commons-lang/repository-configuration.json
- name: Check quality gate status
env:
EMBOLD_TOKEN: ${{ secrets.EMBOLD_TOKEN_DEMO_INST }}
run: |
# Wait for scan end or error in a loop
scanStatus='PROCESSING'
while [ "$scanStatus" != 'SUCCESS' ] && [ "$scanStatus" != 'FAIL' ]; do
sleep 5
# Call the scan status API
response=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" --location --request GET "https://demo.embold.io/api/v1/repositories/e602c21b7e4d91f90b2914504eaeb8ae/scans/$scanId/status" --header "Authorization:Bearer $(EMBOLD_TOKEN)")
HTTP_BODY=$(echo "$response" | sed -e 's/HTTPSTATUS\:.*//g')
HTTP_STATUS=$(echo "$response" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')
if [ "$HTTP_STATUS" != 200 ] && [ "$HTTP_STATUS" != 204 ]; then
echo 'Error while running scan'
echo "$HTTP_BODY" | jq -r '.error.message'
exit 1
fi
scanStatus=$(echo "$HTTP_BODY" | jq -r '.scanStatus')
currentStep=$(echo "$HTTP_BODY" | jq -r '.currentStep')
echo "Current status: ""$scanStatus" : "$currentStep"
done
echo "Scan completed successfully"
# Check the quality gate
response=$(curl --silent --location --request GET "https://demo.embold.io/api/v1/repositories/e602c21b7e4d91f90b2914504eaeb8ae/qualitygateprofiles/status" --header "Authorization:Bearer $(EMBOLD_TOKEN)")
if [ "$response" != 'passed' ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
printf "Embold Quality gate ${RED}FAILED${NC}\n"
exit 1
fi
printf "Embold Quality gate ${GREEN}PASSED${NC}\n"