diff --git a/build-and-test-sonarqube.yaml b/build-and-test-sonarqube.yaml new file mode 100644 index 0000000..117dbaf --- /dev/null +++ b/build-and-test-sonarqube.yaml @@ -0,0 +1,101 @@ +name: Zing_hr_frontend +on: + push: + branches: + - main + - beta + - testing + - client + - staging + - production + pull_request: + branches: + - main + - beta + - testing + - client + - staging + - production +jobs: + ZingHR-Frontend-Build-Test: + name: Build and Test PR + if: github.event_name == 'pull_request' && github.base_ref == 'testing' + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Installing Dependecies + run: npm i --legacy-peer-deps + - name: Check Build + run: npm run build + - name: Auditing Node Dependecies + run: npm audit --audit-level=critical + - name: Checkout Code + uses: actions/checkout@v3 + with: + # Disabling shallow clone is recommended for improving relevancy of reporting + fetch-depth: 0 + - name: SonarQube Scan + uses: kitabisa/sonarqube-action@v1.2.0 + with: + host: ${{ secrets.SONARQUBE_HOST }} + login: ${{ secrets.SONARQUBE_TOKEN }} + + Build and Deploy Zing_hr_frontend: + if: github.event_name == 'push' && github.ref_name == 'testing' + runs-on: ubuntu-latest + steps: + - name: Checkout Code in Runner + uses: actions/checkout@v3 + - name: Branch and Folder Selection for Deployment + run: | + BRANCH_NAME=${{ gitea.ref_name }} + case $BRANCH_NAME in + beta) + echo "PROJECT_FOLDER=null" >> $GITHUB_ENV + PROJECT_FOLDER="null" + echo "PM2_ID=null" >> $GITHUB_ENV + ;; + testing) + echo "PROJECT_FOLDER=/home/zinghr/Test_Release/zing_hr_frontend" >> $GITHUB_ENV + PROJECT_FOLDER="/home/zinghr/Test_Release/zing_hr_frontend" + echo "PM2_ID=3" >> $GITHUB_ENV + ;; + client) + echo "PROJECT_FOLDER=/home/zinghr/Client_Release/zing_hr_frontend" >> $GITHUB_ENV + PROJECT_FOLDER="/home/zinghr/Client_Release/zing_hr_frontend" + echo "PM2_ID=4" >> $GITHUB_ENV + ;; + *) + echo "Unknown Branch" + exit 1 + ;; + esac + echo "BRANCH_NAME=${{ gitea.ref_name }}" >> $GITHUB_ENV + echo "SELECTED BRANCH : $BRANCH_NAME" + echo "SELECTED FOLDER : $PROJECT_FOLDER" + + - name: Deployment to Server SSH + uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.BETA_SERVER_HOST }} + username: ${{ secrets.BETA_SERVER_USERNAME }} + password: ${{ secrets.BETA_SERVER_PASSWORD }} + port: ${{ secrets.BETA_SERVER_PORT }} + envs: BRANCH_NAME,PROJECT_FOLDER,PM2_ID + script: | + set -xe + echo $BRANCH_NAME + echo $PROJECT_FOLDER + cd $PROJECT_FOLDER + git fetch origin + git reset --hard origin/$BRANCH_NAME + git pull origin $BRANCH_NAME + echo "BUILDING..... " + npm i --legacy-peer-deps + npm run build + pm2 restart $PM2_ID +