Skip to content

Merge pull request #24 from timmyb824/ci/ci-add-conditional #40

Merge pull request #24 from timmyb824/ci/ci-add-conditional

Merge pull request #24 from timmyb824/ci/ci-add-conditional #40

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
jobs:
Test:
environment:
name: production
runs-on: ubuntu-latest
name: Build and Test
# env:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.11.2'
- name: Install poetry
shell: bash
run: |
python -m pip install poetry==1.5.1
- name: Configure poetry
shell: bash
run: |
python -m poetry config virtualenvs.in-project true
- name: Cache the virtualenv
uses: actions/cache@v3
with:
path: ./.venv
key: ${{ runner.os }}-venv-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
shell: bash
run: |
python -m poetry install --no-root
# - name: Code quality checks
# shell: bash
# run: |
# poetry run python -m black --check .
- name: Run unit tests
shell: bash
run: |
poetry run python -m pytest -xvvv tests/
- name: Test run the tool
if: success()
shell: bash
run: |
export PYTHONPATH="${PYTHONPATH}:./src"
python -m poetry run python src/main.py run -a
Release:
needs: Test
environment:
name: production
url: https://pypi.org/project/python-sysinformer/
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
name: Release
concurrency: Release
permissions:
id-token: write
contents: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: '3.11.2'
- name: Install poetry
shell: bash
run: |
python -m pip install poetry==1.5.1
- name: Install dependencies
shell: bash
run: |
python -m poetry install --no-root
- name: Prepare package for release
id: package_release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.name github-actions
git config user.email [email protected]
poetry run semantic-release version
delimiter="$(openssl rand -hex 8)"
POETRY_VERSION=$(poetry run semantic-release version)
echo "version-output<<${delimiter}" >> "${GITHUB_OUTPUT}"
echo "${POETRY_VERSION}" >> "${GITHUB_OUTPUT}"
echo "${delimiter}" >> "${GITHUB_OUTPUT}"
poetry run semantic-release changelog
poetry run semantic-release publish
# Unable to use at the moment due to the python version used by the action
# - name: Run Python Semantic Release
# id: release
# uses: python-semantic-release/python-semantic-release@master
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Check release output and terminate if no new version
if: contains(steps.package_release.outputs.version-output, 'No release will be made,') && contains(steps.package_release.outputs.version-output, 'has already been released!')
run: |
echo "No new version to release. Ending workflow."
exit 0
- name: Publish to TestPyPI
id: test_publish
if: steps.package_release.outcome == 'success'
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Test install from TestPyPI
if: steps.test_publish.outcome == 'success'
shell: bash
id: test_install
run: |
python -m pip install \
--index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple \
python-sysinformer
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
if: steps.test_install.outcome == 'success'