-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
351 lines (320 loc) · 15.5 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# The MIT License (MIT)
#
# Copyright © 2024 The GHDL Developers
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the “Software”), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
name: Setup GHDL
branding:
icon: play
color: gray-dark
description: Install and setup GHDL downloaded from GHDL's release pages at GitHub.
author: Patrick Lehmann (@Paebbels)
inputs:
version:
description: |
A tagged GHDL version starting at `v5.0.0` or `nightly`.
type: string
required: false
default: 'nightly'
backend:
description: |
GHDL backend: `llvm`, `llvm-jit`, `mcode`, `gcc`.
type: string
required: false
default: 'mcode'
runtime:
description: |
If runner OS is Windows, a MSYS2 runtime can be selected (`mingw64`, `ucrt64`). If not set, Windows native is used (not MSYS2 environment).
type: string
required: false
default: ''
install-directory:
description: |
Local installation directory, in case an archive asset is downloaded and extracted.
type: string
required: false
default: 'install'
investigate:
description: |
If enabled, more details are printed and check the GHDL installation is checked.
type: boolean
required: false
default: false
runs:
using: composite
steps:
- name: Detect correct shell
id: shell
shell: bash
run: |
# Detect correct shell
if [[ "${{ runner.os }}" == "Windows" && "${{ inputs.runtime }}" != "" ]]; then
printf "shell=msys2 {0}" >> $GITHUB_OUTPUT
else
printf "shell=bash" >> $GITHUB_OUTPUT
fi
- name: Update 'Bash' on macOS
if: runner.os == 'macOS'
shell: bash
run: |
# Update Bash on macOS
brew install bash
- name: Install 'jq' in Git Bash on Windows (native)
if: runner.os == 'Windows' && inputs.runtime == ''
shell: bash
run: |
printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Download 'jq' and copy to Git Bash ..."
curl -L -o /usr/bin/jq.exe https://github.com/jqlang/jq/releases/latest/download/jq-win64.exe
printf "::endgroup::\n"
- name: Download and install GHDL
id: generic
shell: ${{ steps.shell.outputs.shell }}
run: |
# Download and install GHDL
ANSI_LIGHT_RED=$'\x1b[91m'
ANSI_LIGHT_GREEN=$'\x1b[92m'
ANSI_LIGHT_BLUE="\e[94m"
ANSI_NOCOLOR=$'\x1b[0m'
if [[ "${{ runner.os }}" == "Linux" ]]; then
if [[ "${{ runner.arch }}" != "X64" ]]; then
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported architecture '${{ runner.arch }}' for Ubuntu."
exit 1
fi
source /etc/lsb-release
osName="Ubuntu"
osMajorVersion=${DISTRIB_RELEASE}
osArchitecture="x86-64"
osRuntime="native"
elif [[ "${{ runner.os }}" == "macOS" ]]; then
if [[ "${{ runner.arch }}" == "X64" ]]; then
osArchitecture="x86-64"
elif [[ "${{ runner.arch }}" == "ARM64" ]]; then
osArchitecture="aarch64"
else
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported macOS architecture '${{ runner.arch }}'."
exit 1
fi
osVersion="$(sw_vers -productVersion)"
osName="macOS"
osMajorVersion="${osVersion%%.*}"
osRuntime="native"
elif [[ "${{ runner.os }}" == "Windows" ]]; then
if [[ "${{ runner.arch }}" != "X64" ]]; then
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported architecture '${{ runner.arch }}' for Windows."
exit 1
fi
if [[ "${{ inputs.runtime }}" == "mingw64" ]]; then
osRuntime="mingw64"
printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Installing 'jq' file ..."
pacman -S --noconfirm mingw64/mingw-w64-x86_64-jq
printf "::endgroup::\n"
elif [[ "${{ inputs.runtime }}" == "ucrt64" ]]; then
osRuntime="ucrt64"
printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Installing 'jq' file ..."
pacman -S --noconfirm ucrt64/mingw-w64-ucrt-x86_64-jq
printf "::endgroup::\n"
elif [[ "${{ inputs.runtime }}" == "" ]]; then
osRuntime="native"
else
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported MSYS2 runtime '${{ inputs.runtime }}'."
exit 1
fi
osName="Windows"
osMajorVersion="2022"
osArchitecture="x86-64"
else
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported runner OS '${{ runner.os }}'."
exit 1
fi
# A generic test for supported named versions or tagged versions.
if [[ "${{ inputs.version }}" == "latest" ]]; then
# TODO: could be read from nightly's inventory.json
VERSION_IN_URL="v5.0.0"
elif [[ "${{ inputs.version }}" =~ ^v[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|nightly$ ]]; then
VERSION_IN_URL="${{ inputs.version }}"
elif [[ "${{ inputs.version }}" =~ ^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$ ]]; then
VERSION_IN_URL="v${{ inputs.version }}"
else
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported GHDL version '${{ inputs.version }}'."
exit 1
fi
# Check for generally supported GHDL backend names. A more specific test per platform follows later.
if ! [[ "${{ inputs.backend }}" =~ ^mcode|llvm(-jit)?|gcc$ ]]; then
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported GHDL backend '${{ inputs.backend }}'."
exit 1
fi
printf "Creating installation directory '${{ inputs.install-directory }}' ...\n"
mkdir -p "${{ inputs.install-directory }}"
cd "${{ inputs.install-directory }}"
DOWNLOAD_URL="https://github.com/ghdl/ghdl/releases/download/${VERSION_IN_URL}/inventory.json"
printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Downloading release inventory file from '${DOWNLOAD_URL}' ..."
curl -L "${DOWNLOAD_URL}" -o inventory.json
retCode=$?
printf "::endgroup::\n Downloading release inventory "
if [[ $retCode -eq 0 ]]; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s\${ANSI_NOCOLOR}n" "[FAILED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Failed to download 'inventory.json'."
exit 1
fi
printf "%s" "Check if runner OS '${osName}' is supported ... "
if jq -e ".files.ghdl | has(\"${osName,,}\")" inventory.json > /dev/null; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[UNSUPPORTED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported runner OS '${osName}'."
exit 1
fi
printf "%s" "Check if ${osName} version '${osMajorVersion}' is supported ... "
if jq -e ".files.ghdl.\"${osName,,}\" | has(\"${osMajorVersion}\")" inventory.json > /dev/null; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[UNSUPPORTED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported ${osName} version '${osMajorVersion}'."
exit 1
fi
printf "%s" "Check if ${osName} architecture '${osArchitecture}' is supported ... "
if jq -e ".files.ghdl.\"${osName,,}\".\"${osMajorVersion}\" | has(\"${osArchitecture}\")" inventory.json > /dev/null; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[UNSUPPORTED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported ${osName} architecture '${osArchitecture}'."
exit 1
fi
if [[ "${osName}" == "Windows" ]]; then
printf "%s" "Check if MSYS2 runtime '${osRuntime}' is supported ... "
if jq -e ".files.ghdl.\"${osName,,}\".\"${osMajorVersion}\".\"${osArchitecture}\" | has(\"${osRuntime}\")" inventory.json > /dev/null; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[UNSUPPORTED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported MSYS2 runtime '${osRuntime}'."
exit 1
fi
fi
printf "%s" "Check if GHDL backend '${{ inputs.backend }}' is supported for this runner OS version ... "
if jq -e ".files.ghdl.\"${osName,,}\".\"${osMajorVersion}\".\"${osArchitecture}\".\"${osRuntime}\" | has(\"${{ inputs.backend }}\")" inventory.json > /dev/null; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[UNSUPPORTED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Unsupported GHDL backend '${{ inputs.backend }}' for ${osName} ${osMajorVersion}."
exit 1
fi
printf "Runner OS: ${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "${osName} ${osMajorVersion} (${osArchitecture})"
printf "GHDL Backend: ${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "${{ inputs.backend }}"
printf "GHDL Version: ${ANSI_LIGHT_BLUE}%s (Git: %s)${ANSI_NOCOLOR}\n" "$(jq -r '.meta.version' inventory.json)" "$(jq -r '.meta."git-hash"' inventory.json)"
if [[ "${osName}" == "Windows" ]]; then
printf "MSYS2 Runtime: ${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "${osRuntime}"
fi
downloadBase="$(jq -r '.meta."release-url"' inventory.json)"
downloadFile="$(jq -r ".files.ghdl.\"${osName,,}\".\"${osMajorVersion}\".\"${osArchitecture}\".\"${osRuntime}\".\"${{ inputs.backend }}\".file" inventory.json)"
downloadFile="${downloadFile#*/}"
printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Downloading asset from '${downloadBase}/${downloadFile}' ..."
curl -L "${downloadBase}/${downloadFile}" -o "${downloadFile}"
retCode=$?
printf "::endgroup::\n Downloading GHDL installation archive "
if [[ $retCode -eq 0 ]]; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[FAILED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Failed to download '${downloadFile}'."
exit 1
fi
if [[ "${osRuntime}" == "native" ]]; then
if [[ "${osName}" == "Windows" ]]; then
printf "::group::${ANSI_LIGHT_BLUE}%s.${ANSI_NOCOLOR}\n" "Extracting '${downloadFile}' ..."
unzip "${downloadFile}"
retCode=$?
printf "::endgroup::\n Extracting archive "
if [[ $retCode -eq 0 ]]; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[FAILED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Failed to extract '${downloadFile}'."
exit 1
fi
else # macOS, Ubuntu
printf "%s" "Extracting installation archive ... "
tar -xzf "${downloadFile}" --strip-components 1
if [[ $? -eq 0 ]]; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[FAILED]"
printf "::error title=%s::%s\n" "setup-ghdl" "Failed to extract '${downloadFile}'."
exit 1
fi
fi
if [[ "${osName}" == "Ubuntu" ]]; then
printf "::group::${ANSI_LIGHT_BLUE}%s.${ANSI_NOCOLOR}\n" "Installing dependencies from './ubuntu.requirements' using 'apt-get' ..."
sudo xargs --no-run-if-empty -a ./ubuntu.requirements -- apt-get install -y --no-install-recommends
printf "::endgroup::\n"
fi
else
printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Installing '${downloadFile}' file ..."
pacman -U --noconfirm ${downloadFile}
printf "::endgroup::\n"
fi
printf "Deleting '%s' ... " "${downloadFile}"
rm "${downloadFile}"
if [[ $? -eq 0 ]]; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[FAILED]"
printf "::warning title=%s::%s\n" "setup-ghdl" "Failed to remove '${downloadFile}'."
fi
printf "%s" "Removing inventory file 'inventory.json' ... "
rm "inventory.json"
if [[ $? -eq 0 ]]; then
printf "${ANSI_LIGHT_GREEN}%s${ANSI_NOCOLOR}\n" "[OK]"
else
printf "${ANSI_LIGHT_RED}%s${ANSI_NOCOLOR}\n" "[FAILED]"
printf "::warning title=%s::%s\n" "setup-ghdl" "Couldn't remove 'inventory.json'."
fi
if [[ "${{ inputs.investigate }}" == "true" ]]; then
if [[ "${osName}" == "macOS" ]]; then
printf "::group::${ANSI_LIGHT_BLUE}%s${ANSI_NOCOLOR}\n" "Installing tree ..."
brew install tree
printf "::endgroup::\n"
fi
if ! [[ "${osName}" == "Windows" && "${osRuntime}" != "" ]]; then
printf "::group::${ANSI_LIGHT_BLUE}%s.${ANSI_NOCOLOR}\n" "Content of '$(pwd)'"
tree -pash .
printf "::endgroup::\n"
fi
fi
printf "Setting environment variable 'GHDL_PREFIX' ...\n"
if [[ "${osRuntime}" == "native" ]]; then
if [[ "${osName}" != "Windows" ]]; then
printf " GHDL_PREFIX=%s >> ${GITHUB_ENV}\n" "$(pwd)/lib/ghdl"
printf "GHDL_PREFIX=%s\n" "$(pwd)/lib/ghdl" >> ${GITHUB_ENV}
else
printf " GHDL_PREFIX=%s >> ${GITHUB_ENV}\n" "$(cygpath -w "$(pwd)/lib/ghdl")"
printf "GHDL_PREFIX=%s\n" "$(cygpath -w "$(pwd)/lib/ghdl")" >> ${GITHUB_ENV}
fi
else # MSYS2 packages -> search installation path via which
printf " GHDL_PREFIX=%s >> ${GITHUB_ENV}\n" "$(realpath $(dirname $(which ghdl))/../lib/ghdl)"
printf "GHDL_PREFIX=%s\n" "$(realpath $(dirname $(which ghdl))/../lib/ghdl)" >> ${GITHUB_ENV}
fi
printf "Adding GHDL to 'PATH' ...\n"
if [[ "${osRuntime}" == "native" ]]; then
if [[ "${osName}" != "Windows" ]]; then
printf " %s >> ${GITHUB_PATH}\n" "$(pwd)/bin"
printf "%s\n" "$(pwd)/bin" >> ${GITHUB_PATH}
else
printf " %s >> ${GITHUB_PATH}\n" "$(cygpath -w "$(pwd)/bin")"
printf "%s\n" "$(cygpath -w "$(pwd)/bin")" >> ${GITHUB_PATH}
fi
fi
printf "Writing step outputs ...\n"
printf " ❌ NOT IMPLEMENTED ❌\n"