From fc34bc4297559bfb447546cc57c8e9b8cc9be5af Mon Sep 17 00:00:00 2001 From: Stephen Jolly Date: Thu, 20 Jun 2024 09:39:39 +0100 Subject: [PATCH 1/2] Add Github Action to semi-automatically publish a package to PyPI The workflow runs whenever a new release is created, which is a manual process. The workflow runs in the "release" environment, which will be configured to require an additional manual approval step from someone other than the person who creates the release. --- .github/workflows/publish.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..e05c67d --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,30 @@ +name: Upload Package to PyPI when a Release is Created + +on: + release: + types: [created] + +jobs: + pypi-publish: + name: Publish release to PyPI + runs-on: ubuntu-latest + environment: + name: release + url: https://pypi.org/p/audio-offset-finder + permissions: + id-token: write + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel + - name: Build package + run: | + python -m build + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 \ No newline at end of file From 9672940dc7b81c7ce2c07c60ef9f4df58a145472 Mon Sep 17 00:00:00 2001 From: Stephen Jolly Date: Thu, 20 Jun 2024 12:24:08 +0100 Subject: [PATCH 2/2] Ensure that the code passes basic lint / unit tests before publishing Technically this is redundant because the same checks are run every time changes are merged, but better safe than sorry. --- .github/workflows/publish.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e05c67d..c7cced2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,6 +15,10 @@ jobs: id-token: write steps: - uses: actions/checkout@v4 + - name: Install FFMPEG + run: | + sudo apt-get update + sudo apt install -y ffmpeg - name: Set up Python uses: actions/setup-python@v4 with: @@ -22,7 +26,14 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel + pip install setuptools wheel pytest + - name: Lint with black + uses: psf/black@stable + with: + version: "22.3.0" + - name: Test with pytest + run: | + pytest - name: Build package run: | python -m build