Skip to content

Commit

Permalink
Merge pull request #5 from anaconda/chore/ci-and-pkg
Browse files Browse the repository at this point in the history
[chore] CI and packaging
  • Loading branch information
AlbertDeFusco authored Nov 18, 2024
2 parents cca561e + 0b235e9 commit 14cc057
Show file tree
Hide file tree
Showing 9 changed files with 6,314 additions and 5 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: "release"

on:
push:
tags:
- "v*"

jobs:
test:
uses: ./.github/workflows/test.yml

publish-conda-pkg-to-anaconda-dot-org:
name: Publish conda package to Anaconda.org
runs-on: ubuntu-latest
if: github.event_name == 'push' # Only run on push to main branch
needs: [test]
steps:
- name: Retrieve the source code
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
fetch-depth: 0
- name: Create build environment
run: |
source $CONDA/bin/activate
conda create -n build --file ./etc/build.linux-64.lock
- name: Download the build artifacts
uses: actions/download-artifact@9c19ed7fe5d278cd354c7dfd5d3b88589c7e2395 # v4
with:
name: anaconda-cli-base-conda-${{ github.sha }}
path: ~/anaconda-cli-base-conda-bld
- name: publish
env:
TOKEN: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}
run: |
source $CONDA/bin/activate && conda activate build
[[ "$GITHUB_REF" =~ ^refs/tags/v ]] || export LABEL="--label dev"
anaconda --verbose \
--token $TOKEN \
upload \
--user anaconda-cloud \
$LABEL \
--force \
~/anaconda-cli-base-conda-bld/noarch/anaconda-cli-base-*
publish-wheel-to-anaconda-dot-org:
name: Publish wheel to Anaconda.org
runs-on: ubuntu-latest
if: github.event_name == 'push' # Only run on push to main branch
needs: [test]
steps:
- name: Retrieve the source code
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
fetch-depth: 0
- name: Download the build artifacts
uses: actions/download-artifact@9c19ed7fe5d278cd354c7dfd5d3b88589c7e2395 # v4
with:
name: anaconda-cli-base-wheel-${{ github.sha }}
path: ~/dist
- name: Create build environment
run: |
source $CONDA/bin/activate
conda create -n build --file ./etc/build.linux-64.lock
- name: Upload to anaconda.org
env:
TOKEN: ${{ secrets.ANACONDA_ORG_UPLOAD_TOKEN }}
GITHUB_REF: ${{ github.ref }}
run: |
source $CONDA/bin/activate && conda activate build
[[ "$GITHUB_REF" =~ ^refs/tags/v ]] || export LABEL="--label dev"
anaconda --verbose \
--token $TOKEN \
upload \
--user anaconda-cloud \
~/dist/*.whl \
--summary \
"A base CLI entrypoint supporting Anaconda CLI plugins" \
$LABEL \
--force \
publish-to-pypi:
name: Build & publish to PyPI
if: startsWith(github.event.ref, 'refs/tags/v')
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
- name: Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
- name: Download the build artifacts
uses: actions/download-artifact@9c19ed7fe5d278cd354c7dfd5d3b88589c7e2395 # v4
with:
name: anaconda-cli-base-wheel-${{ github.sha }}
path: ~/dist
- name: Install build dependencies
run: pip install twine
- name: Upload to PyPI with twine
run: python -m twine upload ~/dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
90 changes: 90 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: "test"

on:
pull_request:
branches:
- main
merge_group:
workflow_call:

jobs:
test:
name: Python ${{ matrix.python-version }}
runs-on:
labels: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
- name: Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
with:
python-version: ${{ matrix.python-version }}
- name: Install testing dependencies
run: python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox

build-conda-package:
name: Build conda package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
fetch-depth: 0
- name: Create build environment
run: |
source $CONDA/bin/activate
conda create -n build --file ./etc/build.linux-64.lock
- name: conda build
run: |
source $CONDA/bin/activate && conda activate build
mkdir -p ./conda-bld
VERSION=`hatch version` conda build -c conda-forge -c defaults --override-channels conda.recipe --output-folder ./conda-bld
- name: Upload the build artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: anaconda-cli-base-conda-${{ github.sha }}
path: ./conda-bld
if-no-files-found: error
retention-days: 7

build-wheel:
name: Build the wheel
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5
with:
python-version: "3.10"
- name: Install build dependencies
run: pip install build
- name: Build the package
run: python -m build
- name: Upload the build artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4
with:
name: anaconda-cli-base-wheel-${{ github.sha }}
path: dist/*
if-no-files-found: error
retention-days: 7

# This check job runs to ensure all tests and builds have passed, such that we can use it as a "wildcard"
# for branch protection to ensure all tests pass before a PR can be merged.
check:
name: Check all tests passed
if: always()
needs: [test, build-conda-package, build-wheel]
runs-on: ubuntu-latest
steps:
- name: Decide whether all required jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
47 changes: 47 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
env/
build/
develop-eggs/
dist/
*.egg-info

# Unit test / coverage reports
htmlcov/
.coverage
.coverage.*
coverage.xml
.pytest_cache/
.tox/

# Documentation
docs/_build/
docs/.cache/

# Jupyter Notebook
.ipynb_checkpoints

# dotenv
.env

# virtualenv
.venv
venv/

# mypy
.mypy_cache/

# vscode ide stuff
*.code-workspace
.history
.vscode

# Version file generated by setuptools-scm
src/*/_version.py

# Stored tokens (for dev)
/tokens.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ config = MyPluginConfig()
assert config.foo == "baz"
```

See the [tests](https://github.com/anaconda/anaconda-cloud-tools/blob/feat/cli-base-config-file/libs/anaconda-cli-base/tests/test_config.py) for more examples.
See the [tests](https://github.com/anaconda/anaconda-cli-base/blob/main/tests/test_config.py) for more examples.

## Setup for development

Expand All @@ -137,6 +137,7 @@ make test
```

## Run the unit tests across isolated environments with tox

```shell
make tox
```
27 changes: 27 additions & 0 deletions etc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Command aliases
CONDA_EXE ?= conda
CONDA_LOCK := $(CONDA_EXE)-lock

name = $(word 1, $(subst ., ,$1))

ENVIRONMENT_YMLS = $(wildcard *.environment.yml)
ENVIRONMENTS := $(foreach e,$(wildcard *.environment.yml),$(call name, $e))
LOCKFILES := $(foreach e, $(ENVIRONMENTS), $e.conda-lock.yml)
# Explicit lockfiles are used in github actions with conda-incubator/setupminiconda
EXPLICIT_LOCKFILES := $(foreach e, $(ENVIRONMENTS), $e.linux-64.lock)

help: ## Display help on all Makefile targets
@@grep -h '^[a-zA-Z]' $(MAKEFILE_LIST) | awk -F ':.*?## ' 'NF==2 {printf " %-20s%s\n", $$1, $$2}' | sort

.PHONY: $(ENVIRONMENTS)
$(ENVIRONMENTS): ## Lock this specific environment.yml file
rm -f $@.conda-lock.yml
rm -f $@.linux-64.lock
$(CONDA_LOCK) lock -f $@.environment.yml --lockfile $@.conda-lock.yml
$(CONDA_LOCK) render -p linux-64 --filename-template "$@.{platform}.lock" $@.conda-lock.yml

lock: $(ENVIRONMENTS) ## lock all .environment.yml files

clean: ## Remove lockfiles and explicit files
rm $(LOCKFILES)
rm $(EXPLICIT_LOCKFILES)
Loading

0 comments on commit 14cc057

Please sign in to comment.