Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cd workflow with pip & conda deploy, etc. #27

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .conda/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
channels:
- conda-forge
- accessnri
- default

dependencies:
- anaconda-client
- conda-build
- conda-verify
37 changes: 37 additions & 0 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{% set data = load_setup_py_data(setup_file='../setup.py', from_recipe_dir=True) %}
{% set version = data.get('version') %}

package:
name: access-py-telemetry
version: "{{ version }}"

source:
url: "https://pypi.io/packages/source/a/access-py-telemetry/access_py_telemetry-{{ version }}.tar.gz"

build:
noarch: python
number: 0
script: "{{ PYTHON }} -m pip install . -vv"

requirements:
host:
- python
- pip
- versioneer
run:
- python >=3.10
- ipython>=7.0.0
- pydantic>=2.0.0
- pyyaml>=6.0.0
- httpx>=0.28.0

about:
home: https://github.com/ACCESS-NRI/access-py-telemetry
license: Apache Software
license_family: APACHE
summary: "Tools to add telemetry data to Python package usage"
# doc_url: https://access-py-telemetry-catalog.readthedocs.io/en/latest/

extra:
recipe-maintainers:
- charles-turner-1
62 changes: 62 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CD

on: [push, pull_request]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It running on.push without specifying any branches might be overly broad. Is this deployment to PyPi supposed to be for only pushes to main? If so, it can be updated to:

Suggested change
on: [push, pull_request]
on:
push:
branches:
- main
paths-ignore:
- .github # updates to CD infra shouldn't deploy to pypi
pull_request:
paths-ignore:
- .github # probably the case here, too


jobs:
pypi:
name: build and deploy to PyPI
if: github.repository == 'ACCESS-NRI/access-py-telemetry' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: "ubuntu-latest"
permissions:
id-token: write

steps:
- name: Checkout source
uses: actions/[email protected]

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
Comment on lines +17 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although not super critical, you can cache the installation of later python packages by adding the cache: pip argument to the setup-python action, like so:

Suggested change
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: pip


- name: Install build dependencies
run: python -m pip install build twine

- name: Build distributions
shell: bash -l {0}
run: |
git clean -xdf
pyproject-build

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

conda:
name: build and deploy to conda
needs: pypi
if: always() && needs.pypi.result == 'success'
Comment on lines +36 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I understand, is it the intention that the conda job runs only on.pull_request, or both on.push/on.pull_request?

Currently it will only run on.push - on.pull_request won't run this job, because the status of the pypi job will be skipped rather than success. If you want it to run on.pull_request, the condition should be:

if: always() && (needs.pypi.result == 'success' || needs.pypi.result == 'skipped')

If you do want it to run only on.push, the conditional can be removed, as by default the job will only run if the jobs it needs are success.

runs-on: "ubuntu-latest"

steps:
- name: Checkout source
uses: actions/[email protected]

- name: Setup conda environment
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
python-version: 3.11
environment-file: .conda/environment.yml
auto-update-conda: false
auto-activate-base: false
show-channel-urls: true

- name: Build and upload the conda package
uses: uibcdf/[email protected]
with:
meta_yaml_dir: .conda
python-version: 3.11
user: accessnri
label: main
token: ${{ secrets.anaconda_token }}

Loading