Skip to content

Commit 4c2a1b6

Browse files
committed
Add full CI, versioning, and packaging.
1 parent ead5a60 commit 4c2a1b6

10 files changed

Lines changed: 1053 additions & 43 deletions

File tree

.github/workflows/devel.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Release Devel
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ devel ]
7+
8+
jobs:
9+
build:
10+
name: build (${{ matrix.python-version }}, ${{ matrix.platform.name }})
11+
runs-on: ${{ matrix.platform.os }}
12+
strategy:
13+
max-parallel: 9
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.10", "3.11", "3.12"]
17+
platform:
18+
- { name: "linux", os: "ubuntu-latest", shell: "bash -l {0}" }
19+
- { name: "macos", os: "macos-latest", shell: "bash -l {0}" }
20+
exclude:
21+
# Exclude all but the latest Python from all
22+
# but Linux
23+
- platform:
24+
{ name: "macos", os: "macos-latest", shell: "bash -l {0}" }
25+
python-version: "3.12" # MacOS can't run 3.12 yet... We want 3.10 and 3.11
26+
environment:
27+
name: ghostly-build
28+
defaults:
29+
run:
30+
shell: ${{ matrix.platform.shell }}
31+
env:
32+
SIRE_DONT_PHONEHOME: 1
33+
SIRE_SILENT_PHONEHOME: 1
34+
steps:
35+
- uses: conda-incubator/setup-miniconda@v3
36+
with:
37+
auto-update-conda: true
38+
python-version: ${{ matrix.python-version }}
39+
activate-environment: ghostly_build
40+
miniforge-version: latest
41+
#
42+
- name: Clone the devel branch
43+
run: git clone -b devel https://github.com/openbiosim/ghostly
44+
#
45+
- name: Setup Conda
46+
run: conda install -y -c conda-forge boa anaconda-client packaging
47+
#
48+
- name: Update Conda recipe
49+
run: python ${{ github.workspace }}/ghostly/actions/update_recipe.py
50+
#
51+
- name: Prepare build location
52+
run: mkdir ${{ github.workspace }}/build
53+
#
54+
- name: Build Conda package using conda build
55+
run: conda build -c conda-forge -c openbiosim/label/dev ${{ github.workspace }}/ghostly/recipes/ghostly
56+
#
57+
- name: Upload Conda package
58+
run: python ${{ github.workspace }}/ghostly/actions/upload_package.py
59+
env:
60+
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
61+
ANACONDA_LABEL: dev
62+
if: ${{ matrix.platform.name == 'linux' && matrix.python-version == '3.11' }}

.github/workflows/main.yaml

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,63 @@
1-
name: Build and test
1+
name: Release Main
22

33
on:
44
workflow_dispatch:
5-
push:
6-
branches:
7-
- "**"
8-
pull_request:
9-
branches:
10-
- "main"
5+
inputs:
6+
upload_packages:
7+
required: true
8+
description: "Upload packages to anaconda?"
9+
type: boolean
1110

1211
jobs:
13-
pre_job:
14-
runs-on: ubuntu-latest
15-
outputs:
16-
should_skip: ${{ steps.skip_check.outputs.should_skip }}
17-
steps:
18-
- id: skip_check
19-
uses: fkirc/skip-duplicate-actions@v5
20-
with:
21-
concurrent_skipping: 'same_content_newer'
2212
build:
23-
needs: pre_job
24-
if: needs.pre_job.outputs.should_skip != 'true'
2513
name: build (${{ matrix.python-version }}, ${{ matrix.platform.name }})
2614
runs-on: ${{ matrix.platform.os }}
2715
strategy:
2816
max-parallel: 9
2917
fail-fast: false
3018
matrix:
31-
python-version: ["3.11"]
19+
python-version: ["3.10", "3.11", "3.12"]
3220
platform:
33-
#- { name: "windows", os: "windows-latest", shell: "pwsh" }
3421
- { name: "linux", os: "ubuntu-latest", shell: "bash -l {0}" }
3522
- { name: "macos", os: "macos-latest", shell: "bash -l {0}" }
23+
exclude:
24+
- platform:
25+
{ name: "macos", os: "macos-latest", shell: "bash -l {0}" }
26+
python-version: "3.12" # MacOS can't run 3.12 yet...
27+
environment:
28+
name: ghostly-build
3629
defaults:
3730
run:
3831
shell: ${{ matrix.platform.shell }}
32+
env:
33+
SIRE_DONT_PHONEHOME: 1
34+
SIRE_SILENT_PHONEHOME: 1
3935
steps:
40-
#
41-
- name: Checkout the repository (commit)
42-
uses: actions/checkout@v4
43-
if: github.event_name != 'pull_request'
44-
#
45-
- name: Checkout the repository (PR)
46-
uses: actions/checkout@v4
47-
with:
48-
ref: ${{ github.event.pull_request.head.sha }}
49-
if: github.event_name == 'pull_request'
50-
#
5136
- uses: conda-incubator/setup-miniconda@v3
5237
with:
5338
auto-update-conda: true
5439
python-version: ${{ matrix.python-version }}
55-
activate-environment: somd2
56-
environment-file: environment.yaml
40+
activate-environment: ghostly_build
5741
miniforge-version: latest
58-
run-post: ${{ matrix.platform.name != 'windows' }}
5942
#
60-
- name: Install pytest
61-
run: conda install pytest
43+
- name: Clone the main branch
44+
run: git clone -b main https://github.com/openbiosim/ghostly
45+
#
46+
- name: Setup Conda
47+
run: conda install -y -c conda-forge boa anaconda-client packaging
48+
#
49+
- name: Update Conda recipe
50+
run: python ${{ github.workspace }}/ghostly/actions/update_recipe.py
51+
#
52+
- name: Prepare build location
53+
run: mkdir ${{ github.workspace }}/build
6254
#
63-
- name: Install the package
64-
run: pip install .
55+
- name: Build Conda package using conda build
56+
run: conda build -c conda-forge -c openbiosim/label/main ${{ github.workspace }}/ghostly/recipes/ghostly
6557
#
66-
- name: Run the tests
67-
run: python -m pytest -svvv --color=yes tests
58+
- name: Upload Conda package
59+
run: python ${{ github.workspace }}/ghostly/actions/upload_package.py
60+
env:
61+
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
62+
ANACONDA_LABEL: main
63+
if: github.event.inputs.upload_packages == 'true' and ${{ matrix.platform.name == 'linux' && matrix.python-version == '3.11' }}

