Merge pull request #26 from timmyb824/ci/ci-add-conditional3 #44
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: 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: Set Git config | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
- name: Semantic Release Version | |
shell: bash | |
id: version | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
VERSION=$(poetry run semantic-release version) | |
echo "VERSION_OUTPUT<<EOF" >> $GITHUB_ENV | |
echo "$VERSION" >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
echo ${{ env.VERSION_OUTPUT }} | |
- name: Check release output and terminate if no new version | |
if: contains(${{ env.VERSION_OUTPUT }}, 'No new version to release') && contains(${{ env.VERSION_OUTPUT }}, 'has already been released!') | |
run: | | |
echo "No new version to release. Ending workflow." | |
exit 0 | |
- name: Semantic Release Publish | |
id: package_release | |
shell: bash | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
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: 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' |