Update commonslang.yml #12
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
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 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 | |
# 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 }}" | |
- 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" |