.github/workflows/pr.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Pull-Request
2+
3+
on:
4+
pull_request:
5+
branches: [devel, main]
6+
7+
jobs:
8+
build:
9+
name: build (${{ matrix.python-version }}, ${{ matrix.platform.name }})
10+
runs-on: ${{ matrix.platform.os }}
11+
strategy:
12+
max-parallel: 9
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.10", "3.11", "3.12"]
16+
platform:
17+
- { name: "windows", os: "windows-latest", shell: "pwsh" }
18+
- { name: "linux", os: "ubuntu-latest", shell: "bash -l {0}" }
19+
- { name: "macos", os: "macos-latest", shell: "bash -l {0}" }
20+
exclude:
21+
# Exclude all but the latest Python from all
22+
# but Linux
23+
- platform:
24+
{ name: "macos", os: "macos-latest", shell: "bash -l {0}" }
25+
python-version: "3.10"
26+
- platform: { name: "windows", os: "windows-latest", shell: "pwsh" }
27+
python-version: "3.10"
28+
- platform:
29+
{ name: "macos", os: "macos-latest", shell: "bash -l {0}" }
30+
python-version: "3.12" # MacOS can't run 3.12 yet...
31+
- platform: { name: "windows", os: "windows-latest", shell: "pwsh" }
32+
python-version: "3.11"
33+
environment:
34+
name: ghostly-build
35+
defaults:
36+
run:
37+
shell: ${{ matrix.platform.shell }}
38+
env:
39+
SIRE_DONT_PHONEHOME: 1
40+
SIRE_SILENT_PHONEHOME: 1
41+
REPO: "${{ github.event.pull_request.head.repo.full_name || github.repository }}"
42+
steps:
43+
- uses: conda-incubator/setup-miniconda@v3
44+
with:
45+
auto-update-conda: true
46+
python-version: ${{ matrix.python-version }}
47+
activate-environment: ghostly_build
48+
miniforge-version: latest
49+
#
50+
- name: Clone the feature branch
51+
run: git clone -b ${{ github.head_ref }} --single-branch https://github.com/${{ env.REPO }} ghostly
52+
#
53+
- name: Setup Conda
54+
run: conda install -y -c conda-forge boa anaconda-client packaging
55+
#
56+
- name: Update Conda recipe
57+
run: python ${{ github.workspace }}/ghostly/actions/update_recipe.py
58+
#
59+
- name: Prepare build location
60+
run: mkdir ${{ github.workspace }}/build
61+
#
62+
- name: Build Conda package using conda build using main channel
63+
if: ${{ github.base_ref == 'main' }}
64+
run: conda build -c conda-forge -c openbiosim/label/main ${{ github.workspace }}/ghostly/recipes/ghostly
65+
#
66+
- name: Build Conda package using conda build using dev channel
67+
if: ${{ github.base_ref != 'main' }}
68+
run: conda build -c conda-forge -c openbiosim/label/dev ${{ github.workspace }}/ghostly/recipes/ghostly

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Ghostly
88

