Add test suites #9
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: Publish to PyPI | |
on: | |
workflow_dispatch: | |
pull_request: | |
paths: | |
- "src/**" | |
- "tests/**" | |
- ".github/workflows/test_suite.yml" | |
push: | |
tags: | |
- "v*" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.10", "3.11", "3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install pytest pytest-cov pytest-asyncio | |
pip install -r requirements.txt | |
pip install -e . | |
- name: Run tests | |
run: | | |
pytest tests/ -v --cov=web_search --cov-report=xml | |
- name: Upload coverage reports to Codecov | |
uses: codecov/codecov-action@v3 | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
build-and-publish: | |
needs: test | |
runs-on: ubuntu-latest | |
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || github.event_name == 'workflow_dispatch' | |
environment: | |
name: pypi | |
url: https://pypi.org/p/async-web-search | |
permissions: | |
id-token: write # Required for PyPI trusted publishing | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.12" | |
- name: Install package & build dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
pip install build twine | |
- name: Build package | |
run: python -m build | |
- name: Check package | |
run: twine check dist/* | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
verify-metadata: false | |
verbose: true | |
print-hash: true | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} | |
create-release: | |
needs: build-and-publish | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get version from tag | |
id: get_version | |
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
- name: Generate changelog | |
id: changelog | |
run: | | |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
if [ -z "$PREVIOUS_TAG" ]; then | |
git log --pretty=format:"* %s" > CHANGELOG.md | |
else | |
git log --pretty=format:"* %s" $PREVIOUS_TAG..HEAD > CHANGELOG.md | |
fi | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
name: Release v${{ steps.get_version.outputs.VERSION }} | |
body_path: CHANGELOG.md | |
draft: false | |
prerelease: false |