Bump version: 0.1.4 → 0.1.5 (#25) #77
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: Build, test and publish | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [ "3.8", "3.9", "3.10", "3.11" ] | |
steps: | |
- name: Install libegl1 | |
run: sudo apt-get install -y libegl1 | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Set up python | |
id: setup-python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
installer-parallel: true | |
- name: Load cached venv | |
id: cached-poetry-dependencies | |
uses: actions/cache@v3 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} | |
- name: Install dependencies | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction --no-root | |
- name: Install project | |
run: poetry install --no-interaction | |
- name: Lint with isort, black and flake8 | |
run: | | |
poetry run isort visprompt | |
poetry run isort tests | |
poetry run black visprompt | |
poetry run black tests | |
poetry run flake8 visprompt | |
poetry run flake8 tests | |
continue-on-error: true | |
- name: Test with pytest | |
run: | | |
poetry run coverage erase | |
poetry run coverage run -a --source=./visprompt --branch -m pytest -s -v --black --isort tests --junit-xml=junit/test-results-${{ matrix.python-version }}.xml | |
poetry run coverage report | |
poetry run coverage xml | |
check_version_change: | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
outputs: | |
should_publish: ${{ steps.compare_versions.outputs.should_publish }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Fetch main branch (current and before merge) | |
run: | | |
git fetch origin ${{ github.event.before }}:refs/remotes/origin/main-before | |
git fetch origin main:refs/remotes/origin/main-current | |
- name: Get version from main before merge | |
id: main_previous_version | |
run: | | |
git checkout refs/remotes/origin/main-before | |
MAIN_PREVIOUS_VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml) | |
echo "Main previous version: $MAIN_PREVIOUS_VERSION" | |
echo "::set-output name=main_previous_version::$MAIN_PREVIOUS_VERSION" | |
- name: Get version from main current | |
id: main_current_version | |
run: | | |
git checkout refs/remotes/origin/main-current | |
MAIN_CURRENT_VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml) | |
echo "Main current version: $MAIN_CURRENT_VERSION" | |
echo "::set-output name=main_current_version::$MAIN_CURRENT_VERSION" | |
- name: Compare versions and set flag | |
id: compare_versions | |
run: | | |
if [[ "${{ steps.main_previous_version.outputs.main_previous_version }}" != "${{ steps.main_current_version.outputs.main_current_version }}" ]]; then | |
echo "Version changed from ${{ steps.main_previous_version.outputs.main_previous_version }} to ${{ steps.main_current_version.outputs.main_current_version }}." | |
echo "::set-output name=should_publish::true" | |
else | |
echo "No version change detected." | |
echo "::set-output name=should_publish::false" | |
fi | |
publish: | |
needs: [build_and_test, check_version_change] | |
if: needs.check_version_change.outputs.should_publish == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up python | |
id: setup-python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
installer-parallel: true | |
- name: Load cached venv | |
uses: actions/cache@v3 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-3.x-${{ hashFiles('**/poetry.lock') }} | |
- name: Install dependencies | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: poetry install --no-interaction --no-root | |
- name: Install project | |
run: poetry install --no-interaction | |
- name: Publish to PyPI | |
env: | |
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
poetry config pypi-token.pypi ${{ secrets.PYPI_API_TOKEN }} | |
poetry publish --build |