Skip to content

Commit

Permalink
Merge pull request #1310 from Dessia-tech/fix_ci_upload_coverage
Browse files Browse the repository at this point in the history
Fix: CI upload coverage / CI for fork
  • Loading branch information
WirajanDASILVA authored Mar 6, 2024
2 parents bb4f9d1 + 655657e commit c43c302
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 27 deletions.
122 changes: 96 additions & 26 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ kind: pipeline
type: docker
name: default



steps:
- name: merge master on testing
image: alpine/git
when:
event: push
branch: master

commands:
- cd /tmp
- git clone $DRONE_GIT_HTTP_URL
Expand All @@ -19,11 +22,13 @@ steps:
- git merge master
- git push


- name: merge testing on dev
image: alpine/git
when:
event: push
branch: testing

commands:
- cd /tmp
- git clone $DRONE_GIT_HTTP_URL
Expand All @@ -34,42 +39,26 @@ steps:
- git merge testing
- git push

- name: notify by email
when:
event: push
branch:
- master
- dev
status:
- failure
image: drillster/drone-email
settings:
host: mail.dessia.tech
username: [email protected]
password:
from_secret: email_password
from: [email protected]

volumes:
# Mount pip cache from host
- name: cache
path: /root/.cache

- name: check changelog update
image: python:3.9
when:
event: pull_request

commands:
- git fetch origin "$DRONE_TARGET_BRANCH" "$DRONE_SOURCE_BRANCH"
- git fetch origin "$DRONE_TARGET_BRANCH":"refs/remotes/origin/$DRONE_TARGET_BRANCH"
- git fetch origin pull/$DRONE_PULL_REQUEST/head:refs/remotes/origin/pr/$DRONE_PULL_REQUEST
- bash code_changelog.sh


- name: check pep8 formatting
image: python:3.9
when:
event:
exclude:
- tag
- pull_request
- push

commands:
- pip3 install -U pip autopep8==2.0.0
- bash code_pep8.sh
Expand All @@ -79,13 +68,15 @@ steps:
- name: pip_cache
path: /root/.cache/pip


- name: check code complexity
image: dessia/python-ci:3.9
when:
event:
exclude:
- tag
- pull_request
- push

commands:
- pip install numpy Cython>3
- pip install pylint==2.17.3 pydocstyle==6.3.0 pre-commit shellcheck-py cython-lint pyenchant==3.2.2
Expand All @@ -98,17 +89,19 @@ steps:
- name: pip_cache
path: /root/.cache/pip


- name: install, build doc run scripts and tutorials
image: python:3.9
when:
event: pull_request
event: push

commands:
- git fetch --tags
- pip install .[doc,test]
- python setup.py build_ext --inplace
- cd tests
- coverage run --rcfile=../.coveragerc --data-file=../.coverage --source volmdlr -m unittest discover -v
- cd ../scripts
- cd ../scripts
- coverage run --rcfile=../.coveragerc --data-file=../.coverage --source volmdlr -a ci_scripts.py
- cd ../tutorials
- coverage run --rcfile=../.coveragerc --data-file=../.coverage --source volmdlr -a ci_tutorials.py
Expand All @@ -126,10 +119,59 @@ steps:
path: /root/.cache/pip


# Special step for fork pull request
- name: Fork only; install, build doc run scripts and tutorials
image: python:3.9
when:
event:
- pull_request

environment:
GITHUB_TOKEN:
from_secret: github_token

commands:
- apt-get update && apt-get install -y jq
- |
api_url="https://api.github.com/repos/${DRONE_REPO}/pulls/${DRONE_PULL_REQUEST}"
source_repo=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$api_url" | jq -r .head.repo.full_name)
echo "Source Repository: $source_repo"
if [ -z "$source_repo" ] || [ "$source_repo" = "null" ]; then
echo "Failed to fetch source repository. The GitHub token may have expired or lacks the necessary permissions."
exit 1
fi
if [ "$source_repo" = "${DRONE_REPO}" ]; then
echo "Source repo is ${DRONE_REPO}. Skipping step..."
else
echo "Source repo is a fork. Performing install, build doc run scripts and tutorials..."
git fetch --tags
pip install .[doc,test]
python setup.py build_ext --inplace
cd tests
coverage run --rcfile=../.coveragerc --data-file=../.coverage --source volmdlr -m unittest discover -v
cd ../scripts
coverage run --rcfile=../.coveragerc --data-file=../.coverage --source volmdlr -a ci_scripts.py
cd ../tutorials
coverage run --rcfile=../.coveragerc --data-file=../.coverage --source volmdlr -a ci_tutorials.py
cd ../doc
make html
cd ..
coverage json
coverage report
coverage html
python coverage.py
fi
- name: generate sdist
image: python:3.9
when:
branch: master

commands:
- git fetch --tags
- pip install .
Expand All @@ -140,6 +182,7 @@ steps:
- name: pip_cache
path: /root/.cache/pip


- name: generate bdist_wheel
image: python:3.9
when:
Expand All @@ -156,16 +199,19 @@ steps:
- name: pip_cache
path: /root/.cache/pip


- name: upload to pypi
image: plugins/pypi
when:
event: tag

settings:
skip_build: True
username: dessia_tech
password:
from_secret: pypi_password


- name: upload_doc_master
image: appleboy/drone-scp
when:
Expand All @@ -180,10 +226,11 @@ steps:
password:
from_secret: ssh_drone_password


- name: upload coverage
image: appleboy/drone-scp
when:
event: pull_request
event: push
failure: ignore
settings:
host: magenta.dessia.tech
Expand All @@ -196,6 +243,29 @@ steps:



- name: notify by email
when:
event: push
branch:
- master
- dev
status:
- failure

image: drillster/drone-email
settings:
host: mail.dessia.tech
username: [email protected]
password:
from_secret: email_password
from: [email protected]

volumes:
- name: cache
path: /root/.cache



volumes:
- name: pip_cache
host:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Avoid `pip install .` in drone as it is redundant with `python setup.py build_ext --inplace`
- Re-order CI steps to build doc in the end / perform shortest test first
- Avoid duplication of test between push and PR
- Fix `upload coverage` step
- Fix CI for PR from fork repo


### Updates
Expand Down
2 changes: 1 addition & 1 deletion code_changelog.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

lines=$(git diff origin/"$DRONE_TARGET_BRANCH"..origin/"$DRONE_SOURCE_BRANCH" -- CHANGELOG.md README.md CONTRIBUTING.md --unified=0| wc -l)
lines=$(git diff origin/"$DRONE_TARGET_BRANCH"..origin/pr/"$DRONE_PULL_REQUEST" -- CHANGELOG.md README.md CONTRIBUTING.md --unified=0 | wc -l)
echo "$lines lines modified on CHANGELOG.md or other doc files in PR $DRONE_SOURCE_BRANCH -> $DRONE_TARGET_BRANCH"


Expand Down

0 comments on commit c43c302

Please sign in to comment.