Skip to content

Commit

Permalink
Improve CI workflow
Browse files Browse the repository at this point in the history
- Split workflows into `test` and `deploy`
- We generate the package once, and test it in the different environments
- Deployment is done via manual trigger, which requires approval and takes care of pushing the release tag and creating a GH release only after the package has been uploaded to PyPI.

This is the workflow that we have been adopting in other pytest plugins at pytest-dev.
  • Loading branch information
nicoddemus committed Sep 28, 2023
1 parent 2f2d047 commit 253b6d8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 44 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: deploy

on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
default: '1.2.3'

jobs:

package:
runs-on: ubuntu-latest
env:
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ github.event.inputs.version }}

steps:
- uses: actions/checkout@v3

- name: Build and Check Package
uses: hynek/build-and-inspect-python-package@v1.5

deploy:
needs: package
runs-on: ubuntu-latest
environment: deploy
permissions:
id-token: write # For PyPI trusted publishers.
contents: write # For tag and release notes.

steps:
- uses: actions/checkout@v3

- name: Download Package
uses: actions/download-artifact@v3
with:
name: Packages
path: dist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@v1.8.5

- name: Push tag
run: |
git config user.name "pytest bot"
git config user.email "pytestbot@gmail.com"
git tag --annotate --message=v${{ github.event.inputs.version }} v${{ github.event.inputs.version }} ${{ github.sha }}
git push origin v${{ github.event.inputs.version }}
- name: GitHub Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
tag_name: v${{ github.event.inputs.version }}
55 changes: 24 additions & 31 deletions .github/workflows/main.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build
name: test

on:
push:
Expand All @@ -14,7 +14,17 @@ concurrency:
cancel-in-progress: true

jobs:
build:

package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build and Check Package
uses: hynek/build-and-inspect-python-package@v1.5

test:

needs: [package]

runs-on: ${{ matrix.os }}

Expand All @@ -37,41 +47,24 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Download Package
uses: actions/download-artifact@v3
with:
name: Packages
path: dist

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}

- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Test
run: |
tox -e ${{ matrix.tox_env }}
deploy:

if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
pip install tox
runs-on: ubuntu-latest

needs: build

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Install wheel
run: |
python -m pip install --upgrade pip
python -m pip install build
- name: Build package
- name: Test
shell: bash
run: |
python -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.pypi_token }}
tox run -e ${{ matrix.tox_env }} --installpkg `find dist/*.tar.gz`
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,6 @@ pytest-datadir will copy the original file to a temporary folder, so changing th

Both `datadir` and `shared_datadir` fixtures are `pathlib.Path` objects.

# Releases

Follow these steps to make a new release:

1. Create a new branch `release-X.Y.Z` from `master`.
2. Update `CHANGELOG.rst`.
3. Open a PR.
4. After it is **green** and **approved**, push a new tag in the format `X.Y.Z`.

Travis will deploy to PyPI automatically.

Afterwards, update the recipe in [conda-forge/pytest-datadir-feedstock](https://github.com/conda-forge/pytest-datadir-feedstock).

# License

MIT.
7 changes: 7 additions & 0 deletions RELEASING.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Here are the steps on how to make a new release.

1. Create a ``release-VERSION`` branch from ``upstream/master``.
2. Update ``CHANGELOG.rst``.
3. Push the branch to ``upstream``.
4. Once all tests pass, start the ``deploy`` workflow manually.
5. Merge the PR.

0 comments on commit 253b6d8

Please sign in to comment.