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. + + diff --git a/.github/workflows/feature-workflow.yaml b/.github/workflows/feature-workflow.yaml index 6f3d13e2b..1583b49e2 100644 --- a/.github/workflows/feature-workflow.yaml +++ b/.github/workflows/feature-workflow.yaml @@ -1,13 +1,13 @@ -name: Obi Test +name: erp-lms-service on: push: branches: - - feature/obi + - feature/obi/test 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 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} diff --git a/.github/workflows/pr-check.yaml b/.github/workflows/pr-check.yaml new file mode 100644 index 000000000..65c72a697 --- /dev/null +++ b/.github/workflows/pr-check.yaml @@ -0,0 +1,40 @@ +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 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - 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. 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.") +}