diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml new file mode 100644 index 00000000..cf763e1b --- /dev/null +++ b/.github/workflows/analysis.yml @@ -0,0 +1,29 @@ +name: "Periodic analysis" + +on: + schedule: + # Change this in your project to a random time. + # Every monday at 06:09 UTC + - cron: "9 6 * * 1" + +jobs: + codeql: + name: "๐Ÿ” Perform CodeQL analysis" + runs-on: ubuntu-latest + + permissions: + security-events: write + actions: read + contents: read + + steps: + - name: "โฌ‡๏ธ Checkout repository" + uses: actions/checkout@v3 + + - name: "๐Ÿ”จ Initialize CodeQL" + uses: github/codeql-action/init@v2 + with: + languages: python + + - name: "๐Ÿ” Perform CodeQL analysis" + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..430d1c0f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,134 @@ +name: "Automated release" + +on: + push: + tags: + - "v*" + + +defaults: + run: + shell: bash + + +jobs: + tests: + uses: "./.github/workflows/tests.yml" + + build-package: + name: "๐Ÿ“ฆ Build Python package" + runs-on: ubuntu-latest + 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@v0.2.4 + + - name: "๐Ÿ— Build package with Poetry" + run: poetry build --no-interaction + + - name: "โฌ†๏ธ Upload code package to artifacts" + uses: actions/upload-artifact@v3 + with: + name: "Build" + path: dist/*.tar.gz + if-no-files-found: error + + - name: "โฌ†๏ธ Upload wheel package to artifacts" + uses: actions/upload-artifact@v3 + with: + name: "Build" + path: dist/*.whl + if-no-files-found: warn + + publish-github: + name: "๐ŸŒ Publish release on GitHub" + needs: + - "tests" + - "build-package" + runs-on: ubuntu-latest + steps: + - name: "โฌ‡๏ธ Download built packages from artifacts" + uses: actions/download-artifact@v3 + with: + name: "Build" + path: dist/ + + - name: "๐ŸŒ Create release" + uses: ncipollo/release-action@v1.10.0 + with: + artifactErrorsFailBuild: true + artifacts: dist/* + draft: true + generateReleaseNotes: true + + publish-pypi: + name: "๐ŸŒ Publish release on PyPI" + needs: + - "tests" + - "build-package" + runs-on: ubuntu-latest + steps: + - name: "โฌ‡๏ธ Download built packages from artifacts" + uses: actions/download-artifact@v3 + with: + name: "Build" + path: dist/ + + - name: "๐ŸŒ Upload package" + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: "__token__" + password: ${{ secrets.PYPI_TOKEN }} + + publish-docker: + name: "๐Ÿณ Build and publish Docker image on ghcr.io" + runs-on: ubuntu-latest + needs: + - "tests" + - "build-package" + steps: + - name: "Checkout repository" + uses: actions/checkout@v2 + + - name: "โ“ Find the release semantic version" + id: semver + uses: Steffo99/actions-semver@v0.3.4 + with: + string: ${{ github.ref_name }} + + - name: "๐Ÿ”จ Setup Buildx" + uses: docker/setup-buildx-action@v1 + + - name: "๐Ÿ”‘ Login to GitHub Containers" + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: "๐Ÿ”ฝ Find the lowercase name of the repository" + id: reponame + uses: ASzc/change-string-case-action@v2 + with: + string: ${{ github.repository }} + + - name: "๐Ÿ— Build and push the Docker image" + uses: docker/build-push-action@v2 + with: + target: "entrypoint" + tags: >- + ghcr.io/${{ steps.reponame.outputs.lowercase }}:${{ steps.semver.outputs.precedence }}, + ghcr.io/${{ steps.reponame.outputs.lowercase }}:${{ steps.semver.outputs.core }}, + ghcr.io/${{ steps.reponame.outputs.lowercase }}:${{ steps.semver.outputs.pair }}, + ghcr.io/${{ steps.reponame.outputs.lowercase }}:${{ steps.semver.outputs.major }}, + ghcr.io/${{ steps.reponame.outputs.lowercase }}:latest + push: true + diff --git a/.github/workflows/stefflow.yml b/.github/workflows/stefflow.yml deleted file mode 100644 index 9c43fe9d..00000000 --- a/.github/workflows/stefflow.yml +++ /dev/null @@ -1,166 +0,0 @@ -name: "๐Ÿ”จ Steffo's Python Poetry Workflow" - -on: - push: - branches: - - main - - master - pull_request: - branches: - - main - - master - schedule: - - cron: "13 10 * * 1" # Every monday at 10:10 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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..08644afd --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,89 @@ +name: "Test suite" + +on: + push: + branches: + - main + - master + pull_request: + branches: + - main + - master + workflow_call: + + +defaults: + run: + shell: bash + +jobs: + pytest: + name: "๐Ÿงช Test package using pytest" + runs-on: ubuntu-latest + + # If you need a database to perform your tests + # 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@v0.2.4 + + - 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: "Coverage" + path: htmlcov + + # If you do not want to use unit testing + # syntax: + # name: "๐Ÿงช Check the package's syntax" + # runs-on: ubuntu-latest + # + # steps: + # - name: "โฌ‡๏ธ Checkout repository" + # uses: actions/checkout@v3 + # + # - name: "๐Ÿ”จ Setup Python" + # uses: actions/setup-python@v3 + # with: + # python-version: '3.8' + # + # - name: "๐Ÿ”จ Setup Poetry" + # uses: abatilo/actions-poetry@v2.1.4 + # + # - name: "๐Ÿ”จ Setup Poetry Python environment" + # id: pyenv + # uses: Steffo99/actions-poetry-deps@v0.2.4 + # + # - name: "๐Ÿงช Run check" + # run: | + # source ${{ steps.pyenv.outputs.pyenv }}/activate + # python -m compileall thorunimore