Skip to content

Commit

Permalink
Add CI workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
prisae committed May 22, 2024
1 parent 56042dd commit faf9996
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 2 deletions.
143 changes: 143 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: linux

# Only build PRs, the main branch, and releases.
on:
pull_request:
push:
branches:
- main
- dieter
release:
types:
- published
schedule:
- cron: "14 14 20 * *"

# Use bash by default in all jobs
defaults:
run:
# Using "-l {0}" is necessary for conda environments to be activated
# But this breaks on MacOS if using actions/setup-python:
# https://github.com/actions/setup-python/issues/132
shell: bash

# Cancel any previous run of the test job.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:

name: basic
runs-on: ubuntu-latest

steps:

# Checks-out your repository under $GITHUB_WORKSPACE
- name: Checkout
uses: actions/checkout@v4
with:
# Need to fetch more than the last commit so that setuptools-scm can
# create the correct version string. If the number of commits since
# the last release is greater than this, the version still be wrong.
# Increase if necessary.
fetch-depth: 100
# The GitHub token is preserved by default but this job doesn't need
# to be able to push to GitHub.
persist-credentials: false

# Need the tags so that setuptools-scm can form a valid version number
- name: Fetch git tags
run: git fetch origin 'refs/tags/*:refs/tags/*'

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
shell: bash -l {0}
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements-dev.txt
- name: Flake8
shell: bash -l {0}
run: flake8 docs/conf.py setup.py resmda/ tests/

- name: Test with pytest
shell: bash -l {0}
run: |
python -m pip install .
pytest --cov=resmda
deploy:
needs: test
name: Deploy to PyPI
runs-on: ubuntu-latest
# Only from the origin repository, not forks; only main and tags.
if: github.repository_owner == 'tuda' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))

steps:
# Checks-out your repository under $GITHUB_WORKSPACE
- name: Checkout
uses: actions/checkout@v4
with:
# Need to fetch more than the last commit so that setuptools-scm can
# create the correct version string. If the number of commits since
# the last release is greater than this, the version will still be
# wrong. Increase if necessary.
fetch-depth: 100
# The GitHub token is preserved by default but this job doesn't need
# to be able to push to GitHub.
persist-credentials: false

# Need the tags so that setuptools-scm can form a valid version number
- name: Fetch git tags
run: git fetch origin 'refs/tags/*:refs/tags/*'

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build setuptools-scm
- name: Build source and wheel distributions
if: github.ref == 'refs/heads/main'
run: |
# Change setuptools-scm local_scheme to "no-local-version" so the
# local part of the version isn't included, making the version string
# compatible with Test PyPI.
sed --in-place 's/"root"/"local_scheme":"no-local-version","root"/g' setup.py
- name: Build source and wheel distributions
run: |
# Build source and wheel packages
python -m build
echo ""
echo "Generated files:"
ls -lh dist/
- name: Publish to Test PyPI
if: success()
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_PASSWORD }}
repository_url: https://test.pypi.org/legacy/
# Allow existing releases on test PyPI without errors.
# NOT TO BE USED in PyPI!
skip_existing: true

- name: Publish to PyPI
# Only for releases
if: success() && github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Directories
# Directories and file types
__pycache__/
*.pdf

# Pytest and coverage related
htmlcov
.coverage
.pytest_cache/

# setuptools_scm
resmda/version.py
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ help:
@echo "Commands:"
@echo ""
@echo " install install in editable mode"
@echo " dev-install install in editable mode with dev requirements"
@echo " pytest run the test suite and report coverage"
@echo " flake8 style check with flake8"
@echo " clean clean up all generated files"
@echo ""

install:
python -m pip install --no-build-isolation --no-deps -e .

dev-install:
python -m pip install -r requirements-dev.txt && python -m pip install --no-build-isolation --no-deps -e .

.ONESHELL:
pytest:
rm -rf .coverage htmlcov/ .pytest_cache/
pytest --cov=resmda
coverage html

flake8:
flake8 setup.py resmda/
flake8 setup.py resmda/ tests/

clean:
python -m pip uninstall resmda -y
rm -rf build/ dist/ .eggs/ resmda.egg-info/ resmda/version.py # build
rm -rf */__pycache__/ */*/__pycache__/ # python cache
rm -rf .coverage htmlcov/ .pytest_cache/ # tests and coverage
11 changes: 11 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# GLOBAL REQUIREMENTS
-r requirements.txt

# SETUP RELATED
setuptools_scm

# FOR TESTING
flake8
pytest
coveralls
pytest_cov
Empty file added tests/.keep
Empty file.

0 comments on commit faf9996

Please sign in to comment.