Skip to content

Commit 1f01d72

Browse files
authored
[Github Actions] Cache builds of cmdstan in the CI (#423)
* Try cacheing * Test caching cmdstan * Try run with cached builds * Test cache miss * Revert "Test cache miss" This reverts commit 02d921e. * Don't delete bernoulli.exe after build * Alternative way of getting cmdstan version * Formatting; should be done * Try only one api call? * Cleanup
1 parent 52e34f1 commit 1f01d72

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

.github/workflows/main.yml

+20-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,20 @@ on:
99
- '**'
1010
pull_request:
1111
jobs:
12+
get-cmdstan-version:
13+
# get the latest cmdstan version to use as part of the cache key
14+
name: grab version
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Get CmdStan version
18+
id: check-cmdstan
19+
run: |
20+
echo "::set-output name=version::$(python -c 'import requests;print(requests.get("https://api.github.com/repos/stan-dev/cmdstan/releases/latest").json()["tag_name"][1:])')"
21+
outputs:
22+
version: ${{ steps.check-cmdstan.outputs.version }}
23+
1224
cmdstanpy:
25+
needs: get-cmdstan-version
1326
name: tests
1427
runs-on: ${{ matrix.os }}
1528
strategy:
@@ -52,22 +65,26 @@ jobs:
5265
if: matrix.os == 'windows-latest'
5366
run: |
5467
$whl = Get-ChildItem -Path dist -Filter *.whl | Select-Object -First 1
55-
pip install "$whl"
68+
pip install "$whl"
5669
5770
- name: Show libraries
5871
run: python -m pip freeze
5972

73+
- name: CmdStan installation cacheing
74+
uses: actions/cache@v2
75+
with:
76+
path: ~/.cmdstan
77+
key: ${{ runner.os }}-cmdstan-${{ needs.get-cmdstan-version.outputs.version }}-${{ hashFiles('**/install_cmdstan.py') }}
78+
6079
- name: Install CmdStan (Linux, macOS)
6180
if: matrix.os != 'windows-latest'
6281
run: |
6382
python -m cmdstanpy.install_cmdstan
64-
python scripts/clean_examples.py
6583
6684
- name: Install CmdStan (Windows)
6785
if: matrix.os == 'windows-latest'
6886
run: |
6987
python -m cmdstanpy.install_cmdstan --compiler
70-
python scripts/clean_examples.py
7188
7289
- name: Run tests
7390
run: |
@@ -80,7 +97,6 @@ jobs:
8097
cd run_tests
8198
python -m pip install -r ../requirements-optional.txt
8299
python ../test/example_script.py
83-
python ../scripts/clean_examples.py
84100
85101
- name: Submit codecov
86102
run: |

scripts/clean_examples.py

-21
This file was deleted.

test/example_script.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def run_bernoulli_fit():
1515
cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan'
1616
)
1717
bernoulli_model = CmdStanModel(stan_file=bernoulli_path)
18-
bernoulli_model.compile()
18+
bernoulli_model.compile(force=True)
1919

2020
# specify data, fit the model
2121
bernoulli_data = {'N': 10, 'y': [0, 1, 0, 0, 0, 0, 0, 0, 0, 1]}

0 commit comments

Comments
 (0)