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

Cahce dependencies in CI to speedup workflows #471

Merged
merged 50 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
7af70e2
it can't be this simple right?
savente93 Aug 3, 2023
4b9f7d1
add some temp code so ci runs
savente93 Aug 3, 2023
3e221f5
right?
savente93 Aug 3, 2023
f654a30
don't mind me
savente93 Aug 3, 2023
678e029
add caching steps to test workflow
savente93 Aug 9, 2023
17a30e7
Merge branch 'main' into ci-cache
savente93 Aug 9, 2023
b13bff9
add python version matrix back in
savente93 Aug 9, 2023
685c7a3
setup empty mambaforge step for cache
savente93 Aug 9, 2023
8077fa6
dummy commit to run CI
savente93 Aug 9, 2023
829de2b
Merge branch 'main' into ci-cache
savente93 Aug 9, 2023
d232dc9
add some keys to use mamba
savente93 Aug 9, 2023
ebd94bb
new try
savente93 Aug 9, 2023
1d09f75
run ci
savente93 Aug 9, 2023
d2c7256
fix yaml mistake
savente93 Aug 9, 2023
ae97435
fix yaml AGAIN
savente93 Aug 9, 2023
f7dd9df
try
savente93 Aug 9, 2023
a833f7a
try
savente93 Aug 9, 2023
7604648
try
savente93 Aug 9, 2023
7b28a98
try
savente93 Aug 9, 2023
8f5a478
move timeout to pytest
savente93 Aug 9, 2023
e8d5e09
add caching to doc generation
savente93 Aug 9, 2023
1ab7edc
cleanup
savente93 Aug 9, 2023
6517744
fix publish docker on
savente93 Aug 9, 2023
fbef274
darn you pas sam. don't add random print statments you silly
savente93 Aug 9, 2023
bcf716a
add clear cache action
savente93 Aug 9, 2023
7d3f382
see if can cache mamba install
savente93 Aug 9, 2023
c7fbe5f
add channel back
savente93 Aug 9, 2023
43cb8f1
try
savente93 Aug 9, 2023
207fa64
try
savente93 Aug 9, 2023
6c6e6c3
try
savente93 Aug 9, 2023
656e2c5
try
savente93 Aug 9, 2023
831d18e
try
savente93 Aug 9, 2023
dff8e72
try
savente93 Aug 9, 2023
dc40c1c
try
savente93 Aug 9, 2023
74eac39
try
savente93 Aug 9, 2023
9b47556
try
savente93 Aug 9, 2023
f894143
try
savente93 Aug 9, 2023
24be88f
try
savente93 Aug 9, 2023
6fffa59
try
savente93 Aug 9, 2023
dae9463
try
savente93 Aug 9, 2023
71b826b
clear cache daily
savente93 Aug 9, 2023
bb6f6b1
try
savente93 Aug 9, 2023
5652616
try
savente93 Aug 9, 2023
0302c30
revert test file
savente93 Aug 9, 2023
4453de9
remove comment
savente93 Aug 9, 2023
8f4993f
try
savente93 Aug 9, 2023
89cbdde
fix flag
savente93 Aug 9, 2023
5aaa302
Merge branch 'main' into ci-cache
savente93 Aug 10, 2023
7f6a155
move clear cache to their own workflows
savente93 Aug 10, 2023
1923f98
fix typo
savente93 Aug 10, 2023
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
38 changes: 24 additions & 14 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Build Documentation

# We don't want pushes (or PRs) to gh-pages to kick anything off
on:
push:
branches: [main]
Expand All @@ -23,9 +22,7 @@ on:
- pyproject.toml

jobs:
# Build docs on Linux
Docs:
timeout-minutes: 10
name: linux docs
runs-on: ubuntu-latest
env:
Expand All @@ -37,22 +34,35 @@ jobs:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout source
- name: checkout code
uses: actions/checkout@v3
- name: install tomli
run: pip install tomli

- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.11
miniforge-variant: Mambaforge
miniforge-version: latest
channels: conda-forge
activate-environment: hydromt
use-mamba: true
- name: Generate env spec
run: python make_env.py doc

- name: Setup environment
uses: conda-incubator/setup-miniconda@v2

- name: Set cache date
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV

- name: load from cache if it exists for our environment
uses: actions/cache@v2
with:
python-version: '3.10'
miniforge-variant: Mambaforge
channels: conda-forge, defaults
channel-priority: strict
environment-file: environment.yml
activate-environment: hydromt
path: /usr/share/miniconda3/envs/hydromt
key: docs-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}
id: cache

- name: Update environment & write to cache
run: mamba env update -n hydromt -f environment.yml
if: steps.cache.outputs.cache-hit != 'true'

- name: Install hydromt
run: pip install .
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
---
name: Build and publish HydroMT to DockerHub

# on:
# release:
# types:
# - published
# push:
# tags:
# - v*
on:
release:
types:
- published

jobs:
publish-docker-image:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ jobs:
echo "hydromt --models"

upload-to-test-pypi:
timeout-minutes: 10
needs: test-built-dist
if: github.event_name == 'push'
runs-on: ubuntu-latest
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/purge_all_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: cleanup all caches
on:
workflow_disptach:


jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup caches
run: |
gh cache delete -a
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/purge_pr_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

name: cleanup caches by a branch
on:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup caches
run: |
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"

echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH -L 100 | cut -f 1 )

## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54 changes: 34 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: Tests

on:
Expand All @@ -10,44 +9,59 @@ on:
- data/*
- pyproject.toml
pull_request:
branches: [main]
branches:
- main
paths:
- tests/*
- hydromt/*
- data/*
- pyproject.toml

jobs:
Test-matrix:
name: ${{ matrix.os }} - py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10
build:
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9','3.10','3.11']
name: py ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
concurrency:
group: ${{ github.workflow }}-${{ matrix.python-version }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v3

- name: Setup Mambaforge
uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: hydromt
use-mamba: true
- name: Generate env spec
run: pip install tomli && python make_env.py test
- uses: conda-incubator/setup-miniconda@v2


- name: Set cache date
run: echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV

- name: load from cache if it exists for our environment
uses: actions/cache@v2
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
channels: conda-forge, defaults
channel-priority: strict
environment-file: environment.yml
activate-environment: hydromt
path: /usr/share/miniconda3/envs/hydromt
key: ${{ matrix.python-version }}-conda-${{ hashFiles('environment.yml') }}-${{ env.DATE }}
id: cache

- name: Update environment & write to cache
run: mamba env update -n hydromt -f environment.yml
if: steps.cache.outputs.cache-hit != 'true'

- name: Test
run: python -m pytest --verbose --cov=hydromt --cov-report xml

- uses: codecov/codecov-action@v3

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
- name: Upload code coverage
uses: codecov/codecov-action@v3
1 change: 1 addition & 0 deletions make_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def _parse_profile(profile_str: str, opt_deps: dict, project_name: str) -> List[
channels = install_config.get("channels", ["conda-forge"])
if args.channels is not None:
channels.extend(args.channels.split(","))
channels = list(set(channels))

# parse environment name
name = args.name
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test = [
"pytest>=2.7.3", # testing framework
"pytest-cov", # test coverage
"pytest-mock", # mocking
"pytest-timeout", # darn hanging tests
]
doc = [
"nbsphinx", # build notebooks in docs
Expand Down Expand Up @@ -136,7 +137,9 @@ include = ["hydromt"]
exclude = ["docs", "examples", "envs", "tests", "binder", ".github"]

[tool.pytest.ini_options]
addopts = "--ff --timeout=60"
testpaths = ["tests"]

filterwarnings = [
"ignore:distutils Version classes are deprecated:DeprecationWarning",
"ignore:getargs:DeprecationWarning", # The 'u' format is deprecated. Use 'U' instead.
Expand Down
Loading