From a97159a8eb10bc2c561bc4f311d22121f827db2d Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 11:35:07 +0530 Subject: [PATCH 01/12] Update feature-workflow.yaml --- .github/workflows/feature-workflow.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/feature-workflow.yaml b/.github/workflows/feature-workflow.yaml index 6f3d13e2b..69fa8285f 100644 --- a/.github/workflows/feature-workflow.yaml +++ b/.github/workflows/feature-workflow.yaml @@ -7,7 +7,7 @@ on: - feature/obi jobs: - app-containerize: + docker-build-and-push: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -27,8 +27,8 @@ jobs: run: | docker build -t $ECR_REGISTRY/onebillionideas:erp-lms-v1 . docker push $ECR_REGISTRY/onebillionideas:erp-lms-v1 - deploy: - needs: app-containerize + deploy-Container: + needs: docker-build-and-push runs-on: ubuntu-latest steps: - name: Checkout code From 5909530be9f81290549d02e017156b9b30a0b962 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 11:36:12 +0530 Subject: [PATCH 02/12] Update feature-workflow.yaml --- .github/workflows/feature-workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/feature-workflow.yaml b/.github/workflows/feature-workflow.yaml index 69fa8285f..a632ed7a7 100644 --- a/.github/workflows/feature-workflow.yaml +++ b/.github/workflows/feature-workflow.yaml @@ -1,5 +1,5 @@ -name: Obi Test +name: erp-lms-service on: push: From 44535066e8022d4eb9b5987b09bfb4112ef68926 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 12:33:05 +0530 Subject: [PATCH 03/12] Update deploy.yaml --- .github/workflows/deploy.yaml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 6a329fe53..ef8cd96ef 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,26 +1,27 @@ -name: Obi Test +name: erp-lms-service on: push: branches: - - feature/obitest + - feature/obi/test jobs: - deploy: + deploy-Container: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: SSH into EC2 instance and deploy Docker container - uses: appleboy/ssh-action@v0.1.5 + - name: Notify Slack + uses: asconsoft/action-slack@v4.0.1 with: - host: ${{ secrets.SERVER_IP }} - port: ${{ secrets.SERVER_PORT }} - username: ${{ secrets.SERVER_USERNAME }} - password: ${{ secrets.EC2_PASSWORD }} - script: | - docker pull $ECR_REGISTRY/onebillionideas:${IMAGE_TAG} - docker stop my-docker-container || true - docker rm my-docker-container || true - docker run -d -p 8080:8080 $ECR_REGISTRY/onebillionideas:${IMAGE_TAG}" + channel: '#deployment' + if_mention: failure,cancelled + status: ${{ job.status }} + fields: workflow,job,commit,repo,ref,author + text_success: ':rocket: `erp-lms` is successfully deployed in an EC2 instance' + text_failure: ':boom: `erp-lms` has failed to be deployed :-1:; working on it :hammer_and_wrench:' + env: + SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required + if: always() # Pick up events even if the job fails or is canceled. + + From f56fafa10aa24c2bedf708df2d7c22c97de0f651 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 12:41:21 +0530 Subject: [PATCH 04/12] Update feature-workflow.yaml --- .github/workflows/feature-workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/feature-workflow.yaml b/.github/workflows/feature-workflow.yaml index a632ed7a7..1583b49e2 100644 --- a/.github/workflows/feature-workflow.yaml +++ b/.github/workflows/feature-workflow.yaml @@ -4,7 +4,7 @@ name: erp-lms-service on: push: branches: - - feature/obi + - feature/obi/test jobs: docker-build-and-push: From 7177fe45b4b8f65ee859829d36fe3517bc8dcaed Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:05:24 +0530 Subject: [PATCH 05/12] Create pr-check.yaml --- .github/workflows/pr-check.yaml | 88 +++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/pr-check.yaml diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml new file mode 100644 index 000000000..9469ace5c --- /dev/null +++ b/.github/workflows/pr-check.yaml @@ -0,0 +1,88 @@ +on: + pull_request: + branches: + - feature/obi + paths-ignore: + - .github/** + +name: DangerJS | Sonarqube + +env: + REPO: ${GITHUB_REPOSITORY} + FROM: ${GITHUB_HEAD_REF#refs/heads/} + TO: ${GITHUB_BASE_REF#refs/heads/} + KEY: ${{ github.event.number }} + +jobs: + danger_check: + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' + name: Danger JS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Danger + uses: danger/danger-js@9.1.8 + env: + SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional + - name: Notify Slack + uses: asconsoft/action-slack@v4.0.1 + with: + channel: '#pr' + if_mention: failure,cancelled + status: ${{ job.status }} + fields: workflow,job,commit,repo,ref,author + text_success: ':dizzy: `erp-lms` - this PR is successfully passed the checks for `Dangerjs` :v:' + text_failure: ':boom: `erp-lms` - this PR is failed the checks for `Dangerjs` :-1:; working on it :hammer_and_wrench:' + env: + SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required + if: always() # Pick up events even if the job fails or is canceled. + + sonar_analyze: + if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' + name: Sonarqube Analysis + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + #- run: git checkout develop + #- run: git checkout pr_decor + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Create settings.xml file + run: | + mkdir -p $HOME/.m2 + echo "${{ secrets.SETTINGS_XML_FILE_B64 }}" | base64 --decode > $HOME/.m2/settings.xml + - name: Build and sonar analyze with Maven + run: |- + mvn -B clean jacoco:prepare-agent install jacoco:report sonar:sonar \ + -Dsonar.pullrequest.key=${{ github.event.number }} \ + -Dsonar.pullrequest.branch=${GITHUB_HEAD_REF#refs/heads/} \ + -Dsonar.pullrequest.base=${GITHUB_BASE_REF#refs/heads/} \ + -Dsonar.pullrequest.github.repository=${GITHUB_REPOSITORY} \ + -Dsonar.pullrequest.provider=Github \ + -Dsonar.coverage.jacoco.xmlReportPaths=./target/site/jacoco/jacoco.xml \ + -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \ + -Dsonar.login=${{ secrets.SONARQUBE_TOKEN }} + - name: Cache Maven packages + uses: actions/cache@v2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Notify Slack + uses: asconsoft/action-slack@v4.0.1 + with: + channel: '#pr' + if_mention: failure,cancelled + status: ${{ job.status }} + fields: workflow,job,commit,repo,ref,author + text_success: ':dizzy: `erp-lms` this PR is successfully passed the checks for `Sonarqube` :v:' + text_failure: ':boom: `erp-lms` this PR is failed the checks for `Sonarqube` :-1:; working on it :hammer_and_wrench:' + env: + SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required + if: always() # Pick up events even if the job fails or is canceled. From 2107628aec0d2bba7f3e2f458c76d67b0875bec1 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:20:44 +0530 Subject: [PATCH 06/12] Update pr-check.yaml --- .github/workflows/pr-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml index 9469ace5c..85a6075ab 100644 --- a/.github/workflows/pr-check.yaml +++ b/.github/workflows/pr-check.yaml @@ -23,7 +23,7 @@ jobs: - name: Danger uses: danger/danger-js@9.1.8 env: - SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional + SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} - name: Notify Slack uses: asconsoft/action-slack@v4.0.1 with: From 672476a664fc001b5e74fcecb8b47cf4199859d5 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:27:56 +0530 Subject: [PATCH 07/12] Delete main.yaml --- .github/workflows/main.yaml | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .github/workflows/main.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml deleted file mode 100644 index 64654ec6e..000000000 --- a/.github/workflows/main.yaml +++ /dev/null @@ -1,28 +0,0 @@ -name: Obi Test - -on: - push: - branches: - - master - -jobs: - build-and-push: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ap-south-1 - - name: Login to Amazon ECR - id: login-ecr - uses: aws-actions/amazon-ecr-login@v1 - - name: Build and push Docker image - env: - ECR_REGISTRY: 288408890206.dkr.ecr.ap-south-1.amazonaws.com - IMAGE_TAG: ${{ github.sha }} - run: | - docker build -t $ECR_REGISTRY/onebillionideas:${IMAGE_TAG} . - docker push $ECR_REGISTRY/onebillionideas:${IMAGE_TAG} From 77ee09a0c159725b6d283e52aaa07d5f2b9e3540 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Sat, 11 Mar 2023 16:28:24 +0530 Subject: [PATCH 08/12] Update pr-check.yaml --- .github/workflows/pr-check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml index 85a6075ab..9469ace5c 100644 --- a/.github/workflows/pr-check.yaml +++ b/.github/workflows/pr-check.yaml @@ -23,7 +23,7 @@ jobs: - name: Danger uses: danger/danger-js@9.1.8 env: - SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} + SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional - name: Notify Slack uses: asconsoft/action-slack@v4.0.1 with: From a65e061ed0fd53e9309b2dceb47ca531461ca0fd Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Tue, 14 Mar 2023 19:11:14 +0530 Subject: [PATCH 09/12] Update pr-check.yaml --- .github/workflows/pr-check.yaml | 51 +-------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml index 9469ace5c..1a58bbdb5 100644 --- a/.github/workflows/pr-check.yaml +++ b/.github/workflows/pr-check.yaml @@ -36,53 +36,4 @@ jobs: env: SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required - if: always() # Pick up events even if the job fails or is canceled. - - sonar_analyze: - if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' - name: Sonarqube Analysis - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - #- run: git checkout develop - #- run: git checkout pr_decor - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Create settings.xml file - run: | - mkdir -p $HOME/.m2 - echo "${{ secrets.SETTINGS_XML_FILE_B64 }}" | base64 --decode > $HOME/.m2/settings.xml - - name: Build and sonar analyze with Maven - run: |- - mvn -B clean jacoco:prepare-agent install jacoco:report sonar:sonar \ - -Dsonar.pullrequest.key=${{ github.event.number }} \ - -Dsonar.pullrequest.branch=${GITHUB_HEAD_REF#refs/heads/} \ - -Dsonar.pullrequest.base=${GITHUB_BASE_REF#refs/heads/} \ - -Dsonar.pullrequest.github.repository=${GITHUB_REPOSITORY} \ - -Dsonar.pullrequest.provider=Github \ - -Dsonar.coverage.jacoco.xmlReportPaths=./target/site/jacoco/jacoco.xml \ - -Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \ - -Dsonar.login=${{ secrets.SONARQUBE_TOKEN }} - - name: Cache Maven packages - uses: actions/cache@v2 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} - restore-keys: ${{ runner.os }}-m2 - - name: Notify Slack - uses: asconsoft/action-slack@v4.0.1 - with: - channel: '#pr' - if_mention: failure,cancelled - status: ${{ job.status }} - fields: workflow,job,commit,repo,ref,author - text_success: ':dizzy: `erp-lms` this PR is successfully passed the checks for `Sonarqube` :v:' - text_failure: ':boom: `erp-lms` this PR is failed the checks for `Sonarqube` :-1:; working on it :hammer_and_wrench:' - env: - SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required - if: always() # Pick up events even if the job fails or is canceled. + if: always() # Pick up events even if the job fails or is canceled. From 48a260e57b92535a020245d1cd676b144b6563d3 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Wed, 15 Mar 2023 11:37:25 +0530 Subject: [PATCH 10/12] Update pr-check.yaml --- .github/workflows/pr-check.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml index 1a58bbdb5..8054b23b5 100644 --- a/.github/workflows/pr-check.yaml +++ b/.github/workflows/pr-check.yaml @@ -2,8 +2,8 @@ on: pull_request: branches: - feature/obi - paths-ignore: - - .github/** + # paths-ignore: + # - .github/** name: DangerJS | Sonarqube From 4ce4676f9754f67151c5bbe8e2f6547fbb8b4387 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Wed, 15 Mar 2023 21:37:18 +0530 Subject: [PATCH 11/12] Update pr-check.yaml --- .github/workflows/pr-check.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml index 8054b23b5..65c72a697 100644 --- a/.github/workflows/pr-check.yaml +++ b/.github/workflows/pr-check.yaml @@ -23,7 +23,8 @@ jobs: - name: Danger uses: danger/danger-js@9.1.8 env: - SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional + # SLACK_GIT_TOKEN: ${{ secrets.SLACK_GIT_TOKEN }} # optional + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Notify Slack uses: asconsoft/action-slack@v4.0.1 with: From 15120d6504e057b1dd0adca6e46c8d7a8d187e39 Mon Sep 17 00:00:00 2001 From: DibyoGit <64616330+DibyoGit@users.noreply.github.com> Date: Wed, 15 Mar 2023 21:40:35 +0530 Subject: [PATCH 12/12] Create dangerfile.ts --- dangerfile.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 dangerfile.ts diff --git a/dangerfile.ts b/dangerfile.ts new file mode 100644 index 000000000..eb63e6cd8 --- /dev/null +++ b/dangerfile.ts @@ -0,0 +1,36 @@ +import { message, warn, fail, markdown } from "danger" + +// Add a CHANGELOG entry for app changes +const hasChangelog = danger.git.modified_files.includes("changelog.md") +const isTrivial = (danger.github.pr.body + danger.github.pr.title).includes("#trivial") + +if (!hasChangelog && !isTrivial) { + warn("Please add a changelog entry for your changes.") +} + +// Enforce smaller PRs +var bigPRThreshold = 600; +if (danger.github.pr.additions + danger.github.pr.deletions > bigPRThreshold) { + warn(':exclamation: Big PR (' + ++errorCount + ')'); + markdown('> (' + errorCount + ') : Pull Request size seems relatively large. If Pull Request contains multiple changes, split each into separate PR will helps faster, easier review.'); +} else { + message("Thanks - We :heart: small PR!") +} + +// Always ensure we assign someone, so that our Slackbot can do its work correctly +if (danger.github.pr.assignee === null) { + fail("Please assign someone to merge this PR, and optionally include people who should review.") +} + +// Check documentation change and ensure test +const docs = danger.git.fileMatch("**/*.md") +const main = danger.git.fileMatch("src/main/java/**/*.java") +const tests = danger.git.fileMatch("src/test/java/**/*.java") + +if (docs.edited) { + message("Thanks - We :heart: our documentarians!") +} + +if (main.modified && !tests.modified) { + fail("You have main Java files changes without test Java files.") +}