From 2be1dfb20d5a12265e93831e60320b5bee21446b Mon Sep 17 00:00:00 2001 From: srakeshkumar1019 Date: Thu, 13 Jun 2024 16:02:15 +0530 Subject: [PATCH] SUPINT-2380: pr checksbox test feat --- .github/workflows/build.yaml | 15 +++++++---- .github/workflows/lint.yaml | 33 ++++++++++++++++++++++- .github/workflows/pr-checkbox.yml | 45 +++++++++++++++++++++++++++++++ .github/workflows/utest.yaml | 11 ++++++++ 4 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/pr-checkbox.yml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b8a85f68..da95b669 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -33,11 +33,16 @@ jobs: with: ref: ${{ env.BRANCH_NAME }} - # - name: Remove .npmrc file if exists - # run: | - # if [ -f .npmrc ]; then - # rm .npmrc - # fi + - name: Check PR Description for Build Checkbox + id: check-build-checkbox + run: | + PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH") + if echo "$PR_BODY" | grep -q '\- \[x\] Stop Build'; then + echo "Build checkbox is checked. Proceeding with build." + else + echo "Build checkbox is not checked. Skipping build." + exit 78 # Exit with a neutral status to stop further jobs + fi - name: Setup Node.js uses: actions/setup-node@v4 diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 0065e88d..d366f192 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -16,6 +16,28 @@ env: BRANCH_NAME: ${{ github.head_ref || inputs.branch || 'dev' }} jobs: + check-pr-body: + runs-on: ubuntu-latest + outputs: + should_run_ci: ${{ steps.check.outputs.should_run_ci }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ env.BRANCH_NAME }} + + - name: Check PR body for unchecked checkbox + id: check + run: | + PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH") + if echo "$PR_BODY" | grep -q '\[ \]'; then + echo "should_run_ci=true" >> $GITHUB_ENV + echo "::set-output name=should_run_ci::true" + else + echo "should_run_ci=false" >> $GITHUB_ENV + echo "::set-output name=should_run_ci::false" + fi + lint: runs-on: ubuntu-latest steps: @@ -23,6 +45,16 @@ jobs: with: ref: ${{ env.BRANCH_NAME }} + - name: Check PR Description for Checkboxes + id: check-pr-description + run: | + PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH") + if echo "$PR_BODY" | grep -q '\- \[x\] Stop Lint'; then + echo "Lint checkbox is checked. Stopping workflow." + exit 78 # Exit with a neutral status to stop further jobs + fi + echo "Lint checkbox is not checked. Proceeding with linting." + - name: Remove .npmrc file if exists run: | if [ -f .npmrc ]; then @@ -40,7 +72,6 @@ jobs: npm config set //npm.pkg.github.com/:_authToken=${{ secrets.GIT_TOKEN }} --global npm config set registry https://registry.npmjs.org/ --global - - name: Install @angular/cli run: npm install -g @angular/cli diff --git a/.github/workflows/pr-checkbox.yml b/.github/workflows/pr-checkbox.yml new file mode 100644 index 00000000..91107299 --- /dev/null +++ b/.github/workflows/pr-checkbox.yml @@ -0,0 +1,45 @@ +name: Check PR Checkboxes + +on: + pull_request: + types: [opened, edited, synchronize] + +jobs: + check-pr-body: + runs-on: ubuntu-latest + outputs: + run_lint: ${{ steps.check.outputs.run_lint }} + run_build: ${{ steps.check.outputs.run_build }} + run_utest: ${{ steps.check.outputs.run_utest }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Check PR body for checkboxes + id: check + run: | + PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH") + + if echo "$PR_BODY" | grep -q '\- \[ \] Stop Lint'; then + echo "run_lint=true" >> $GITHUB_ENV + echo "::set-output name=run_lint::true" + else + echo "run_lint=false" >> $GITHUB_ENV + echo "::set-output name=run_lint::false" + fi + + if echo "$PR_BODY" | grep -q '\- \[ \] Stop Build'; then + echo "run_build=true" >> $GITHUB_ENV + echo "::set-output name=run_build::true" + else + echo "run_build=false" >> $GITHUB_ENV + echo "::set-output name=run_build::false" + fi + + if echo "$PR_BODY" | grep -q '\- \[ \] Stop Unit Tests'; then + echo "run_utest=true" >> $GITHUB_ENV + echo "::set-output name=run_utest::true" + else + echo "run_utest=false" >> $GITHUB_ENV + echo "::set-output name=run_utest::false" + fi diff --git a/.github/workflows/utest.yaml b/.github/workflows/utest.yaml index e2c97818..736318ed 100644 --- a/.github/workflows/utest.yaml +++ b/.github/workflows/utest.yaml @@ -23,6 +23,17 @@ jobs: with: ref: ${{ env.BRANCH_NAME }} + - name: Check PR Description for Unit Test Checkbox + id: check-utest-checkbox + run: | + PR_BODY=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH") + if echo "$PR_BODY" | grep -q '\- \[x\] Stop Unit Tests'; then + echo "Unit Tests checkbox is checked. Proceeding with unit tests." + else + echo "Unit Tests checkbox is not checked. Skipping unit tests." + exit 78 # Exit with a neutral status to stop further jobs + fi + - name: Remove .npmrc file if exists run: | if [ -f .npmrc ]; then