From 6ee42e57507aaf5fda0e6849961ace2d5ad93d30 Mon Sep 17 00:00:00 2001 From: Meer Sawood Date: Thu, 4 Feb 2021 01:15:51 -0800 Subject: [PATCH] chore: Migrate CI to Gh actions (#52) * Initial GH actions commit * small fix * small fix * final * add image build job --- .github/workflows/ci-build-image.yml | 58 ++++++++++++++++++++++++ .github/workflows/ci-build.yml | 67 ++++++++++++++++++++++++++++ .github/workflows/slash-command.yml | 14 ++++++ README.md | 3 ++ qa/measure-cyclomatic-complexity.sh | 11 ++--- qa/measure-maintainability-index.sh | 11 ++--- qa/runtests.sh | 3 +- 7 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/ci-build-image.yml create mode 100644 .github/workflows/ci-build.yml create mode 100644 .github/workflows/slash-command.yml diff --git a/.github/workflows/ci-build-image.yml b/.github/workflows/ci-build-image.yml new file mode 100644 index 0000000..afa5903 --- /dev/null +++ b/.github/workflows/ci-build-image.yml @@ -0,0 +1,58 @@ +name: CI Build / Push Image +on: + repository_dispatch: + types: [build-image-command] + +env: + REGISTRY: ghcr.io + REPOSITORY: ${{ github.event.client_payload.github.payload.repository.full_name }} + DEFAULT_TAG: SNAPSHOT-PR-${{ github.event.client_payload.github.payload.issue.number }} + FULL_NAME: fabric8-analytics-github-refresh-cornjob + + +jobs: + Build-push-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: | + git fetch origin +refs/pull/${{ github.event.client_payload.github.payload.issue.number }}/merge + git checkout FETCH_HEAD + - name: Create comment + uses: peter-evans/create-or-update-comment@v1 + with: + edit-mode: replace + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + body: | + **Edit:** :test_tube: [CI has Started Image Build]( https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) + reactions: eyes + - name: Login to Github Container Registry + uses: docker/login-action@v1 + with: + registry: ${{ env. REGISTRY }} + username: ${{ github.event.client_payload.github.actor }} + password: ${{ secrets.CR_PAT }} + - name: Build Image + run: docker build --no-cache -t ${{env.REGISTRY}}/${{env.REPOSITORY}}/${{env.FULL_NAME}}:${{env.DEFAULT_TAG}} -f Dockerfile . + - name: Push Image + run: docker push ${{env.REGISTRY}}/${{env.REPOSITORY}}/${{env.FULL_NAME}}:${{env.DEFAULT_TAG}} + - name: Create success comment + if: success() + uses: peter-evans/create-or-update-comment@v1 + env: + IMAGE_URL: ${{env.REGISTRY}}/${{env.REPOSITORY}}/${{env.FULL_NAME}}:${{env.DEFAULT_TAG}} + with: + edit-mode: replace + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + body: | + **Edit:** :v: [Image Build Successfull]( https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) @${{github.event.client_payload.github.actor}}, Avaliable at: ```${{ env.IMAGE_URL }}``` + reactions: hooray, heart + - name: Create fail comment + if: failure() + uses: peter-evans/create-or-update-comment@v1 + with: + edit-mode: replace + comment-id: ${{ github.event.client_payload.github.payload.comment.id }} + body: | + **Edit:** :facepalm: [Build and Push Image Failed]( https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}) + reactions: confused diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml new file mode 100644 index 0000000..0858583 --- /dev/null +++ b/.github/workflows/ci-build.yml @@ -0,0 +1,67 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + Code-Quality-Checks: + runs-on: ubuntu-latest + strategy: + matrix: + scripts: + - run-linter + - check-docstyle + - detect-dead-code + - detect-common-errors + - measure-maintainability-index + - measure-cyclomatic-complexity + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.6 + uses: actions/setup-python@v2 + with: + python-version: '3.6' + - name: Install virtualenv + run: pip install -U pip && pip install virtualenv + - name: ${{ matrix.scripts }} + run: bash qa/${{ matrix.scripts }}.sh; + Unit-Tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.6 + uses: actions/setup-python@v2 + with: + python-version: '3.6' + - name: Install virtualenv + run: pip install -U pip && pip install virtualenv + - name: Run Unit Tests + run: bash qa/runtests.sh + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml + openshift-yaml-validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install oc + uses: redhat-actions/oc-installer@v1 + with: + version: '4.6' + - name: Run oc process + run: oc process --local -f openshift/template.yaml -o yaml > blueprint.yaml + - name: validate openshift yaml + uses: instrumenta/kubeval-action@master + with: + files: blueprint.yaml + Build-docker-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run Docker Build + run: docker build --no-cache -t tests-image -f Dockerfile . diff --git a/.github/workflows/slash-command.yml b/.github/workflows/slash-command.yml new file mode 100644 index 0000000..a9d87cf --- /dev/null +++ b/.github/workflows/slash-command.yml @@ -0,0 +1,14 @@ +name: Slash Command Dispatch +on: + issue_comment: + types: [created] +jobs: + slashCommandDispatch: + runs-on: ubuntu-latest + steps: + - name: Slash Command Dispatch + uses: peter-evans/slash-command-dispatch@v2 + with: + token: ${{ secrets.CR_PAT }} + commands: | + build-image diff --git a/README.md b/README.md index 69630df..b8e978f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +![CI](https://github.com/fabric8-analytics/fabric8-analytics-github-refresh-cornjob/workflows/CI/badge.svg?branch=master) +[![codecov](https://codecov.io/gh/fabric8-analytics/fabric8-analytics-github-refresh-cornjob/branch/master/graph/badge.svg?token=qi833miGbI)](https://codecov.io/gh/fabric8-analytics/fabric8-analytics-github-refresh-cornjob) + # GitHub refresh cronjob OpenShift cron job for refreshing GitHub data of ingested packages. diff --git a/qa/measure-cyclomatic-complexity.sh b/qa/measure-cyclomatic-complexity.sh index 6affb96..f9383cb 100755 --- a/qa/measure-cyclomatic-complexity.sh +++ b/qa/measure-cyclomatic-complexity.sh @@ -20,12 +20,9 @@ radon cc -s -a -i venv . popd -if [[ "$1" == "--fail-on-error" ]] +defects="$(radon cc -s -n D -i venv . | wc -l)" +if [[ $defects -gt 0 ]] then - defects="$(radon cc -s -n D -i venv . | wc -l)" - if [[ $defects -gt 0 ]] - then - echo "File(s) with too high cyclomatic complexity detected!" - exit 1 - fi + echo "File(s) with too high cyclomatic complexity detected!" + exit 1 fi diff --git a/qa/measure-maintainability-index.sh b/qa/measure-maintainability-index.sh index ce75381..ca961a6 100755 --- a/qa/measure-maintainability-index.sh +++ b/qa/measure-maintainability-index.sh @@ -20,12 +20,9 @@ radon mi -s -i venv . popd -if [[ "$1" == "--fail-on-error" ]] +defects="$(radon mi -s -n B -i venv . | wc -l)" +if [[ $defects -gt 0 ]] then - defects="$(radon mi -s -n B -i venv . | wc -l)" - if [[ $defects -gt 0 ]] - then - echo "File(s) with too low maintainability index detected!" - exit 1 - fi + echo "File(s) with too low maintainability index detected!" + exit 1 fi diff --git a/qa/runtests.sh b/qa/runtests.sh index 4cac93f..250a801 100755 --- a/qa/runtests.sh +++ b/qa/runtests.sh @@ -42,8 +42,7 @@ check_python_version $(which pip3) install pytest-cov -PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$(pwd) python3 "$(which pytest)" --cov=./src --cov-config .coveragerc --cov-report term-missing --cov-fail-under=$COVERAGE_THRESHOLD -vv tests/ -codecov --token=c7d85992-337d-48b1-abb4-e55429b3e9c9 +PYTHONDONTWRITEBYTECODE=1 PYTHONPATH=$(pwd) python3 "$(which pytest)" --cov=./src --cov-config .coveragerc --cov-report=xml --cov-fail-under=$COVERAGE_THRESHOLD -vv tests/ printf "%stests passed%s\n\n" "${GREEN}" "${NORMAL}" popd > /dev/null