From de583745857f07d1dbff84b095409b2aa2878581 Mon Sep 17 00:00:00 2001 From: Derrick Chambers Date: Fri, 3 Jan 2025 15:17:30 -0800 Subject: [PATCH] refactor actions (#477) --- .github/actions/build-docs/action.yml | 20 +++++ .../actions/mamba-install-dascore/action.yml | 90 +++++++++++++++++++ .github/min_deps_environment.yml | 7 ++ .../workflows/build_deploy_master_docs.yaml | 46 ++-------- .../workflows/build_deploy_stable_docs.yaml | 51 ++--------- .github/workflows/get_coverage.yml | 27 +----- .github/workflows/lint.yml | 6 +- .github/workflows/run_min_dep_tests.yml | 56 ++---------- .github/workflows/runtests.yml | 54 +---------- 9 files changed, 139 insertions(+), 218 deletions(-) create mode 100644 .github/actions/build-docs/action.yml create mode 100644 .github/actions/mamba-install-dascore/action.yml create mode 100644 .github/min_deps_environment.yml diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.yml new file mode 100644 index 00000000..389ef1a4 --- /dev/null +++ b/.github/actions/build-docs/action.yml @@ -0,0 +1,20 @@ +name: "Build DASCore Docs" +description: "Builds DASCore's Documentation." + +runs: + using: "composite" + steps: + - name: Install quarto + uses: quarto-dev/quarto-actions/setup@v2 + with: + version: 1.3.450 + tinytex: true + + - name: print quarto version + run: | + quarto --version + + - name: render API docs + shell: bash -l {0} + run: | + python scripts/build_api_docs.py diff --git a/.github/actions/mamba-install-dascore/action.yml b/.github/actions/mamba-install-dascore/action.yml new file mode 100644 index 00000000..6e2198cf --- /dev/null +++ b/.github/actions/mamba-install-dascore/action.yml @@ -0,0 +1,90 @@ +name: "Mamba Install" +description: "Sets up mamba before installing DASCore's environment.yml file." +inputs: + python-version: + description: "The python string of the version to install" + required: true + + environment-file: + description: "The path to the environment file to use." + required: false + default: "environment.yml" + + install-group-str: + description: "The string to use for specifying install groups" + default: "[dev]" + required: false + + install-package: + description: "If true, install dascore" + default: true + required: false + type: boolean + + cache-number: + description: "Cache number. Use != 1 to reset data cache" + required: false + default: 1 + +runs: + using: "composite" + steps: + - name: Set up environment variable with date + shell: bash -l {0} + run: echo "CURRENT_DATE=$(date '+%Y-%m-%d')" >> $GITHUB_ENV + + - uses: mamba-org/setup-micromamba@v2 + with: + micromamba-version: '2.0.5-0' # versions: https://github.com/mamba-org/micromamba-releases + environment-file: ${{ inputs.environment-file }} + init-shell: >- + bash + powershell + cache-environment: true + cache-environment-key: environment-${{ env.CURRENT_DATE }}-${{ inputs.environment-file }} + post-cleanup: 'all' + create-args: >- + python=${{ inputs.python-version }} + + # Not sure why this is needed but it appears to be the case + - name: fix env + shell: bash -l {0} + run: | + micromamba shell init --shell bash --root-prefix=~/micromamba + eval "$(micromamba shell hook --shell bash)" + micromamba activate dascore + + - name: print python version + shell: bash -el {0} + run: | + python --version + + - name: get tags for correct versioning + shell: bash -el {0} + run: | + git fetch --tags --force + + - name: install dascore + if: "${{ inputs.install-package == 'true' }}" + shell: bash -l {0} + run: | + pip install -e .${{ inputs.install-group-str }} + + - name: set data cache path + shell: bash -el {0} + run: | + echo "DATA_CACHE_PATH=$(python -c "import pooch; print(pooch.os_cache('dascore'))")" >> $GITHUB_ENV + + - name: cache test data + uses: actions/cache@v3 + with: + enableCrossOsArchive: true + path: ${{ env.DATA_CACHE_PATH }} + key: DATA_${{ inputs.cache-number }} + + # Print out the package info for current environment + - name: print package info + shell: bash -el {0} + run: | + micromamba info + micromamba list diff --git a/.github/min_deps_environment.yml b/.github/min_deps_environment.yml new file mode 100644 index 00000000..54c51173 --- /dev/null +++ b/.github/min_deps_environment.yml @@ -0,0 +1,7 @@ +name: dascore +channels: + - conda-forge +dependencies: + - pytables + - h5py + - pooch diff --git a/.github/workflows/build_deploy_master_docs.yaml b/.github/workflows/build_deploy_master_docs.yaml index ad5a0a2d..d32376c4 100644 --- a/.github/workflows/build_deploy_master_docs.yaml +++ b/.github/workflows/build_deploy_master_docs.yaml @@ -34,50 +34,14 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-tags: "true" - - name: "get tags" - run: | - git fetch --tags --force # Retrieve annotated tags. - - - uses: mamba-org/setup-micromamba@v1 + - uses: ./.github/actions/mamba-install-dascore with: - micromamba-version: '1.5.8-0' # versions: https://github.com/mamba-org/micromamba-releases - environment-file: ./.github/doc_environment.yml - init-shell: >- - bash - powershell - cache-environment: true - post-cleanup: 'all' - - # Not sure why this is needed but it appears to be the case - - name: fix env - shell: bash -l {0} - run: | - micromamba shell init --shell bash --root-prefix=~/micromamba - eval "$(micromamba shell hook --shell bash)" - micromamba activate dascore - - - name: install dascore with docbuild reqs - shell: bash -l {0} - run: | - conda install -c conda-forge pandoc - python -m pip install -e .[docs,all] + python-version: "3.12" + environment-file: '././github/doc_environment.yml' - - name: Install quarto - uses: quarto-dev/quarto-actions/setup@v2 - with: - version: 1.3.450 - tinytex: true - - - name: print quarto version - run: | - quarto --version - - - name: render API docs - shell: bash -l {0} - run: | - python scripts/build_api_docs.py + - uses: ./.github/actions/build-docs - name: publish docs to netlify shell: bash -l {0} diff --git a/.github/workflows/build_deploy_stable_docs.yaml b/.github/workflows/build_deploy_stable_docs.yaml index 1814a984..f184a91f 100644 --- a/.github/workflows/build_deploy_stable_docs.yaml +++ b/.github/workflows/build_deploy_stable_docs.yaml @@ -32,55 +32,14 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-depth: 0 + fetch-tags: "true" - - name: "get tags" - run: | - git fetch --tags --force # Retrieve annotated tags. - - - name: Get tags - run: git fetch --tags origin - - - uses: mamba-org/setup-micromamba@v2 + - uses: ./.github/actions/mamba-install-dascore with: - micromamba-version: '2.0.2-1' # versions: https://github.com/mamba-org/micromamba-releases - environment-file: ./.github/doc_environment.yml - init-shell: >- - bash - powershell - cache-environment: true - post-cleanup: 'all' - cache-environment-key: environment-${{ steps.date.outputs.date }} - - # Not sure why this is needed but it appears to be the case - - name: fix env - shell: bash -l {0} - run: | - micromamba shell init --shell bash --root-prefix=~/micromamba - eval "$(micromamba shell hook --shell bash)" - micromamba activate dascore - - - name: install dascore with docbuild reqs - shell: bash -l {0} - run: | - conda install -c conda-forge pandoc - python -m pip install -e .[docs,all] - - - name: Install quarto - uses: quarto-dev/quarto-actions/setup@v2 - with: - version: 1.3.450 - tinytex: true - - - name: print quarto version - run: | - quarto --version + python-version: "3.12" + environment-file: '././github/doc_environment.yml' - - name: Render Quarto Project - shell: bash -l {0} - run: | - python scripts/build_api_docs.py - quarto render docs + - uses: ./.github/actions/build-docs - name: Setup Pages uses: actions/configure-pages@v2 diff --git a/.github/workflows/get_coverage.yml b/.github/workflows/get_coverage.yml index 3ef1783d..ad0e34e9 100644 --- a/.github/workflows/get_coverage.yml +++ b/.github/workflows/get_coverage.yml @@ -12,32 +12,9 @@ jobs: steps: - uses: actions/checkout@v4 - - name: "get tags" - run: | - git fetch --tags --force # Retrieve annotated tags. - - - uses: mamba-org/setup-micromamba@v1 + - uses: ./.github/actions/min-deps-install-dascore with: - micromamba-version: '1.5.8-0' # versions: https://github.com/mamba-org/micromamba-releases - environment-file: environment.yml - init-shell: >- - bash - powershell - cache-environment: true - post-cleanup: 'all' - - # Not sure why this is needed but it appears to be the case - - name: fix env - shell: bash -l {0} - run: | - micromamba shell init --shell bash --root-prefix=~/micromamba - eval "$(micromamba shell hook --shell bash)" - micromamba activate dascore - - - name: install dascore - shell: bash -l {0} - run: | - python -m pip install -e .[test] + python-version: ${{ matrix.python-version }} - name: run test suite shell: bash -l {0} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a9b19f64..5ed3d587 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,10 +11,8 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: "get tags" - run: | - git fetch --tags --force # Retrieve annotated tags. + with: + fetch-tags: 'true' - name: Install uv uses: astral-sh/setup-uv@v3 diff --git a/.github/workflows/run_min_dep_tests.yml b/.github/workflows/run_min_dep_tests.yml index 3651a8c3..16a79d7b 100644 --- a/.github/workflows/run_min_dep_tests.yml +++ b/.github/workflows/run_min_dep_tests.yml @@ -12,10 +12,6 @@ on: - '**.py' - '.github/workflows/run_min_dep_tests.yml' -env: - # used to manually trigger cache reset. Just increment if needed. - CACHE_NUMBER: 1 - # Cancel previous runs when this one starts. concurrency: group: TestCodeMinDeps-${{ github.event.pull_request.number || github.run_id }} @@ -35,63 +31,21 @@ jobs: # only run if CI isn't turned off if: github.event_name == 'push' || !contains(github.event.pull_request.labels.*.name, 'no_ci') - env: - # set conda environment file with dependencies - env_file: "environment.yml" - steps: - uses: actions/checkout@v4 with: - depth: 0 - - - name: "get tags" - run: | - git fetch --tags --force # Retrieve annotated tags. + fetch-tags: 'true' - - uses: mamba-org/setup-micromamba@v2 + - uses: ./.github/actions/mamba-install-dascore with: - micromamba-version: '2.0.2-1' # versions: https://github.com/mamba-org/micromamba-releases - environment-file: environment.yml - init-shell: >- - bash - powershell - cache-environment: true - cache-environment-key: environment-${{ steps.date.outputs.date }} - post-cleanup: 'all' - create-args: >- - python=${{ matrix.python-version }} - - # Not sure why this is needed but it appears to be the case. - # Also installs pytables so hdf5 gets installed on windows - - name: fix env - shell: bash -l {0} - run: | - micromamba shell init --shell bash --root-prefix=~/micromamba - eval "$(micromamba shell hook --shell bash)" - micromamba activate dascore - - - name: install hdf5 - shell: bash -l {0} - run: | - micromamba install pytables + python-version: ${{ matrix.python-version }} + install-package: false + environment-file: './.github/min_deps_environment.yml' # Then switch over to uv. We can use this exclusively once we drop pytables. - name: Install uv uses: astral-sh/setup-uv@v3 - - name: set data cache path - shell: bash -l {0} - run: | - export PATH="$pythonLocation:$PATH" - echo "DATA_CACHE_PATH=$(uv run --extra test python -c "import pooch; print(pooch.os_cache('dascore'))")" >> $GITHUB_ENV - - - name: cache test data - uses: actions/cache@v3 - with: - enableCrossOsArchive: true - path: ${{ env.DATA_CACHE_PATH }} - key: DATA_${{ env.CACHE_NUMBER }} - - name: run test suite shell: bash -l {0} run: uv run --extra test --python ${{ matrix.python-version }} pytest -s --cov dascore --cov-append --cov-report=xml diff --git a/.github/workflows/runtests.yml b/.github/workflows/runtests.yml index f36ec01b..d6142acf 100644 --- a/.github/workflows/runtests.yml +++ b/.github/workflows/runtests.yml @@ -41,60 +41,12 @@ jobs: steps: - uses: actions/checkout@v4 - - - name: "get tags" - run: | - git fetch --tags --force # Retrieve annotated tags. - - - uses: mamba-org/setup-micromamba@v2 with: - micromamba-version: '2.0.2-1' # versions: https://github.com/mamba-org/micromamba-releases - environment-file: environment.yml - init-shell: >- - bash - powershell - cache-environment: true - cache-environment-key: environment-${{ steps.date.outputs.date }} - post-cleanup: 'all' - create-args: >- - python=${{ matrix.python-version }} - - # Not sure why this is needed but it appears to be the case - - name: fix env - shell: bash -l {0} - run: | - micromamba shell init --shell bash --root-prefix=~/micromamba - eval "$(micromamba shell hook --shell bash)" - micromamba activate dascore + fetch-tags: 'true' - - name: print python version - shell: bash -el {0} - run: | - python --version - - - name: install dascore - shell: bash -el {0} - run: | - python -m pip install -e .[test,all] - - - name: set data cache path - shell: bash -el {0} - run: | - echo "DATA_CACHE_PATH=$(python -c "import pooch; print(pooch.os_cache('dascore'))")" >> $GITHUB_ENV - - - name: cache test data - uses: actions/cache@v3 + - uses: ./.github/actions/mamba-install-dascore with: - enableCrossOsArchive: true - path: ${{ env.DATA_CACHE_PATH }} - key: DATA_${{ env.CACHE_NUMBER }} - - # Print out the package info for current environment - - name: print package info - shell: bash -el {0} - run: | - micromamba info - micromamba list + python-version: ${{ matrix.python-version }} # Runs test suite and calculates coverage - name: run test suite