check based on env #730
Workflow file for this run
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 Tag | |
# Runs on every push to run the unit tests. | |
# Additionally, if on main, reads the current version from setup.py and then creates a new tag and release named | |
# for that version. | |
# If a tag already exists with that name, the Create Release step is skipped. | |
on: | |
workflow_dispatch: | |
push: | |
paths-ignore: | |
- "**/README.md" | |
jobs: | |
run-unit-tests: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
# If updating this list of python versions, you also need to update tox config in pyproject.toml | |
python-version: ['3.10', '3.11', '3.12'] | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install -r requirements-test.txt | |
- name: Run tests | |
run: | | |
tox | |
create-release: | |
runs-on: ubuntu-latest | |
needs: run-unit-tests | |
if: github.ref == 'refs/heads/main' | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup python | |
id: setup_python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Get package version | |
id: package_version | |
run: echo "app_version="$(python setup.py --version) >> $GITHUB_OUTPUT | |
- name: Check if tag exists | |
uses: mukunku/[email protected] | |
id: check_tag | |
with: | |
tag: ${{ steps.package_version.outputs.app_version }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- uses: ncipollo/[email protected] | |
name: Create Release | |
id: create_release | |
if: ${{ steps.check_tag.outputs.exists == 'false' }} | |
with: | |
commit: main | |
tag: ${{ steps.package_version.outputs.app_version }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
publish-release: | |
runs-on: ubuntu-latest | |
needs: create-release | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup python | |
id: setup_python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Build for publish | |
id: build_dist | |
run: | | |
python -m pip install --upgrade pip && pip install build | |
python -m build | |
echo workspace dir $GITHUB_WORKSPACE | |
- name: Publish to PyPI | |
id: publish-to-pypi | |
uses: pypa/[email protected] | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} |