From 37a69833bba1f34797709ba19bda3bfc5dc5dee8 Mon Sep 17 00:00:00 2001 From: Wes Bonelli Date: Thu, 8 Jun 2023 15:04:23 -0400 Subject: [PATCH] feat(inputs): add tag and subset inputs --- .github/workflows/ci.yml | 110 +++++++++++++++++++++++++++++++++++++++ README.md | 18 +++++++ action.yml | 34 ++++++++++-- test/test.py | 8 ++- 4 files changed, 165 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 49e1220..3a2bee3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 }} \ No newline at end of file diff --git a/README.md b/README.md index ed11492..e9fc4a8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ An action to setup MODFLOW 6 and related programs. + - [Overview](#overview) - [Usage](#usage) - [Environment variables](#environment-variables) @@ -16,6 +17,8 @@ An action to setup MODFLOW 6 and related programs. - [`github_token`](#github_token) - [`path`](#path) - [`repo`](#repo) + - [`tag`](#tag) + - [`subset`](#subset) - [`cache`](#cache) - [Outputs](#outputs) - [`cache-hit`](#cache-hit) @@ -62,6 +65,9 @@ The action accepts the following optional inputs: - `github_token` - `path` - `repo` +- `tag` +- `subset` +- `cache` ### `github_token` @@ -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`. diff --git a/action.yml b/action.yml index edda709..c886d48 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 @@ -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' @@ -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' @@ -112,6 +129,11 @@ 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" @@ -119,7 +141,11 @@ runs: 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 }} diff --git a/test/test.py b/test/test.py index 6c9987a..886923a 100644 --- a/test/test.py +++ b/test/test.py @@ -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}") @@ -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