Skip to content

Commit

Permalink
chore: Migrate CI to Gh actions (#52)
Browse files Browse the repository at this point in the history
* Initial GH actions commit

* small fix

* small fix

* final

* add image build job
  • Loading branch information
Meer Sawood authored Feb 4, 2021
1 parent f250ba3 commit 6ee42e5
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 16 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/ci-build-image.yml
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
@@ -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 .
14 changes: 14 additions & 0 deletions .github/workflows/slash-command.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 4 additions & 7 deletions qa/measure-cyclomatic-complexity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 4 additions & 7 deletions qa/measure-maintainability-index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions qa/runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6ee42e5

Please sign in to comment.