From d1a1c61150fc2fdfd6b0e4290bb0adeae7dbd87b Mon Sep 17 00:00:00 2001 From: w-bonelli Date: Tue, 8 Aug 2023 11:02:54 -0400 Subject: [PATCH] feat(inputs): make repo owner configurable (#17) * add owner input to support get-modflow --owner * miscellaneous cleanup * update cache key * update readme --- .github/workflows/ci.yml | 2 ++ README.md | 32 +++++++++++++++++------- action.yml | 53 +++++++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a2bee3..0f6749b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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' ] @@ -81,6 +82,7 @@ jobs: uses: ./ with: path: ${{ env.TEST_BINDIR }} + owner: ${{ matrix.owner }} repo: ${{ matrix.repo }} cache: ${{ matrix.cache }} diff --git a/README.md b/README.md index e9fc4a8..23c9d7a 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ 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) @@ -22,8 +23,6 @@ An action to setup MODFLOW 6 and related programs. - [`cache`](#cache) - [Outputs](#outputs) - [`cache-hit`](#cache-hit) - - [Cache key](#cache-key) - - [`code.json`](#codejson) - [MODFLOW Resources](#modflow-resources) @@ -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 @@ -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. @@ -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: diff --git a/action.yml b/action.yml index db16722..a0b6084 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 @@ -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=" @@ -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' @@ -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" @@ -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: