Merge branch 'main' of https://github.com/marcwimmer/gimera #188
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test and Upload Pypi | |
on: | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: "3.10" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install flake8 pytest click inquirer pyyaml | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
# - name: Lint with flake8 | |
# run: | | |
# # stop the build if there are Python syntax errors or undefined names | |
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
- name: Test with pytest | |
run: | | |
git config --global user.email [email protected] | |
git config --global user.name gimera | |
pytest | |
- name: setup merge | |
run: | | |
set -x | |
git config --global user.email '[email protected]' | |
git config --global user.name '[email protected]' | |
git fetch | |
- name: increment version | |
run: | | |
python3 << EOF | |
import re | |
from pathlib import Path | |
file = Path('setup.cfg') | |
lines = file.read_text() | |
find = re.findall(r'version = (.*)', lines) | |
old_version_string = find[-1] | |
old_version = f'version = {old_version_string}' | |
version = list(map(int, find[-1].split('.'))) | |
version[-1] += 1 | |
version_string = '.'.join(map(str, version)) | |
new_version = 'version = ' + version_string | |
lines = lines.replace(old_version, new_version) | |
file.write_text(lines) | |
Path(".version").write_text(version_string) | |
EOF | |
- name: commit and tag new version | |
run: | | |
set -x | |
git fetch --tags | |
COMMIT_MSG='autocommit by github action' | |
if [ $(git log -n1 | grep -q "$COMMIT_MSG") ]; then | |
echo "No new commit" | |
echo "DO_PYPI=0" >> "$GITHUB_ENV" | |
else | |
git add . | |
git commit -am "$COMMIT_MSG" | |
VERSION=$(cat .version) | |
git tag ${VERSION} | |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY | |
git push origin --tags | |
git push | |
python3 setup.py sdist | |
echo "DO_PYPI=1" >> "$GITHUB_ENV" | |
fi | |
- name: Publish to PyPi | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
if: env.DO_PYPI == '1' |