Skip to content

Commit b92084f

Browse files
committed
Use conda-lock to create test environments
1 parent 83cb28c commit b92084f

11 files changed

+9626
-3
lines changed

.github/workflows/ci.yml

+16-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
push:
77
branches: [main]
88

9+
defaults:
10+
run:
11+
# Ensure activation for micromamba
12+
shell: bash -leo pipefail {0} {0}
13+
914
jobs:
1015
lint:
1116
runs-on: ubuntu-latest
@@ -30,10 +35,18 @@ jobs:
3035

3136
steps:
3237
- uses: actions/checkout@v3
33-
- name: Set up Python
34-
uses: actions/setup-python@v3
38+
- name: Rename lockfile
39+
run: |
40+
mv conda/conda-lock-${{ matrix.python-version }}.yaml conda/conda-lock.yml
41+
- uses: mamba-org/setup-micromamba@v1
3542
with:
36-
python-version: ${{ matrix.python-version }}
43+
micromamba-version: 1.5.5-0
44+
environment-file: conda/conda-lock.yml
45+
environment-name: causalpy-test-${{ matrix.python-version }}
46+
cache-environment: true
47+
create-args: >-
48+
--category main
49+
--category dev
3750
- name: Run doctests
3851
run: |
3952
pip install -e .[test]

.github/workflows/update-lockfile.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Update lockfile
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# At 06:12 UTC on Monday
7+
- cron: 12 6 * * MON
8+
9+
jobs:
10+
conda-lock:
11+
strategy:
12+
matrix:
13+
python-version: ["3.8", "3.9", "3.10"]
14+
defaults:
15+
run:
16+
# Ensure the environment is activated
17+
# <https://github.com/mamba-org/setup-micromamba#about-login-shells>
18+
shell: bash -l {0}
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Install Conda environment with Micromamba
23+
uses: mamba-org/setup-micromamba@v1
24+
with:
25+
environment-file: conda/environment-conda-locker.yaml
26+
environment-name: conda-lock-env
27+
cache-environment: true
28+
29+
- name: Run conda-lock
30+
run: |
31+
conda-lock lock --mamba \
32+
--extras test \
33+
--filter-extras \
34+
--file pyproject.toml \
35+
--file conda/environment-test-${{ matrix.python-version }}.yaml \
36+
--lockfile conda/conda-lock-${{ matrix.python-version }}.yaml
37+
38+
- name: Upload lockfile
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: lockfile-${{ matrix.python-version }}
42+
path: conda/conda-lock-${{ matrix.python-version }}.yaml
43+
44+
open-pr:
45+
needs: conda-lock
46+
runs-on: ubuntu-latest
47+
steps:
48+
- name: Checkout repo
49+
uses: actions/checkout@v4
50+
- name: Download all lockfiles
51+
uses: actions/download-artifact@v4
52+
with:
53+
path: /tmp/conda
54+
- name: Replace existing lockfiles with downloaded ones
55+
run: |
56+
mv /tmp/conda/lockfile-*/* conda/
57+
- name: Open a pull request
58+
uses: peter-evans/create-pull-request@v5
59+
with:
60+
# This PAT should have read-write permissions for "Pull Requests"
61+
# and read-write permissions for "Contents".
62+
token: ${{ secrets.GH_PAT_FOR_PR }}
63+
commit-message: Relock dependencies
64+
title: Relock dependencies
65+
body: >
66+
This pull request relocks the dependencies with conda-lock.
67+
It was created automatically with the GitHub Action
68+
[update-lockfile.yml](.github/workflows/update-lockfile.yml).
69+
branch: relock-deps
70+
labels: conda-lock
71+
delete-branch: true
72+
committer: update-lockfile.yml <nobody@pymc-labs.com>
73+
author: update-lockfile.yml <nobody@pymc-labs.com>

0 commit comments

Comments
 (0)