Skip to content

Commit 155256a

Browse files
authored
feat(inputs): add tag and subset inputs (#15)
1 parent 92fb40d commit 155256a

File tree

4 files changed

+165
-5
lines changed

4 files changed

+165
-5
lines changed

.github/workflows/ci.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,115 @@ jobs:
100100
fi
101101
102102
python test/test.py "$TEST_BINDIR" "${{ matrix.repo }}"
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
106+
test_subset:
107+
name: Test subset input
108+
runs-on: ${{ matrix.os }}
109+
strategy:
110+
fail-fast: false
111+
matrix:
112+
os: [ ubuntu-latest, macos-latest, windows-latest ]
113+
subset: [ '', 'mf6,mf2005' ]
114+
defaults:
115+
run:
116+
shell: bash
117+
steps:
118+
119+
- name: Checkout repo
120+
uses: actions/checkout@v3
121+
122+
- name: Setup Python
123+
uses: actions/setup-python@v4
124+
with:
125+
python-version: 3.9
126+
cache: 'pip'
127+
128+
- name: Install Python dependencies
129+
run: pip install -r test/requirements.txt
130+
131+
- name: Install FloPy
132+
run: pip install git+https://github.com/modflowpy/flopy.git
133+
134+
- name: Set bin path
135+
if: runner.os != 'Windows'
136+
run: |
137+
bindir=""
138+
echo "TEST_BINDIR=$bindir" >> $GITHUB_ENV
139+
140+
- name: Set bin path (Windows)
141+
if: runner.os == 'Windows'
142+
shell: pwsh
143+
run: |
144+
$bindir = ""
145+
echo "TEST_BINDIR=$bindir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
146+
147+
- name: Install executables
148+
id: install-executables
149+
uses: ./
150+
with:
151+
path: ${{ env.TEST_BINDIR }}
152+
subset: ${{ matrix.subset }}
153+
154+
- name: Test installation
155+
run: |
156+
script_path="$RUNNER_TEMP/get_modflow.py"
157+
python test/test.py "$TEST_BINDIR" "executables" "${{ matrix.subset }}"
158+
env:
159+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
160+
161+
test_tag:
162+
name: Test release tag input
163+
runs-on: ${{ matrix.os }}
164+
strategy:
165+
fail-fast: false
166+
matrix:
167+
os: [ ubuntu-latest, macos-latest, windows-latest ]
168+
tag: [ 'latest', '13.0' ]
169+
defaults:
170+
run:
171+
shell: bash
172+
steps:
173+
174+
- name: Checkout repo
175+
uses: actions/checkout@v3
176+
177+
- name: Setup Python
178+
uses: actions/setup-python@v4
179+
with:
180+
python-version: 3.9
181+
cache: 'pip'
182+
183+
- name: Install Python dependencies
184+
run: pip install -r test/requirements.txt
185+
186+
- name: Install FloPy
187+
run: pip install git+https://github.com/modflowpy/flopy.git
188+
189+
- name: Set bin path
190+
if: runner.os != 'Windows'
191+
run: |
192+
bindir=""
193+
echo "TEST_BINDIR=$bindir" >> $GITHUB_ENV
194+
195+
- name: Set bin path (Windows)
196+
if: runner.os == 'Windows'
197+
shell: pwsh
198+
run: |
199+
$bindir = ""
200+
echo "TEST_BINDIR=$bindir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
201+
202+
- name: Install executables
203+
id: install-executables
204+
uses: ./
205+
with:
206+
path: ${{ env.TEST_BINDIR }}
207+
tag: ${{ matrix.tag }}
208+
209+
- name: Test installation
210+
run: |
211+
script_path="$RUNNER_TEMP/get_modflow.py"
212+
python test/test.py "$TEST_BINDIR" "executables"
103213
env:
104214
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ An action to setup MODFLOW 6 and related programs.
99
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1010
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1111

12+
1213
- [Overview](#overview)
1314
- [Usage](#usage)
1415
- [Environment variables](#environment-variables)
1516
- [Inputs](#inputs)
1617
- [`github_token`](#github_token)
1718
- [`path`](#path)
1819
- [`repo`](#repo)
20+
- [`tag`](#tag)
21+
- [`subset`](#subset)
1922
- [`cache`](#cache)
2023
- [Outputs](#outputs)
2124
- [`cache-hit`](#cache-hit)
@@ -62,6 +65,9 @@ The action accepts the following optional inputs:
6265
- `github_token`
6366
- `path`
6467
- `repo`
68+
- `tag`
69+
- `subset`
70+
- `cache`
6571

6672
### `github_token`
6773

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

90+
### `tag`
91+
92+
The `tag` input allows selecting a release by tag name. The default is `latest`.
93+
94+
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).
95+
96+
### `subset`
97+
98+
The `subset` input allows selecting which binaries to install. One or more binaries may be selected with a comma-separated string.
99+
100+
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.
101+
84102
### `cache`
85103

86104
The `cache` input is a boolean that controls whether the action caches the MODFLOW binaries. The default is `true`.

action.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Install MODFLOW
22
description: Install & cache MODFLOW 6 and related programs.
33
inputs:
4+
github_token:
5+
description: GitHub API access token
6+
required: false
47
path:
58
description: Path to install location (e.g. a bin directory)
69
required: false
@@ -9,9 +12,14 @@ inputs:
912
description: Repository to install executables from ('executables', 'modflow6', or 'modflow6-nightly-build')
1013
required: false
1114
default: executables
12-
github_token:
13-
description: GitHub API access token
15+
tag:
16+
description: Tag of the release version to install
1417
required: false
18+
default: 'latest'
19+
subset:
20+
description: Subset of binaries to install
21+
required: False
22+
default: ''
1523
cache:
1624
description: Whether to cache the installation
1725
required: false
@@ -90,6 +98,15 @@ runs:
9098
fi
9199
env:
92100
GH_TOKEN: ${{ steps.set-github-token.outputs.token }}
101+
102+
- name: Replace commas in subset input
103+
id: commas
104+
if: inputs.subset != ''
105+
shell: bash
106+
run: |
107+
subset="${{ inputs.subset }}"
108+
subset=${subset//,/_}
109+
echo "subset=$subset" >> "$GITHUB_OUTPUT"
93110
94111
- name: Get date
95112
if: inputs.cache == 'true'
@@ -103,7 +120,7 @@ runs:
103120
uses: actions/cache@v3
104121
with:
105122
path: ${{ env.MODFLOW_BIN_PATH }}
106-
key: modflow-${{ runner.os }}-${{ inputs.repo }}-${{ hashFiles(steps.check-release.outputs.code_json) }}-${{ steps.get-date.outputs.date }}
123+
key: modflow-${{ runner.os }}-${{ inputs.repo }}-${{ steps.commas.outputs.subset }}-${{ hashFiles(steps.check-release.outputs.code_json) }}-${{ steps.get-date.outputs.date }}
107124

108125
- name: Install executables
109126
if: inputs.cache != 'true' || steps.cache-modflow.outputs.cache-hit != 'true'
@@ -112,14 +129,23 @@ runs:
112129
if command -v get-modflow &> /dev/null
113130
then
114131
echo "get-modflow command is available, running get-modflow"
132+
if [ "${{ inputs.subset }}" == "" ]; then
133+
get-modflow "$MODFLOW_BIN_PATH" --repo ${{ inputs.repo }} --release-id "${{ inputs.tag }}" --force
134+
else
135+
get-modflow "$MODFLOW_BIN_PATH" --repo ${{ inputs.repo }} --release-id "${{ inputs.tag }}" --subset "${{ inputs.subset }}" --force
136+
fi
115137
get-modflow "$MODFLOW_BIN_PATH" --repo ${{ inputs.repo }} --force
116138
else
117139
echo "get-modflow command not available, downloading get_modflow.py"
118140
script_path="$RUNNER_TEMP/get_modflow.py"
119141
curl https://raw.githubusercontent.com/modflowpy/flopy/develop/flopy/utils/get_modflow.py -o "$script_path"
120142
121143
echo "running get_modflow.py"
122-
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}"
144+
if [ "${{ inputs.subset }}" == "" ]; then
145+
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}"
146+
else
147+
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}" --subset "${{ inputs.subset }}"
148+
fi
123149
fi
124150
env:
125151
GITHUB_TOKEN: ${{ steps.set-github-token.outputs.token }}

test/test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from typing import List, Tuple
1111

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

1516
print(f"Path: {path}")
1617
print(f"Repo: {repo}")
@@ -58,6 +59,11 @@
5859
"modflow6-nightly-build": ["libmf6"]
5960
}
6061

62+
# apply subset filter, if provided
63+
if subset:
64+
expected_exes = {k: [vv for vv in v if vv in subset] for k, v in expected_exes.items()}
65+
expected_libs = {k: [vv for vv in v if vv in subset] for k, v in expected_libs.items()}
66+
6167

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

0 commit comments

Comments
 (0)