name: "๐Ÿ”จ Steffo's Python Poetry Workflow" on: push: branches: - main - master pull_request: branches: - main - master schedule: - cron: "14 10 * * 1" # Every monday at 10:14 AM release: types: - published workflow_dispatch: defaults: run: shell: bash jobs: analyze-codeql: name: "๐Ÿ” Perform CodeQL analysis" runs-on: ubuntu-latest if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} permissions: security-events: write actions: read contents: read steps: - name: "โฌ‡๏ธ Checkout repository" uses: actions/checkout@v3 - name: "๐Ÿ”จ Initialize CodeQL" uses: github/codeql-action/init@v1 with: languages: python - name: "๐Ÿ” Perform CodeQL analysis" uses: github/codeql-action/analyze@v1 analyze-pytest: name: "๐Ÿงช Test package" runs-on: ubuntu-latest if: ${{ github.event_name == 'push' || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} services: postgres: image: postgres env: POSTGRES_USER: username POSTGRES_PASSWORD: password POSTGRES_DB: db options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - "5432:5432" steps: - name: "โฌ‡๏ธ Checkout repository" uses: actions/checkout@v3 - name: "๐Ÿ”จ Setup Python" uses: actions/setup-python@v3 - name: "๐Ÿ”จ Setup Poetry" uses: abatilo/actions-poetry@v2.1.4 - name: "๐Ÿ”จ Setup Poetry Python environment" id: pyenv uses: Steffo99/actions-poetry-deps@0.2.3 - name: "๐Ÿงช Run tests" run: | source ${{ steps.pyenv.outputs.pyenv }}/activate pytest --verbose --cov=. --cov-report=html - name: "โฌ†๏ธ Upload coverage" uses: actions/upload-artifact@v3 with: name: "code-coverage-report" path: htmlcov build-package: name: "๐Ÿ“ฆ Build and publish Python package" runs-on: ubuntu-latest if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }} steps: - name: "โฌ‡๏ธ Checkout repository" uses: actions/checkout@v3 - name: "๐Ÿ”จ Setup Python" uses: actions/setup-python@v3 - name: "๐Ÿ”จ Setup Poetry" uses: abatilo/actions-poetry@v2.1.4 - name: "๐Ÿ”จ Setup Poetry Python environment" uses: Steffo99/actions-poetry-deps@0.2.3 - name: "๐Ÿ— Build package with Poetry" run: poetry build --no-interaction - name: "โฌ†๏ธ Upload code package as artifact" uses: actions/upload-artifact@v3 with: name: "package.tar.gz" path: dist/*.tar.gz - name: "โฌ†๏ธ Upload wheel package as artifact" uses: actions/upload-artifact@v3 with: name: "package.whl" path: dist/*.whl - name: "Publish Poetry package" run: poetry publish --no-interaction env: POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} build-docs: name: "๐Ÿ“” Build and publish documentation" runs-on: ubuntu-latest needs: build-package if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }} steps: - name: "โฌ‡๏ธ Checkout repository" uses: actions/checkout@v3 - name: "๐Ÿ”จ Setup Python" uses: actions/setup-python@v3 - name: "๐Ÿ”จ Setup Poetry" uses: abatilo/actions-poetry@v2.1.4 - name: "๐Ÿ”จ Setup Poetry Python environment" id: pyenv uses: Steffo99/actions-poetry-deps@0.2.3 - name: "๐Ÿ— Build HTML documentation with Sphinx" working-directory: docs/ run: | source ${{ steps.pyenv.outputs.pyenv }}/activate make html - name: "โฌ†๏ธ Upload docs artifact" uses: actions/upload-artifact@v3 with: name: "documentation" path: "docs/build/html/" - name: "๐ŸŒ๏ธ Publish build to GitHub Pages" uses: peaceiris/actions-gh-pages@v3.8.0 with: github_token: "${{ secrets.GITHUB_TOKEN }}" publish_dir: "docs/build/html/" enable_jekyll: false