Skip to content

Commit

Permalink
Update commonslang.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshVirkar authored Jan 6, 2025
1 parent 9b60d9a commit 7c5decf
Showing 1 changed file with 61 additions and 39 deletions.
100 changes: 61 additions & 39 deletions .github/workflows/commonslang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,70 @@ jobs:
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 7: Get the current time
- name: Get Current Time
id: get-time
run: echo "current_time=$(date --utc +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_ENV

# 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
- name: Run Static Code Analysis
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://')
./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
# Step 7: Fetch Scan Details
- name: Fetch Scan Details
id: fetch-scans
run: |
response=$(curl -s -X GET "https://https://demo.embold.io/api/v1/repositories/e602c21b7e4d91f90b2914504eaeb8ae/scans" -H "Authorization: Bearer ${{ secrets.EMBOLD_TOKEN_DEMO_INST }}")
echo "response=$response" >> $GITHUB_ENV
# Step 8: Find Latest Scan End Time
- name: Find Latest Scan
id: latest-scan
run: |
latest_scan=$(echo $response | jq -c '[.[] | select(.scanStatus == "SUCCESS" and .isCompleted == true)] | max_by(.endTime)')
end_time=$(echo $latest_scan | jq -r '.endTime')
echo "end_time=$end_time" >> $GITHUB_ENV
# Step 9: Compare End Time with Current Time
- name: Fetch Quality Gate Status
if: steps.latest-scan.outputs.end_time > env.current_time
run: |
echo "Latest scan is completed. Fetching quality gate status..."
curl -X GET "https://demo.embold.io/api/v1/repositories/e602c21b7e4d91f90b2914504eaeb8ae/qualitygateprofiles/status" -H "Authorization: Bearer ${{ secrets.EMBOLD_TOKEN_DEMO_INST }}"
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
- name: Wait and Retry
if: steps.latest-scan.outputs.end_time <= env.current_time
run: |
echo "Latest scan results are not ready yet. Please wait and retry."
# Step 8: Poll for scan completion and fetch the latest scan details
# - name: Fetch Latest Scan Details
# id: fetch-scan-details
# run: |
# REPO_UID="e602c21b7e4d91f90b2914504eaeb8ae"
# API_URL="https://https://demo.embold.io/api/v1/repositories/e602c21b7e4d91f90b2914504eaeb8ae/scans"

# until [[ "$(curl -s -H "Authorization: Bearer ${{ secrets.EMBOLD_TOKEN_DEMO_INST }}" $API_URL | jq -r '.[] | select(.isCompleted == true and .scanStatus == "success") | .endTime')" > "$CURRENT_TIME" ]]; do
# echo "Waiting for latest scan to complete..."
# sleep 30
# done
# echo "Scan completed and results are up-to-date."

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"
# 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"

0 comments on commit 7c5decf

Please sign in to comment.