Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement automatic releases and testing #2

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ omit =
version.py

[report]
include = src/*
include = snippets2changelog/*
# Regexes for lines to exclude from consideration

ignore_errors = True
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---

# this file is *not* meant to cover or endorse the use of GitHub Actions, but
# rather to help make automated releases for this project

name: Upload Python Package

on:
push:
branches:
- main

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.11'
- name: Install build and deploy dependencies
run: |
python -m pip install -U poetry twine
poetry self add "poetry-dynamic-versioning[plugin]"
poetry install
- name: Parse changelog
id: parse_changelog
run: |
poetry run changelog2version --changelog_file changelog.md --print | python -c "import sys, json; print(json.load(sys.stdin)['info']['description'])" > latest_description.txt
echo 'LATEST_DESCRIPTION<<"EOT"' >> $GITHUB_OUTPUT
cat latest_description.txt >> $GITHUB_OUTPUT
echo '"EOT"' >> $GITHUB_OUTPUT
latest_version=$(poetry run changelog2version --changelog_file changelog.md --print | python -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
echo "latest_version=$latest_version" >> $GITHUB_ENV
- name: Build package
run: |
poetry run changelog2version \
--changelog_file changelog.md \
--version_file snippets2changelog/version.py \
--version_file_type py \
--debug
poetry build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
verbose: true
print_hash: true
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.latest_version }}
release_name: ${{ env.latest_version }}
body: ${{ steps.parse_changelog.outputs.LATEST_DESCRIPTION }}
draft: false
prerelease: false
74 changes: 74 additions & 0 deletions .github/workflows/test-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---

# this file is *not* meant to cover or endorse the use of GitHub Actions, but
# rather to help make automated releases for this project

name: Upload Python Package to test.pypi.org

on: [pull_request]

permissions:
contents: write

jobs:
test-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.11'
- name: Install deploy dependencies
run: |
python -m pip install -U poetry twine
poetry self add "poetry-dynamic-versioning[plugin]"
poetry install
- name: Parse changelog
id: parse_changelog
run: |
poetry run changelog2version --changelog_file changelog.md --print | python -c "import sys, json; print(json.load(sys.stdin)['info']['description'])" > latest_description.txt
echo 'LATEST_DESCRIPTION<<"EOT"' >> $GITHUB_OUTPUT
cat latest_description.txt >> $GITHUB_OUTPUT
echo '"EOT"' >> $GITHUB_OUTPUT
latest_version=$(poetry run changelog2version --changelog_file changelog.md --print | python -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
echo "latest_version=$latest_version" >> $GITHUB_ENV
- name: Build package
run: |
poetry run changelog2version \
--changelog_file changelog.md \
--version_file snippets2changelog/version.py \
--version_file_type py \
--additional_version_info="-rc${{ github.run_number }}.dev${{ github.event.number }}" \
--debug
poetry build
- name: Test built package
run: |
twine check dist/*.tar.gz
- name: Archive build package artifact
uses: actions/upload-artifact@v3
with:
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
# ${{ github.repository }} and ${{ github.ref_name }} can't be used for artifact name due to unallowed '/'
name: dist_py.${{ github.event.repository.name }}_sha.${{ github.sha }}_build.${{ github.run_number }}
path: dist/*.tar.gz
retention-days: 14
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
repository_url: https://test.pypi.org/legacy/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
skip_existing: true
verbose: true
print_hash: true
- name: Create Prerelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.latest_version }}-rc${{ github.run_number }}.dev${{ github.event.number }}
release_name: ${{ env.latest_version }}-rc${{ github.run_number }}.dev${{ github.event.number }}
body: ${{ steps.parse_changelog.outputs.LATEST_DESCRIPTION }}
draft: false
prerelease: true
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---

# This workflow will install Python dependencies, run tests and lint with a
# specific Python version
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Test Python package

on:
push:
# branches: [ $default-branch ]
branches-ignore:
- 'main'
- 'develop'

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# python-version: ['3.8', '3.9', '3.10', '3.11']
# # os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install -U poetry
poetry install
- name: Test with pytest
run: |
poetry run pytest -v
- name: Install deploy dependencies
run: |
python -m pip install -U twine
poetry self add "poetry-dynamic-versioning[plugin]"
- name: Build package
run: |
poetry run changelog2version \
--changelog_file changelog.md \
--version_file snippets2changelog/version.py \
--version_file_type py \
--debug
poetry build
- name: Test built package
run: |
twine check dist/*.tar.gz
38 changes: 38 additions & 0 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

# this file is *not* meant to cover or endorse the use of GitHub Actions, but
# rather to help make automated releases for this project

name: Unittest Python Package

on: [push, pull_request]

permissions:
contents: read

jobs:
test-and-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v3
with:
python-version: '3.11'
- name: Execute tests
run: |
python -m pip install -U poetry
poetry install
python create_report_dirs.py
poetry run coverage run -m pytest -v
- name: Create coverage report
run: |
poetry run coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./reports/coverage/coverage.xml
flags: unittests
fail_ci_if_error: true
# path_to_write_report: ./reports/coverage/codecov_report.txt
verbose: true
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Create version info files based on the latest changelog entry.
- [Parse](#parse)
- [Contributing](#contributing)
- [Setup](#setup)
- [Testing](#testing)
- [Credits](#credits)

<!-- /MarkdownTOC -->
Expand Down Expand Up @@ -103,14 +104,33 @@ changelog-generator parse example_snippets/123.md \

For active development you need to have `poetry` and `pre-commit` installed

```sh
```bash
python3 -m pip install --upgrade --user poetry pre-commit
git clone https://github.com/brainelectronics/snippets2changelog.git
cd snippets2changelog
pre-commit install
poetry install
```

### Testing

```bash
# run all tests
poetry run coverage run -m pytest -v

# run only one specific tests
poetry run coverage run -m pytest -v -k "test_read_save_json"
```

Generate the coverage files with

```bash
python create_report_dirs.py
coverage html
```

The coverage report is placed at `reports/coverage/html/index.html`

## Credits

A big thank you to the creators and maintainers of [SemVer.org][ref-semver]
Expand Down
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ r"^\#\# \[\d{1,}[.]\d{1,}[.]\d{1,}\] \- \d{4}\-\d{2}-\d{2}$"
-->

## Released
## [0.1.0] - 2204-05-30
## [0.1.0] - 2024-05-30
### Added
- This changelog file
- [`.coveragerc`](.coveragerc) file
Expand Down
32 changes: 31 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "snippets2changelog"
version = "0.0.0+will-be-updated-automatically"
version = "0.0.0" # will-be-updated-automatically
description = "Generate a changelog from individual snippets"
authors = ["brainelectronics <[email protected]>"]
repository = "https://github.com/brainelectronics/snippets2changelog"
Expand All @@ -10,7 +10,7 @@ packages = [
{ include = "snippets2changelog/**/*.py" }
]
include = [
{ path = 'snippets2changelog/templates/snippet.md.template', format = 'sdist' }
{ path = "snippets2changelog/templates/snippet.md.template", format = ["sdist", "wheel"] }
]
exclude = ["snippets2changelog/out"]
classifiers = [
Expand All @@ -33,7 +33,7 @@ enable = true
format-jinja-imports = [
{ module = "subprocess", item = "check_output" },
]
format-jinja = """{{ check_output(["python", "-c", "from pathlib import Path; exec(Path('snippets2changelog/version.py').read_text()); print(__version__)"]).decode().strip() }}"""
format-jinja = """{{ check_output(["python3", "-c", "from pathlib import Path; exec(Path('snippets2changelog/version.py').read_text()); print(__version__)"]).decode().strip() }}"""
# format-jinja = "{{ env.get('PROJECT_VERSION') }}"

[tool.poetry.scripts]
Expand All @@ -43,9 +43,11 @@ changelog-generator = 'snippets2changelog.cli:main'
python = "^3.11"
pyyaml = "~6.0"
GitPython = "~3.1.43"
jinja2 = "^3.1.4"

[tool.poetry.group.dev.dependencies]
black = "*"
changelog2version = "^0.10"
flake8 = "*"
isort = "*"
mypy = "*"
Expand Down
Empty file added tests/__init__.py
Empty file.
Loading
Loading