-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
184 lines (169 loc) · 6.53 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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
default: "~/.local/bin/modflow"
repo:
description: Repository to install executables from ('executables', 'modflow6', or 'modflow6-nightly-build')
required: false
default: executables
subset:
description: Subset of binaries to install
required: False
default: ''
tag:
description: Tag of the release version to install
required: false
default: 'latest'
ostag:
description: Operating system tag; default is to automatically choose.
required: false
default: ''
outputs:
cache-hit:
description: Whether the installation was restored from cache
value: ${{ steps.cache-modflow.outputs.cache-hit }}
runs:
using: composite
steps:
- name: Set install path variable
if: runner.os != 'Windows'
shell: bash
run: |
path="${{ inputs.path }}"
path=${path:="~/.local/bin/modflow"}
normalized=$(python3 $GITHUB_ACTION_PATH/normalize_path.py "$path")
echo "Normalized bin dir path: $normalized"
echo "MODFLOW_BIN_PATH=$normalized" >> $GITHUB_ENV
mkdir -p "$normalized"
- name: Set install path variable (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$path = "${{ inputs.path }}"
$path = $(if ($path) { $path } else { "~/.local/bin/modflow" })
$normalized = $(python3 $(Join-Path -Path "$env:GITHUB_ACTION_PATH" -ChildPath "normalize_path.py") "$path")
echo "Normalized bin dir path: $normalized"
echo "MODFLOW_BIN_PATH=$normalized" | Out-File -FilePath "$env:GITHUB_ENV" -Encoding utf8 -Append
md -Force "$normalized"
- name: Set github token
id: set-github-token
shell: bash
run: |
if [ "${{ inputs.github_token }}" == "" ]; then
token="${{ github.token }}"
else
token="${{ inputs.github_token }}"
fi
echo "token=$token" >> $GITHUB_OUTPUT
- name: Check release
id: check-release
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/${{ 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="
import json
import sys
pattern = 'code.json'
release = json.load(sys.stdin, strict=False)
metadata = next(iter([a for a in release['assets'] if a['name'] == pattern]), None)
print(dict(metadata)['browser_download_url'] if metadata else '')
"
download_url=$(echo "$release_json" | python3 -c "$get_download_url") || echo "No release to check, skipping"
code_json="$RUNNER_TEMP/code.json"
echo "code_json=$code_json" >> $GITHUB_OUTPUT
# asset_id is empty if code.json asset wasn't found on the release
if [[ -n "$download_url" ]]; then
echo "Downloading code.json from $download_url to $code_json"
curl -L -H "Authorization: Bearer $GH_TOKEN" "$download_url" >> "$code_json"
echo "Found code.json for distribution '${{ inputs.repo }}' with contents:"
cat "$code_json"
else
# give hashFiles an empty file
echo "No code.json found for distribution '${{ inputs.repo }}', creating empty file"
touch "$code_json"
fi
env:
GH_TOKEN: ${{ steps.set-github-token.outputs.token }}
- 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 }}-${{ inputs.tag }}-${{ steps.get-date.outputs.date }}"
if [[ "${{ inputs.subset }}" != "" ]]; then
subset="${{ inputs.subset }}"
subset=${subset//,/-} # replace commas with dashes
key="$key-$subset"
fi
if [[ "${{ inputs.ostag }}" != "" ]]; then
ostag="${{ inputs.ostag }}"
key="$key-$ostag"
fi
echo "key=$key" >> "$GITHUB_OUTPUT"
- name: Cache executables
if: inputs.cache == 'true'
id: cache-modflow
uses: actions/cache@v4
with:
path: ${{ env.MODFLOW_BIN_PATH }}
key: ${{ steps.cache-key.outputs.key }}
- name: Install executables
if: inputs.cache != 'true' || steps.cache-modflow.outputs.cache-hit != 'true'
shell: bash
run: |
# compose arguments
args="--owner ${{ inputs.owner }} --repo ${{ inputs.repo }} --release-id ${{ inputs.tag }} --force"
if [[ "${{ inputs.subset }}" != "" ]]; then
args="$args --subset ${{ inputs.subset }}"
fi
if [[ "${{ inputs.ostag}}" != "" ]]; then
args="$args --ostag ${{ inputs.ostag }}"
fi
# download the installation script if necessary
if command -v get-modflow &> /dev/null
then
echo "get-modflow command is available"
cmd="get-modflow"
else
echo "get-modflow command not available, downloading install script"
script_path="$RUNNER_TEMP/get_modflow.py"
curl https://raw.githubusercontent.com/modflowpy/flopy/develop/flopy/utils/get_modflow.py -o "$script_path"
cmd="python3 $script_path"
fi
echo "starting installation"
$cmd $MODFLOW_BIN_PATH $args
env:
GITHUB_TOKEN: ${{ steps.set-github-token.outputs.token }}
- name: Add executables to path
if: runner.os != 'Windows'
shell: bash
run: |
echo "adding bin dir '$MODFLOW_BIN_PATH' to path"
echo "$MODFLOW_BIN_PATH" >> $GITHUB_PATH
- name: Add executables to path (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
echo "adding bin dir '$env:MODFLOW_BIN_PATH' to path"
echo $env:MODFLOW_BIN_PATH | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append