diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 7ee4021b4..34f98ea7b 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -5,7 +5,9 @@ name: Report something is not working properly 🐛 description: Use this if there is something that is not working properly. If you are not sure or you need help making something work, please ask a question instead. -labels: [ priority:❓, type:bug ] +labels: + - "priority:❓" + - "type:bug" body: - type: markdown attributes: diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml index 709be6996..459dd4b17 100644 --- a/.github/ISSUE_TEMPLATE/feature.yml +++ b/.github/ISSUE_TEMPLATE/feature.yml @@ -3,7 +3,10 @@ name: Request a feature or enhancement ✨ description: Use this if something is missing or could be done better or more easily. -labels: [ part:❓, priority:❓, type:enhancement ] +labels: + - "part:❓" + - "priority:❓" + - "type:enhancement" body: - type: markdown attributes: diff --git a/.github/RELEASE_NOTES.template.md b/.github/RELEASE_NOTES.template.md new file mode 100644 index 000000000..afb10a8ef --- /dev/null +++ b/.github/RELEASE_NOTES.template.md @@ -0,0 +1,17 @@ +# Release Notes + +## Summary + + + +## Upgrading + + + +## New Features + + + +## Bug Fixes + + diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3a7c97b28..b4e1bdb16 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,85 +1,132 @@ name: frequenz-sdk-python -on: - push: - branches: [ v0.x.x ] - - pull_request: - -env: - REGISTRY: ghcr.io +on: [pull_request, push, workflow_dispatch] jobs: test: strategy: fail-fast: false matrix: - python: [ "3.8", "3.9", "3.10" ] - os: [ ubuntu-20.04 ] - + os: + - ubuntu-20.04 + python: + - "3.8" + - "3.9" + - "3.10" runs-on: ${{ matrix.os }} steps: - name: Fetch sources - uses: actions/checkout@v2 - with: - token: ${{ secrets.CI_ACCESS_TOKEN || github.token }} - submodules: true + uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/minimum-requirements-ci.txt') }} + key: ${{ runner.os }}-${{ matrix.python-version }}-pip-${{ hashFiles('minimum-requirements-ci.txt', 'pyproject.toml') }} restore-keys: | - ${{ runner.os }}-pip- + ${{ runner.os }}-${{ matrix.python-version }}-pip- - name: Install required Python packages run: | python -m pip install --upgrade pip - python -m pip install nox wheel + python -m pip install nox - name: run nox run: nox -e ci_checks_max pytest_min timeout-minutes: 10 - build-wheels: + build-dist: runs-on: ubuntu-20.04 - needs: test + steps: + - name: Fetch sources + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install build dependencies + run: | + python -m pip install -U pip + python -m pip install -U build + + - name: Build the source and binary distribution + run: python -m build + - name: Upload dist files + uses: actions/upload-artifact@v3 + with: + name: frequenz-sdk-python-dist + path: dist/ + if-no-files-found: error + + create-github-release: + needs: ["test", "build-dist"] + # Create a release only on tags creation + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + permissions: + # We need write permissions on contents to create GitHub releases and on + # discussions to create the release announcement in the discussion forums + contents: write + discussions: write + runs-on: ubuntu-20.04 steps: - - name: Fetch sources - uses: actions/checkout@v2 - with: - token: ${{ secrets.CI_ACCESS_TOKEN || github.token }} - submodules: true - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: 3.8 - - - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/minimum-requirements-ci.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Install required Python packages - run: | - python -m pip install --upgrade pip - python -m pip install wheel - - - name: make wheel - run: python -m pip wheel --no-deps -w dist . - - - name: upload wheels - uses: actions/upload-artifact@v2 - with: - name: frequenz-sdk-python-wheels - path: dist/*.whl + - name: Download dist files + uses: actions/download-artifact@v3 + with: + name: frequenz-sdk-python-dist + path: dist + + - name: Download RELEASE_NOTES.md + run: | + set -ux + gh api \ + -X GET \ + -f ref=$REF \ + -H "Accept: application/vnd.github.raw" \ + "/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \ + > RELEASE_NOTES.md + env: + REF: ${{ github.ref }} + REPOSITORY: ${{ github.repository }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create GitHub release + run: | + set -ux + extra_opts= + if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi + gh release create \ + -R "$REPOSITORY" \ + --discussion-category announcements \ + --notes-file RELEASE_NOTES.md \ + --generate-notes \ + $extra_opts \ + $REF_NAME \ + dist/* + env: + REF_NAME: ${{ github.ref_name }} + REPOSITORY: ${{ github.repository }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish-to-pypi: + needs: ["create-github-release"] + runs-on: ubuntu-20.04 + steps: + - name: Download dist files + uses: actions/download-artifact@v3 + with: + name: frequenz-sdk-python-dist + path: dist + + - name: Publish the Python distribution to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} + skip_existing: true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..e1f009821 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,83 @@ +# Contributing to `frequenz-sdk` + +## Build + +You can use `build` to simply build the source and binary distribution: + +```sh +python -m pip install build +python -m build +``` + +## Local development + +You can use editable installs to develop the project locally (it will install +all the dependencies too): + +```sh +python -m pip install -e . +``` + +You can also use `nox` to run the tests and other checks: + +```sh +python -m pip install nox +nox +``` + +You can also use `nox -R` to reuse the current testing environment to speed up +test at the expense of a higher chance to end up with a dirty test environment. + +### Running tests individually + +For a better development test cycle you can install the runtime and test +dependencies and run `pytest` manually. + +```sh +python -m pip install . +python -m pip install pytest pytest-asyncio + +# And for example +pytest tests/test_sdk.py +``` + +## Releasing + +These are the steps to create a new release: + +1. Get the latest head you want to create a release from. + +2. Update the `RELEASE_NOTES.md` file if it is not complete, up to date, and + clean from template comments (`