diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 3a85978b..3554c7e6 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -2,9 +2,9 @@ name: Python package on: push: - branches: [master, main] + branches: [master, main, '*.x'] pull_request: - branches: [master, main] + branches: [master, main, '*.x'] jobs: build-lint-unit-test: @@ -49,7 +49,16 @@ jobs: release: runs-on: ubuntu-latest needs: [build-lint-unit-test, integration-test] - if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main') + if: > + github.event_name == 'push' && + ( + github.ref == 'refs/heads/master' || + github.ref == 'refs/heads/main' || + ( + startsWith(github.ref, 'refs/heads/') && + endsWith(github.ref, '.x') + ) + ) steps: - uses: actions/checkout@v3 with: @@ -64,9 +73,29 @@ jobs: - run: poetry install - name: Semantic release run: | - pip install python-semantic-release==7.34.6 + pip install python-semantic-release==10.6.1 git config --global user.name "github-actions" git config --global user.email "action@github.com" + semantic-release version + env: + # To generate a new token use the following guide, providing access to the "repo" scope. + # https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token + # Once you update the secret on the repo, ensure you update the master/main protected branch policy + # to allow your user permission to "bypass required pull requests". + GH_TOKEN: ${{secrets.GH_TOKEN}} + - name: Publish package distributions to PyPI using Twine + # Only publish if Semantic release built packages under "dist/"; hashFiles returns '' when no files match the given pattern. + if: hashFiles('dist/*') != '' + run: | + pip install twine==6.1.0 + python -m twine upload dist/* + env: + TWINE_USERNAME: ${{secrets.REPOSITORY_USERNAME}} + TWINE_PASSWORD: ${{secrets.PYPI_PASSWORD}} + - name: Semantic release - Publish package distributions to GitHub Releases + # Only publish if Semantic release built packages under "dist/"; hashFiles returns '' when no files match the given pattern. + if: hashFiles('dist/*') != '' + run: | semantic-release publish env: # To generate a new token use the following guide, providing access to the "repo" scope. @@ -74,5 +103,3 @@ jobs: # Once you update the secret on the repo, ensure you update the master/main protected branch policy # to allow your user permission to "bypass required pull requests". GH_TOKEN: ${{secrets.GH_TOKEN}} - REPOSITORY_USERNAME: ${{secrets.REPOSITORY_USERNAME}} - REPOSITORY_PASSWORD: ${{secrets.PYPI_PASSWORD}} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2cff0378..1f536ea4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,6 +35,28 @@ To contribute to this project, it is recommended that you follow these steps: 6. Send a GitHub Pull Request to the main repository's master branch. GitHub Pull Requests are the expected method of code collaboration on this project. +## Patching older versions +1. Contact the [repository owners](https://github.com/ni/nisystemlink-clients-python/blob/master/.github/CODEOWNERS) for approval and ask them to create a + branch based on the commit that was used to generate the release to be patched. + The naming for this branch should follow this guideline: + - "1.x", if we want to create a new minor version for version 1 + - "1.3.x", if we want to create a new patch version for version 1.3 + +2. Fork the repository on GitHub. +3. Fetch and check out the maintenance branch created in step 1, then create and + switch to a working branch from it. +4. Run the unit tests on your system (see Testing section). At this point, + if any tests fail, do not begin development. Try to investigate these + failures. If you're unable to do so, report an issue through our + [GitHub issues page](https://github.com/ni/nisystemlink-clients-python/issues). +5. Write new tests that demonstrate your bug or feature. Ensure that these + new tests fail. +6. Make your change. +7. Run all the unit tests again (which include the tests you just added), + and confirm that they all pass. +8. Send a GitHub Pull Request to the main repository branch that was created as a result of step 1. GitHub + Pull Requests are the expected method of code collaboration on this project. + ## Testing Before running any tests, you must have a supported version of Python (3.10+) and [Poetry](https://python-poetry.org/docs/) installed locally. diff --git a/pyproject.toml b/pyproject.toml index 513a8661..5b553050 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,10 +84,16 @@ markers = [ exclude = ".*\\.pyi" [tool.semantic_release] -branch = "master" version_toml = ["pyproject.toml:tool.poetry.version"] build_command = "poetry build" +# Allow releasing from the `master` branch. +[tool.semantic_release.branches.master] +match = "^master$" + +# Allow releasing from maintenance branches named "1.x", "1.2.x", etc. +[tool.semantic_release.branches.maintenance] +match = "^\\d+(?:\\.\\d+)*\\.x$" [build-system]