From 98cf819b80b39afcd0755e92a88aa68ec096961d Mon Sep 17 00:00:00 2001 From: Peder Hovdan Andresen <107681714+pederhan@users.noreply.github.com> Date: Wed, 12 Jun 2024 11:00:16 +0200 Subject: [PATCH] Add publishing workflow and contribution instructions (#254) * Publishing * Add branch condition to publish workflow * Wording * Remove usage of requirements.txt files * Add basepython resolution for numbered envs * Use uv in tox workflows * Unfinished publish workflow * trying stuff * Do not specify tox env in build workflow * Move pyinstaller dependency to tox * Actually run tox * Fix binary dist path * Revert incorrect binary path * Fix underscore in artifact name * verbose pypi * Use test pypi * Use `mreg-cli-v*` tag pattern * Dump workflow info * Add branch check * Try to create release * Try to use trusted publishing * Remove unused pypi vars * Try to rename binaries * Try to actually read actions docs * Fix bin name * Publish a4 * Rename binary after creation * Remove publishing branch * Make built binary executable * Remove executable step * Build on master and publish to real pypi * Update publishing instructions * Exit explicitly only on master branch * Add artifact and version info, move `-desc`to Removed * Final publishing test run * Enable master protection again * Make GitHub release non-prelease * Add missing newline * Fix CONTRIBUTING markdown lint violations Does not "fix" the ordered list rule violation, since indenting the code blocks looks very awkward. --- .github/workflows/publish.yml | 124 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 5 +- CHANGELOG | 36 ++++++++++ CONTRIBUTING | 32 +++++++++ pyproject.toml | 2 +- tox.ini | 11 +-- 6 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 CHANGELOG create mode 100644 CONTRIBUTING diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..a14427f2 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,124 @@ +name: build mreg-cli + +on: + push: + tags: + - mreg-cli-v* + +concurrency: + group: build-mreg-cli-${{ github.head_ref }} + +jobs: + build_pypi: + name: Build wheels and source distribution + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Exit if not on master branch + if: github.ref_name != 'master' + run: exit -1 + + - name: Install build dependencies + run: python -m pip install --upgrade build + + - name: Build source distribution + run: python -m build + + - uses: actions/upload-artifact@v4 + with: + name: pypi_artifacts + path: dist/* + if-no-files-found: error + + build_pyinstaller: + name: Build pyinstaller binary + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-22.04, windows-latest, macos-latest] + python-version: + - '3.12' + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Run PyInstaller with Tox + run: | + python -m ensurepip --upgrade + python -m pip install tox tox-uv tox-gh-actions + tox + + - name: Rename binary + run: | + mv dist/mreg-cli${{ contains(matrix.os, 'windows') && '.exe' || '' }} dist/mreg-cli-${{ matrix.os }}-${{ matrix.python-version }}${{ contains(matrix.os, 'windows') && '.exe' || '' }} + + - uses: actions/upload-artifact@v4 + with: + name: mreg-cli-${{ matrix.os }}-${{ matrix.python-version }}${{ contains(matrix.os, 'windows') && '.exe' || '' }} + path: dist/mreg-cli-${{ matrix.os }}-${{ matrix.python-version }}${{ contains(matrix.os, 'windows') && '.exe' || '' }} + if-no-files-found: error + + publish_pypi: + name: Publish PyPI release + needs: + - build_pypi + runs-on: ubuntu-latest + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: pypi_artifacts + path: dist + + - name: Push build artifacts to PyPI + uses: pypa/gh-action-pypi-publish@v1.8.14 + + publish_github: + name: Publish GitHub release + needs: + - build_pypi + - build_pyinstaller + runs-on: ubuntu-latest + + steps: + - name: Download PyInstaller binaries + uses: actions/download-artifact@v4 + with: + pattern: mreg-cli-* + path: dist + merge-multiple: true + + - name: Download wheel and source distributions + uses: actions/download-artifact@v4 + with: + pattern: pypi_artifacts + path: dist + merge-multiple: true + + - name: Create GitHub release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body: | + Release notes for ${{ github.ref }} + draft: false + prerelease: false + + - name: Upload release asset + id: upload-release-asset + uses: softprops/action-gh-release@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + files: dist/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d0269a5..36879ae8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,6 @@ jobs: - name: Install mreg-cli run: | python -m ensurepip --upgrade - pip install -r requirements.txt pip install -e . - name: Test and compare api calls run: ci/run_testsuite_and_record.sh @@ -54,9 +53,7 @@ jobs: - name: Install dependencies run: | python -m ensurepip --upgrade - python -m pip install tox tox-gh-actions - python -m pip install -r requirements.txt - python -m pip install -r requirements-dev.txt + python -m pip install tox tox-uv tox-gh-actions - name: Test with tox run: tox r \ No newline at end of file diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 00000000..4c457811 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,36 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +The big Pydantic update. The entire codebase has been rewritten to use Pydantic for request and response validation. This brings with it a huge improvement to the development experience and the robustness of the code. + +### Added + +- `--version` option to display current application version and exit. + Version number is in the form of `major.minor.patch` if installed from a published version. + Shows a version number including the commit hash if installed from a git repository in the form of `major.minor.patch.dev123+gabc1234`. + See [Default versioning scheme](https://setuptools-scm.readthedocs.io/en/latest/usage/#default-versioning-scheme) in the [setuptools_scm](https://github.com/pypa/setuptools_scm/) documentation for more information. + - The version can be accessed programmatically with `mreg_cli.__version__`. +- `label set_description` command to set the description of a label. +- `network list_excluded_ranges` command to list the excluded ranges of a network. +- Application can now store tokens for multiple servers and will pick the correct one based on the server URL. +- Building binaries for Windows, Linux and MacOS, and publishing the package to PyPI on each GitHub release. + +### Changed + +- The application now uses Pydantic internally to validate request and response data. This should make the code more robust and easier to maintain. +- Application now attempts to send JSON for every request. This should improve the consistency of the API responses. +- Version now follows Semantic Versioning 2.0.0 and is automatically determined based on the most recent git tag (`mreg-cli-v*`). As part of this change, the verison has been bumped from 0.9.10 to 1.0.0. See the Added section for more information on how version numbers are accessed. + +### Removed + +- `label rename -desc` option. Description modification is now done through the new `label set_description` command. + +### Fixed + +- Hopefully more than we broke. diff --git a/CONTRIBUTING b/CONTRIBUTING new file mode 100644 index 00000000..b469a62b --- /dev/null +++ b/CONTRIBUTING @@ -0,0 +1,32 @@ +# Contributing + +If you would like to contribute to this project, please follow these steps: + +1. Fork the repository +2. Create a new branch (`git checkout -b feature/branch-name`) +3. Make changes +4. Commit your changes (`git commit -am 'Add some feature'`) +5. Push to the branch (`git push origin feature/branch-name`) +6. Create a Pull Request + +## Publishing + +Publishing new versions is automatically handled by GitHub actions for versions tagged with `mreg-cli-v*` (e.g. `mreg-cli-v1.0.0`). If you are a maintainer, you can create a new release by following these steps: + +1. Switch to the `master` branch: + +```bash +git checkout master +``` + +2. Create a new tag: + +```bash +git tag mreg-cli-v1.2.3 +``` + +3. Push the tag to the upstream repository: + +```bash +git push upstream mreg-cli-v1.2.3 +``` diff --git a/pyproject.toml b/pyproject.toml index 2d862094..379a84ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ dynamic = ["version"] [project.optional-dependencies] -dev = ["ruff", "tox", "pyinstaller"] +dev = ["ruff", "tox"] [project.urls] Repository = 'https://github.com/unioslo/mreg-cli/' diff --git a/tox.ini b/tox.ini index 489ccc47..d25c9c59 100644 --- a/tox.ini +++ b/tox.ini @@ -32,13 +32,16 @@ commands = [testenv] skip_install = false -description = Test building binary with pyinstaller +description = Build binary with pyinstaller for {basepython} basepython = python311: python3.11 python312: python3.12 -deps = - -r{toxinidir}/requirements.txt - -r{toxinidir}/requirements-dev.txt + 3.11: python3.11 + 3.12: python3.12 +extras = + dev +deps = + pyinstaller allowlist_externals = pyinstaller commands =