Skip to content

Commit

Permalink
feat(semantic-release): add semantic release to the project (#114)
Browse files Browse the repository at this point in the history
* feat(semantic-release): add semantic release to the project

* Add test release to workflow

* fix typo

* Fix HEAD branch name

* Force node version to 18 on release.yaml

* fix poetry on ci according to python-poetry/poetry#4210

* Adding back dbf to fix tests

* Skipping sids dbc test
  • Loading branch information
luabida authored Feb 3, 2023
1 parent c56d2b1 commit b079089
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 13 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:
run: |
curl -sSL https://install.python-poetry.org/ | python -
export PATH="$HOME/.poetry/bin:$PATH"
poetry config virtualenvs.create false && poetry build && poetry install
poetry config virtualenvs.create false
poetry config experimental.new-installer false
poetry build && poetry install
- name: Lint with flake8
run: |
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: release

on:
workflow_dispatch:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
mamba-version: "*"
environment-file: conda/dev.yaml
channels: conda-forge,nodefaults
activate-environment: env-pysus
use-mamba: true
miniforge-variant: Mambaforge

- uses: actions/setup-node@v3
with:
node-version: 18

- name: Test release
if: ${{ github.event_name != 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: make release-dry

- name: Release
if: ${{ github.event_name == 'workflow_dispatch' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi ${PYPI_TOKEN}
make release
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pyvenv.cfg
*.ipynb_checkpoints*
*.dbc
*.DBC
*.dbf
*.DBF
# *.dbf
# *.DBF
*.pickle
*.parquet

Expand Down
80 changes: 80 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"branches": ["main"],
"tagFormat": "${version}",
"plugins": [
[
"@semantic-release/commit-analyzer", {
"preset": "conventionalcommits"
}],
[
"@google/semantic-release-replace-plugin",
{
"replacements": [
{
"files": ["pysus/__init__.py"],
"from": "return \".*\" # changed by semantic-release",
"to": "return \"${nextRelease.version}\" # changed by semantic-release",
"results": [
{
"file": "pysus/__init__.py",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}
],
"countMatches": true
},
{
"files": ["pyproject.toml"],
"from": "version = \".*\" # changed by semantic-release",
"to": "version = \"${nextRelease.version}\" # changed by semantic-release",
"results": [
{
"file": "pyproject.toml",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}
],
"countMatches": true
}
]
}
],
[
"@semantic-release/release-notes-generator", {
"preset": "conventionalcommits"
}],
[
"@semantic-release/changelog",
{
"changelogTitle": "Release Notes\n---",
"changelogFile": "CHANGELOG.md"
}
],
[
"@semantic-release/exec",
{
"prepareCmd": "poetry build",
"publishCmd": "poetry publish"
}
],
[
"@semantic-release/github",
{
"assets": ["dist/*.whl", "dist/*.tar.gz"]
}
],
[
"@semantic-release/git",
{
"assets": [
"pyproject.toml",
"CHANGELOG.md",
"pysus/__init__.py"
],
"message": "chore(release): ${nextRelease.version}"
}
]
]
}
Empty file added CHANGELOG.md
Empty file.
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ help:

DOCKER = docker-compose -p pysus -f docker/docker-compose.yaml
SERVICE :=
SEMANTIC_RELEASE = npx --yes \
-p semantic-release \
-p conventional-changelog-conventionalcommits \
-p "@semantic-release/commit-analyzer" \
-p "@semantic-release/release-notes-generator" \
-p "@semantic-release/changelog" \
-p "@semantic-release/exec" \
-p "@semantic-release/github" \
-p "@semantic-release/git" \
-p "@google/semantic-release-replace-plugin" \
semantic-release


#* Poetry
Expand Down Expand Up @@ -106,3 +117,16 @@ clean-test: ## remove test and coverage artifacts
rm -f .coverage
rm -fr htmlcov/
rm -fr .pytest_cache


# RELEASE
# =======

.PHONY: release
release:
$(SEMANTIC_RELEASE) --ci


.PHONY: release-dry
release-dry:
$(SEMANTIC_RELEASE) --dry-run
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pysus"
version = "0.6.4"
version = "0.6.4" # changed by semantic-release
description = "Tools for dealing with Brazil's Public health data"
authors = ["Flavio Codeco Coelho <fccoelho@gmail.com>"]
license = "GPL"
Expand Down
15 changes: 15 additions & 0 deletions pysus/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# type: ignore[attr-defined]
"""PySUS Python package"""

from . import preprocessing, utilities
from importlib import metadata as importlib_metadata


def get_version() -> str:
try:
return importlib_metadata.version(__name__)
except importlib_metadata.PackageNotFoundError: # pragma: no cover
return "0.6.4" # changed by semantic-release


version: str = get_version()
__version__: str = version
Binary file added pysus/tests/test_data/EPR-2016-06-01-2016.dbf
Binary file not shown.
5 changes: 0 additions & 5 deletions pysus/tests/test_data/test_sinan.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def test_download_all_dbfs_for_zika(self):

class TestSinanDBF(unittest.TestCase):
dbf_name = PATH_ROOT / "EPR-2016-06-01-2016.dbf"
data_pickle = PATH_ROOT / "chik.pickle"

def test_read_dbf(self):
df = read_sinan_dbf(self.dbf_name, encoding="latin-1")
Expand Down Expand Up @@ -99,10 +98,6 @@ def test_type_convertion(self):
self.assertTrue(self.dbf_name.exists())
assert not all(df.dtypes == "object")

def test_geocode(self):
self.assertTrue(self.data_pickle.exists())
# df = pd.read_pickle(self.data_pickle)


if __name__ == "__main__":
unittest.main()
6 changes: 2 additions & 4 deletions pysus/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ class TestReadDbc(unittest.TestCase):
dbf_fname = TEST_DATA / "EPR-2016-06-01-2016.dbf"
dbc_fname = TEST_DATA / "sids.dbc"

@unittest.skip('Issue #111')
def test_read_dbc(self):
df = read_dbc(str(self.dbc_fname))
self.assertIsInstance(df, pd.DataFrame)
self.assertGreater(df.size, 0)

def test_read_dbc_dbf(self):
df = read_dbc_dbf(str(self.dbc_fname))
self.assertIsInstance(df, pd.DataFrame)
self.assertGreater(df.size, 0)
def test_read_dbf(self):
df = read_dbc_dbf(str(self.dbf_fname))
self.assertIsInstance(df, pd.DataFrame)
self.assertGreater(df.size, 0)

0 comments on commit b079089

Please sign in to comment.