99
[![GitHub Actions](https://github.com/openbiosim/ghostly/actions/workflows/main.yaml/badge.svg)](https://github.com/openbiosim/ghostly/actions/workflows/main.yaml)
10+
[![Conda Version](https://anaconda.org/openbiosim/ghostly/badges/downloads.svg)](https://anaconda.org/openbiosim/ghostly)
1011
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
1112

1213
Ghostly is a package to perform modification of ghost (dummy) atom bonded

actions/update_recipe.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import sys
2+
import os
3+
import subprocess
4+
5+
# Get the name of the script.
6+
script = os.path.abspath(sys.argv[0])
7+
8+
# we want to import the 'get_requirements' package from this directory
9+
sys.path.insert(0, os.path.dirname(script))
10+
11+
# go up one directories to get the source directory
12+
# (this script is in BioSimSpace/actions/)
13+
srcdir = os.path.dirname(os.path.dirname(script))
14+
15+
condadir = os.path.join(srcdir, "recipes", "ghostly")
16+
17+
print(f"conda recipe in {condadir}")
18+
19+
# Store the name of the recipe and template YAML files.
20+
recipe = os.path.join(condadir, "meta.yaml")
21+
template = os.path.join(condadir, "template.yaml")
22+
23+
gitdir = os.path.join(srcdir, ".git")
24+
25+
26+
def run_cmd(cmd):
27+
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
28+
return str(p.stdout.read().decode("utf-8")).lstrip().rstrip()
29+
30+
31+
# Get the remote.
32+
remote = run_cmd(
33+
f"git --git-dir={gitdir} --work-tree={srcdir} config --get remote.origin.url"
34+
)
35+
print(remote)
36+
37+
# Get the branch.
38+
branch = run_cmd(
39+
f"git --git-dir={gitdir} --work-tree={srcdir} rev-parse --abbrev-ref HEAD"
40+
)
41+
print(branch)
42+
43+
lines = open(template, "r").readlines()
44+
45+
with open(recipe, "w") as FILE:
46+
for line in lines:
47+
line = line.replace("GHOSTLY_REMOTE", remote)
48+
line = line.replace("GHOSTLY_BRANCH", branch)
49+
50+
FILE.write(line)

actions/upload_package.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import os
2+
import sys
3+
import glob
4+
5+
script = os.path.abspath(sys.argv[0])
6+
7+
# go up one directories to get the source directory
8+
# (this script is in ghostly/actions/)
9+
srcdir = os.path.dirname(os.path.dirname(script))
10+
11+
print(f"Ghostly source is in {srcdir}\n")
12+
13+
# Get the anaconda token to authorise uploads
14+
if "ANACONDA_TOKEN" in os.environ:
15+
conda_token = os.environ["ANACONDA_TOKEN"]
16+
else:
17+
conda_token = "TEST"
18+
19+
# Get the anaconda channel labels.
20+
if "ANACONDA_LABEL" in os.environ:
21+
conda_label = os.environ["ANACONDA_LABEL"]
22+
else:
23+
conda_label = "dev"
24+
25+
# get the root conda directory
26+
conda = os.environ["CONDA"]
27+
28+
# Set the path to the conda-bld directory.
29+
conda_bld = os.path.join(conda, "envs", "ghostly_build", "conda-bld")
30+
31+
print(f"conda_bld = {conda_bld}")
32+
33+
# Find the packages to upload
34+
ghostly_pkg = glob.glob(os.path.join(conda_bld, "noarch", "ghostly-*.tar.bz2"))
35+
36+
if len(ghostly_pkg) == 0:
37+
print("No ghostly packages to upload?")
38+
sys.exit(-1)
39+
40+
packages = ghostly_pkg
41+
42+
print(f"Uploading packages:")
43+
print(" * ", "\n * ".join(packages))
44+
45+
packages = " ".join(packages)
46+
47+
48+
def run_cmd(cmd):
49+
import subprocess
50+
51+
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
52+
return str(p.stdout.read().decode("utf-8")).lstrip().rstrip()
53+
54+
55+
gitdir = os.path.join(srcdir, ".git")
56+
57+
tag = run_cmd(f"git --git-dir={gitdir} --work-tree={srcdir} tag --contains")
58+
59+
# Upload the packages to the openbiosim channel on Anaconda Cloud.
60+
cmd = f"anaconda --token {conda_token} upload --user openbiosim --label {conda_label} --force {packages}"
61+
62+
print(f"\nUpload command:\n\n{cmd}\n")
63+
64+
if conda_token == "TEST":
65+
print("Not uploading as the ANACONDA_TOKEN is not set!")
66+
sys.exit(-1)
67+
68+
output = run_cmd(cmd)
69+
70+
print(output)
71+
72+
print("Package uploaded!")

pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["setuptools", "setuptools-scm"]
2+
requires = ["setuptools", "versioningit"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
@@ -25,5 +25,10 @@ repository = "https://github.com/OpenBioSim/ghostly"
2525
[tool.setuptools.packages.find]
2626
where = ["src"]
2727

28-
[tool.setuptools_scm]
29-
write_to = "src/ghostly/_version.py"
28+
[tool.versioningit.format]
29+
distance = "{base_version}+{distance}.{vcs}{rev}"
30+
dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
31+
distance-dirty = "{base_version}+{distance}.{vcs}{rev}.dirty"
32+
33+
[tool.versioningit.write]
34+
file = "src/ghostly/_version.py"

0 commit comments

Comments
 (0)