Skip to content

Commit

Permalink
feat(inputs): add tag and subset inputs (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jun 8, 2023
1 parent 92fb40d commit 155256a
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 5 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,115 @@ jobs:
fi
python test/test.py "$TEST_BINDIR" "${{ matrix.repo }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test_subset:
name: Test subset input
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
subset: [ '', 'mf6,mf2005' ]
defaults:
run:
shell: bash
steps:

- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'

- name: Install Python dependencies
run: pip install -r test/requirements.txt

- name: Install FloPy
run: pip install git+https://github.com/modflowpy/flopy.git

- name: Set bin path
if: runner.os != 'Windows'
run: |
bindir=""
echo "TEST_BINDIR=$bindir" >> $GITHUB_ENV
- name: Set bin path (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$bindir = ""
echo "TEST_BINDIR=$bindir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install executables
id: install-executables
uses: ./
with:
path: ${{ env.TEST_BINDIR }}
subset: ${{ matrix.subset }}

- name: Test installation
run: |
script_path="$RUNNER_TEMP/get_modflow.py"
python test/test.py "$TEST_BINDIR" "executables" "${{ matrix.subset }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test_tag:
name: Test release tag input
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
tag: [ 'latest', '13.0' ]
defaults:
run:
shell: bash
steps:

- name: Checkout repo
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: 'pip'

- name: Install Python dependencies
run: pip install -r test/requirements.txt

- name: Install FloPy
run: pip install git+https://github.com/modflowpy/flopy.git

- name: Set bin path
if: runner.os != 'Windows'
run: |
bindir=""
echo "TEST_BINDIR=$bindir" >> $GITHUB_ENV
- name: Set bin path (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$bindir = ""
echo "TEST_BINDIR=$bindir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Install executables
id: install-executables
uses: ./
with:
path: ${{ env.TEST_BINDIR }}
tag: ${{ matrix.tag }}

- name: Test installation
run: |
script_path="$RUNNER_TEMP/get_modflow.py"
python test/test.py "$TEST_BINDIR" "executables"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ An action to setup MODFLOW 6 and related programs.
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Overview](#overview)
- [Usage](#usage)
- [Environment variables](#environment-variables)
- [Inputs](#inputs)
- [`github_token`](#github_token)
- [`path`](#path)
- [`repo`](#repo)
- [`tag`](#tag)
- [`subset`](#subset)
- [`cache`](#cache)
- [Outputs](#outputs)
- [`cache-hit`](#cache-hit)
Expand Down Expand Up @@ -62,6 +65,9 @@ The action accepts the following optional inputs:
- `github_token`
- `path`
- `repo`
- `tag`
- `subset`
- `cache`

### `github_token`

Expand All @@ -81,6 +87,18 @@ The `repo` input allows selecting which MODFLOW 6 executable distribution to ins
- `modflow6`
- `modflow6-nightly-build`

### `tag`

The `tag` input allows selecting a release by tag name. The default is `latest`.

For the `modflow6` distribution, releases are [tagged by semantic version number](https://github.com/MODFLOW-USGS/modflow6/tags). For the `modflow6-nightly-build` distribution, releases are [tagged by date](https://github.com/MODFLOW-USGS/modflow6-nightly-build/tags), in format `%Y%m%d`, e.g. `20230607`. For the `executables` distribution, releases are [tagged by integer version number with trailing ".0"](https://github.com/MODFLOW-USGS/executables/tags).

### `subset`

The `subset` input allows selecting which binaries to install. One or more binaries may be selected with a comma-separated string.

If this input is not provided, or if its value is an empty string, all binaries in the selected distribution are installed. This is the default behavior.

### `cache`

The `cache` input is a boolean that controls whether the action caches the MODFLOW binaries. The default is `true`.
Expand Down
34 changes: 30 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Install MODFLOW
description: Install & cache MODFLOW 6 and related programs.
inputs:
github_token:
description: GitHub API access token
required: false
path:
description: Path to install location (e.g. a bin directory)
required: false
Expand All @@ -9,9 +12,14 @@ inputs:
description: Repository to install executables from ('executables', 'modflow6', or 'modflow6-nightly-build')
required: false
default: executables
github_token:
description: GitHub API access token
tag:
description: Tag of the release version to install
required: false
default: 'latest'
subset:
description: Subset of binaries to install
required: False
default: ''
cache:
description: Whether to cache the installation
required: false
Expand Down Expand Up @@ -90,6 +98,15 @@ runs:
fi
env:
GH_TOKEN: ${{ steps.set-github-token.outputs.token }}

- name: Replace commas in subset input
id: commas
if: inputs.subset != ''
shell: bash
run: |
subset="${{ inputs.subset }}"
subset=${subset//,/_}
echo "subset=$subset" >> "$GITHUB_OUTPUT"
- name: Get date
if: inputs.cache == 'true'
Expand All @@ -103,7 +120,7 @@ runs:
uses: actions/cache@v3
with:
path: ${{ env.MODFLOW_BIN_PATH }}
key: modflow-${{ runner.os }}-${{ inputs.repo }}-${{ hashFiles(steps.check-release.outputs.code_json) }}-${{ steps.get-date.outputs.date }}
key: modflow-${{ runner.os }}-${{ inputs.repo }}-${{ steps.commas.outputs.subset }}-${{ hashFiles(steps.check-release.outputs.code_json) }}-${{ steps.get-date.outputs.date }}

- name: Install executables
if: inputs.cache != 'true' || steps.cache-modflow.outputs.cache-hit != 'true'
Expand All @@ -112,14 +129,23 @@ runs:
if command -v get-modflow &> /dev/null
then
echo "get-modflow command is available, running get-modflow"
if [ "${{ inputs.subset }}" == "" ]; then
get-modflow "$MODFLOW_BIN_PATH" --repo ${{ inputs.repo }} --release-id "${{ inputs.tag }}" --force
else
get-modflow "$MODFLOW_BIN_PATH" --repo ${{ inputs.repo }} --release-id "${{ inputs.tag }}" --subset "${{ inputs.subset }}" --force
fi
get-modflow "$MODFLOW_BIN_PATH" --repo ${{ inputs.repo }} --force
else
echo "get-modflow command not available, downloading get_modflow.py"
script_path="$RUNNER_TEMP/get_modflow.py"
curl https://raw.githubusercontent.com/modflowpy/flopy/develop/flopy/utils/get_modflow.py -o "$script_path"
echo "running get_modflow.py"
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}"
if [ "${{ inputs.subset }}" == "" ]; then
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}"
else
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}" --subset "${{ inputs.subset }}"
fi
fi
env:
GITHUB_TOKEN: ${{ steps.set-github-token.outputs.token }}
Expand Down
8 changes: 7 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from typing import List, Tuple

path = Path(sys.argv[1] if sys.argv[1] else "~/.local/bin/modflow").expanduser().absolute()
repo = sys.argv[2] if (len(sys.argv) > 1 and sys.argv[2]) else "executables"
repo = sys.argv[2] if (len(sys.argv) > 2 and sys.argv[2]) else "executables"
subset = sys.argv[3] if (len(sys.argv) > 3 and sys.argv[3]) else None

print(f"Path: {path}")
print(f"Repo: {repo}")
Expand Down Expand Up @@ -58,6 +59,11 @@
"modflow6-nightly-build": ["libmf6"]
}

# apply subset filter, if provided
if subset:
expected_exes = {k: [vv for vv in v if vv in subset] for k, v in expected_exes.items()}
expected_libs = {k: [vv for vv in v if vv in subset] for k, v in expected_libs.items()}


# TODO: can flopy also store code.json here (or reproduce it in get_modflow.json)?
# this would allow getting expected files from metadata instead of hardcoding them
Expand Down

0 comments on commit 155256a

Please sign in to comment.