Skip to content

Commit

Permalink
feat(inputs): make repo owner configurable (#17)
Browse files Browse the repository at this point in the history
* add owner input to support get-modflow --owner
* miscellaneous cleanup
* update cache key
* update readme
  • Loading branch information
wpbonelli committed Aug 8, 2023
1 parent ef41e23 commit d1a1c61
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
gm: [ flopy, standalone ]
owner: [ MODFLOW-USGS ]
repo: [ executables, modflow6, modflow6-nightly-build ]
path: [ absolute, relative, tilde, empty ]
cache: [ 'true', 'false' ]
Expand Down Expand Up @@ -81,6 +82,7 @@ jobs:
uses: ./
with:
path: ${{ env.TEST_BINDIR }}
owner: ${{ matrix.owner }}
repo: ${{ matrix.repo }}
cache: ${{ matrix.cache }}

Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ An action to setup MODFLOW 6 and related programs.
- [Environment variables](#environment-variables)
- [Inputs](#inputs)
- [`github_token`](#github_token)
- [`owner`](#owner)
- [`path`](#path)
- [`repo`](#repo)
- [`tag`](#tag)
- [`subset`](#subset)
- [`cache`](#cache)
- [Outputs](#outputs)
- [`cache-hit`](#cache-hit)
- [Cache key](#cache-key)
- [`code.json`](#codejson)
- [MODFLOW Resources](#modflow-resources)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand All @@ -45,7 +44,7 @@ The installation is cached by default, with the key changed daily. Daily key rot

## Usage

To use this action, add a step like the following to your workflow:
To install the latest version of MODFLOW 6 and ~20 related programs from the [MODFLOW-USGS/executables](https://github.com/MODFLOW-USGS/executables) distribution, add a step like the following to your workflow:

```yaml
- name: Install MODFLOW 6
Expand All @@ -62,17 +61,25 @@ This action sets the following environment variables:

The action accepts the following optional inputs:

- `cache`
- `github_token`
- `owner`
- `path`
- `repo`
- `tag`
- `subset`
- `cache`
- `tag`


### `github_token`

By default, the action uses the [automatically provided](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret) `GITHUB_TOKEN` secret, but an access token may be explicitly provided as well.

### `owner`

The `owner` input is the name of the repository's owner (username or organization).

This input can be used to install from releases on forks of MODFLOW 6, provided release assets use the same [operating system tag convention](https://modflow-devtools.readthedocs.io/en/latest/md/ostags.html#tag-specification) used by the official repositories.

### `path`

The `path` input is the location to install executables. The path may be absolute or relative to the workflow's working directory. Tilde expansion is also supported on all three major platforms. The resolved path is stored in the `MODFLOW_BIN_PATH` environment variable, which is then available to subsequent workflow steps.
Expand Down Expand Up @@ -115,15 +122,22 @@ The action has the following outputs:

The `cache-hit` output forwards the internal `actions/cache` output of the same name, and is `true` if a matching entry was found and `false` if not.

#### Cache key
Cache keys are composed from:

- runner OS
- repository owner
- repository name
- date
- hash of code.json
- subset of binaries to install (if specified)

Cache keys follow pattern:
With format:

```
modflow-${{ runner.os }}-${{ inputs.repo }}-${{ hashFiles('code.json') }}-${{ %Y%m%d }}
modflow-${{ runner.os }}-${{ inputs.owner }}-${{ inputs.repo }}-${{ %Y%m%d }}-${{ hashFiles('code.json') }}
```

#### `code.json`
If the `subset` input is provided, an additional clause `-${{ inputs.subset }}` is appended to the key.

`code.json` is a version metadata JSON file released with the `executables` distribution, for instance:

Expand Down
53 changes: 31 additions & 22 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
name: Install MODFLOW
description: Install & cache MODFLOW 6 and related programs.
inputs:
cache:
description: Whether to cache the installation
required: false
default: 'true'
github_token:
description: GitHub API access token
required: false
owner:
description: GitHub username or organization name
required: false
default: 'MODFLOW-USGS'
path:
description: Path to install location (e.g. a bin directory)
required: false
Expand All @@ -12,18 +20,15 @@ inputs:
description: Repository to install executables from ('executables', 'modflow6', or 'modflow6-nightly-build')
required: false
default: executables
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
tag:
description: Tag of the release version to install
required: false
default: 'true'
default: 'latest'

outputs:
cache-hit:
description: Whether the installation was restored from cache
Expand Down Expand Up @@ -70,7 +75,7 @@ runs:
shell: bash
run: |
# get info for the executables repository's latest release
release_json=$(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" "https://api.github.com/repos/MODFLOW-USGS/${{ inputs.repo }}/releases/latest") || echo "No release to check, skipping"
release_json=$(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GH_TOKEN" "https://api.github.com/repos/${{ inputs.owner }}/${{ inputs.repo }}/releases/latest") || echo "No release to check, skipping"
# get asset ID of the release's metadata file, if one exists
get_download_url="
Expand Down Expand Up @@ -99,28 +104,32 @@ runs:
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'
id: get-date
shell: bash
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> "$GITHUB_OUTPUT"

- name: Compose cache key
if: inputs.cache == 'true'
id: cache-key
shell: bash
run: |
key="modflow-${{ runner.os }}-${{ inputs.owner }}-${{ inputs.repo }}-${{ steps.get-date.outputs.date }}-${{ hashFiles(steps.check-release.outputs.code_json) }}"
if [[ "${{ inputs.subset }}" != "" ]]; then
subset="${{ inputs.subset }}"
subset=${subset//,/-} # replace commas with dashes
key="$key-$subset"
fi
echo "key=$key" >> "$GITHUB_OUTPUT"
- name: Cache executables
if: inputs.cache == 'true'
id: cache-modflow
uses: actions/cache@v3
with:
path: ${{ env.MODFLOW_BIN_PATH }}
key: modflow-${{ runner.os }}-${{ inputs.repo }}-${{ steps.commas.outputs.subset }}-${{ hashFiles(steps.check-release.outputs.code_json) }}-${{ steps.get-date.outputs.date }}
key: ${{ steps.cache-key.outputs.key }}

- name: Install executables
if: inputs.cache != 'true' || steps.cache-modflow.outputs.cache-hit != 'true'
Expand All @@ -130,9 +139,9 @@ runs:
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
get-modflow "$MODFLOW_BIN_PATH" --owner "${{ inputs.owner }}" --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
get-modflow "$MODFLOW_BIN_PATH" --owner "${{ inputs.owner }}" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}" --subset "${{ inputs.subset }}" --force
fi
else
echo "get-modflow command not available, downloading get_modflow.py"
Expand All @@ -141,9 +150,9 @@ runs:
echo "running get_modflow.py"
if [ "${{ inputs.subset }}" == "" ]; then
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}"
python3 $script_path "$MODFLOW_BIN_PATH" --owner "${{ inputs.owner }}" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}"
else
python3 $script_path "$MODFLOW_BIN_PATH" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}" --subset "${{ inputs.subset }}"
python3 $script_path "$MODFLOW_BIN_PATH" --owner "${{ inputs.owner }}" --repo "${{ inputs.repo }}" --release-id "${{ inputs.tag }}" --subset "${{ inputs.subset }}"
fi
fi
env:
Expand Down

0 comments on commit d1a1c61

Please sign in to comment.