Skip to content

Commit

Permalink
Merge pull request #211 from blaylockbk/178-can-i-use-gh-action-pypi-…
Browse files Browse the repository at this point in the history
…publish

Workflow to automatically upload releases to PyPI
  • Loading branch information
blaylockbk committed Dec 15, 2023
2 parents 58a4d49 + a71ee7a commit e7cfcce
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 240 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: Lint
name: Lint with Black

on: [push, pull_request]
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: psf/black@stable
11 changes: 7 additions & 4 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Python Package using Conda

# THIS WORKFLOW IS NOT USED BECAUSE IT TAKES TOO LONG
# FOR CONDA TO CREATE THE ENVIRONMENT.

on:
#push:
# branches: [master]
Expand All @@ -12,12 +15,12 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Add conda to system path
Expand All @@ -26,7 +29,7 @@ jobs:
echo $CONDA/bin >> $GITHUB_PATH
- name: Install dependencies
run: |
conda env update --file ci/environment.yml --name base
conda env update --file ci/environment.yml --name base --solver classic
- name: Lint with flake8
run: |
conda install flake8
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/release_to_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish to PyPI

on:
push:
tags:
- "20*"

jobs:
pypi-release:
name: Publish release on PyPI
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write

steps:
- name: Checkout source
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Build source and wheel distributions
run: |
python -m pip install --upgrade build twine
python -m build
twine check --strict dist/*
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# Remember to manually create release on GitHub using the same tag.
130 changes: 64 additions & 66 deletions .github/workflows/tests-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests (Conda)

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

# Allow job to be triggered manually.
workflow_dispatch:
Expand Down Expand Up @@ -33,74 +33,72 @@ jobs:

name: Python ${{ matrix.python-version }} on OS ${{ matrix.os }}
steps:
- name: Acquire sources
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Acquire sources
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: CACHING - Anaconda packages
uses: actions/cache@v3
id: cache-pkg
with:
path: ~/conda_pkgs_dir
key:
conda-pkg-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{
env.CACHE_NUMBER }}-${{ hashFiles('environment-test.yml') }}
env:
# Increase this value if `environment-test.yml` has not changed,
# but you still want to reset the cache.
CACHE_NUMBER: 0

- name: CACHING - Anaconda packages
uses: actions/cache@v3
id: cache-pkg
with:
path: ~/conda_pkgs_dir
key:
conda-pkg-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{
env.CACHE_NUMBER }}-${{ hashFiles('environment-test.yml') }}
env:
# Increase this value if `environment-test.yml` has not changed,
# but you still want to reset the cache.
CACHE_NUMBER: 0
- name: INSTALL - Anaconda setup (Mambaforge)
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
miniforge-version: latest
mamba-version: "*"
use-mamba: true
channels: conda-forge,defaults
channel-priority: true
activate-environment: herbie-test
auto-activate-base: false
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!

- name: INSTALL - Anaconda setup (Mambaforge)
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
miniforge-version: latest
mamba-version: "*"
use-mamba: true
channels: conda-forge,defaults
channel-priority: true
activate-environment: herbie-test
auto-activate-base: false
use-only-tar-bz2: true # IMPORTANT: This needs to be set for caching to work properly!
- name: CACHING - Anaconda environment
uses: actions/cache@v3
id: cache-env
with:
path: ${{ env.CONDA }}/envs
key:
conda-env-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{
env.CACHE_NUMBER }}-${{ hashFiles('environment-test.yml') }}
env:
# Increase this value if `environment-test.yml` has not changed,
# but you still want to reset the cache.
CACHE_NUMBER: 0

- name: CACHING - Anaconda environment
uses: actions/cache@v3
id: cache-env
with:
path: ${{ env.CONDA }}/envs
key:
conda-env-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{
env.CACHE_NUMBER }}-${{ hashFiles('environment-test.yml') }}
env:
# Increase this value if `environment-test.yml` has not changed,
# but you still want to reset the cache.
CACHE_NUMBER: 0
- name: DEBUG - Anaconda info
run: conda info
- name: DEBUG - Anaconda configuration
run: conda config --show
- name: DEBUG - Environment variables
run: printenv | sort
- name: DEBUG - Program paths
run: |
command -v conda
command -v mamba
- name: DEBUG - Anaconda info
run: conda info
- name: DEBUG - Anaconda configuration
run: conda config --show
- name: DEBUG - Environment variables
run: printenv | sort
- name: DEBUG - Program paths
run: |
command -v conda
command -v mamba
- name: INSTALL - Update Anaconda environment
run: mamba env update --name herbie-test --file environment-test.yml
if: steps.cache-env.outputs.cache-hit != 'true'

- name: INSTALL - Update Anaconda environment
run:
mamba env update --name herbie-test --file environment-test.yml
if: steps.cache-env.outputs.cache-hit != 'true'

- name: INSTALL - Project
run: |
pip install --editable=.
- name: INSTALL - Project
run: |
pip install --editable=.
- name: Run tests
env:
TMPDIR: ${{ runner.temp }}
run: |
pytest
- name: Run tests
env:
TMPDIR: ${{ runner.temp }}
run: |
pytest
67 changes: 36 additions & 31 deletions .github/workflows/tests-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Tests (Python)

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

# Allow job to be triggered manually.
workflow_dispatch:
Expand All @@ -21,12 +21,13 @@ jobs:
fail-fast: true
matrix:
os: ["ubuntu-latest"]
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
# In order to save resources, only run particular
# matrix slots on other OS than Linux.
include:
- os: "macos-latest"
python-version: "3.11"
# TODO: Building on Windows fails because it fails to install pygrib; eccodes not found
#- os: "windows-latest"
# python-version: "3.11"

Expand All @@ -40,37 +41,41 @@ jobs:

name: Python ${{ matrix.python-version }} on OS ${{ matrix.os }}
steps:
- name: Acquire sources
uses: actions/checkout@v4
with:
fetch-depth: 2

- name: Acquire sources
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: "pip"
cache-dependency-path: "setup.cfg"

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: 'pip'
cache-dependency-path: 'setup.cfg'
- name: Install prerequisites (Linux)
if: runner.os == 'Linux'
run: |
sudo apt -y install libgeos-dev libeccodes-dev
- name: Install prerequisites (Linux)
if: runner.os == 'Linux'
run: |
sudo apt -y install libgeos-dev libeccodes-dev
- name: Install prerequisites (macOS)
if: runner.os == 'macOS'
run: |
brew install pkg-config geos eccodes
- name: Install prerequisites (macOS)
if: runner.os == 'macOS'
run: |
brew install pkg-config geos eccodes
- name: Install prerequisites (Windows)
if: runner.os == 'windows'
run: |
echo "Does anything need to be installed?"
- name: Install project
run: |
pip3 install --requirement=requirements-test.txt
pip3 install --editable=.
- name: Install project
run: |
pip3 install --requirement=requirements-test.txt
pip3 install --editable=.
- name: Run tests
env:
TMPDIR: ${{ runner.temp }}
run: |
pytest
- name: Run tests
env:
TMPDIR: ${{ runner.temp }}
run: |
pytest
Loading

0 comments on commit e7cfcce

Please sign in to comment.