Skip to content

Commit

Permalink
Publish tagged commits to PyPI
Browse files Browse the repository at this point in the history
  • Loading branch information
mx-moth committed Feb 7, 2023
1 parent 781f0fe commit 2c5679d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 20 deletions.
15 changes: 11 additions & 4 deletions .github/actions/environment/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ runs:

steps:
# Used for the pip cache, not for the python version
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
cache: 'pip'
python-version: ${{ inputs.python-version }}

- name: Fetch Python package
uses: actions/download-artifact@v3
with:
name: "Python package"
path: "dist/"

- name: Install base Conda environment
uses: mamba-org/provision-with-micromamba@main
with:
cache-downloads: true
cache-env: true
cache-env: false
channels: conda-forge
environment-file: continuous-integration/environment.yaml
environment-name: continuous-integration
Expand All @@ -27,9 +34,9 @@ runs:
wheel
pip
- name: Install Python dependencies
- name: Install Python packages
shell: bash -l {0}
run: |
pip install \
-r continuous-integration/requirements.txt \
-e .
dist/emsarray-*.whl
80 changes: 64 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,52 @@
name: pytest
name: Build, test, and lint
on:
push:
branches:
- main
tags:
- "v[0-9]+.*"
pull_request:
branches:
- "*"

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
env:
python_version: "3.11"
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ env.python_version }}
cache: 'pip'

- name: Build python package
shell: bash -l {0}
run: |
pip install build
python3 -m build
- uses: actions/upload-artifact@v3
with:
name: "Python package"
path: dist

test:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: ["build"]

strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/environment
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -31,10 +60,11 @@ jobs:
--cov-report xml:coverage-${{ matrix.python-version }}.xml
- name: JUnit Report
uses: mikepenz/action-junit-report@v3.1.0
uses: mikepenz/action-junit-report@v3
if: always()
with:
report_paths: 'junit-py*.xml'
check_name: "JUnit Test Report - Python ${{ matrix.python-version }}"

- uses: actions/upload-artifact@v3
with:
Expand All @@ -44,6 +74,7 @@ jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: ["build"]

defaults:
run:
Expand All @@ -53,7 +84,7 @@ jobs:
python_version: "3.11"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/environment
with:
python-version: ${{ env.python_version }}
Expand All @@ -71,13 +102,14 @@ jobs:
docs:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: ["build"]

defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: ./.github/actions/environment
with:
python-version: "3.11"
Expand All @@ -91,21 +123,37 @@ jobs:
name: Docs
path: docs/_build/dirhtml

package:
publish:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: ['test', 'lint', 'docs']
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/environment
- name: Fetch Python package
uses: actions/download-artifact@v3
with:
python-version: "3.11"

- run: |
pip install build
python3 -m build
name: "Python package"
path: "dist"

- uses: actions/upload-artifact@v3
- name: "Check tag matches version"
shell: bash -l {0}
run: |
VERSION="$( echo "${{ github.ref }}" | sed 's!refs/tags/v!!' )"
echo "Looking for packages with version $VERSION"
ls -l dist/*
packages=(
"dist/emsarray-$VERSION.tar.gz"
"dist/emsarray-$VERSION-*.whl"
)
for package in "${packages[@]}" ; do
if ! test -e $package ; then
echo "Could not find $package"
exit 1
fi
done
- name: "Publish Python package"
uses: pypa/gh-action-pypi-publish@release/v1
with:
name: Python packages
path: dist
password: ${{ secrets.PYPI_API_TOKEN }}

0 comments on commit 2c5679d

Please sign in to comment.