-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaction.yml
236 lines (198 loc) · 8.62 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
# Copyright (C) 2022 - 2025 ANSYS, Inc. and/or its affiliates.
# SPDX-License-Identifier: MIT
#
#
# 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: |
Check licenses action
description: |
Verifies if the licenses of the dependencies installed in the current
environment are compliant with PyAnsys guidelines. This action is assumed to
be used in its own job step. It clones the project and installs the project with
its runtime dependencies.
.. note::
**This action relies on PyPI metadata to identify the license for each package.**
If the metadata are flawed or not included, it may lead to
inconclusive results. In those cases, please perform a thorough review of the
package you are using. Additionally, it is advised not to blindly rely on PyPI metadata.
Even though packages may define their license as of a certain type, the
package could be not applying properly its licensing conditions.
.. jinja:: check-licenses
.. grid:: 1 1 1 2
:gutter: 2
.. grid-item-card:: :octicon:`codescan-checkmark` Accepted third party licenses
{% for license in accepted_licenses %}
* {{ license }}
{% endfor %}
.. grid-item-card:: :octicon:`package` Ignored packages
{% for package in ignored_packages %}
* {{ package }}
{% endfor %}
.. admonition:: Projects requiring additional licenses or packages
If a certain project requires a license or package that is not supported,
`open an issue <https://github.com/ansys/actions/issues>`_ in the
`official ansys/actions repository
<https://github.com/ansys/actions>`_. For additional support, please
contact the `PyAnsys support <mailto:[email protected]>`_.
inputs:
# Optional inputs
python-version:
description: |
Python version used for installing and executing licence check.
default: '3.11'
required: false
type: string
use-python-cache:
description: |
Whether to use the Python cache for installing previously downloaded
libraries. If ``true``, previously downloaded libraries are installed from the
Python cache. If ``false``, libraries are downloaded from the PyPI index.
required: false
default: true
type: boolean
target:
description: |
Optional target used during the building process.
required: false
default: ''
type: string
whitelist-license-check:
description: |
Optional list of packages to ignore during the license check. Separated by a comma.
required: false
default: ''
type: string
skip-install:
description: |
Whether to skip the installation of the project. The default is ``false``.
If used in combination with other actions, it might not be needed to install
the project.
default: false
required: false
type: boolean
checkout:
description: |
Whether to clone the repository in the CI/CD machine. Default value is
``true``.
default: true
required: false
type: boolean
runs:
using: "composite"
steps:
- name: "Install Git and clone project"
uses: actions/checkout@v4
if: ${{ inputs.checkout == 'true' }}
- name: "Set up Python"
uses: ansys/actions/_setup-python@main
with:
python-version: ${{ inputs.python-version }}
use-cache: ${{ inputs.use-python-cache }}
- name: "Update pip and install the pip-licenses library"
shell: bash
run: |
python -m pip install -U pip pip-licenses
- name: "Check if specific target is requested"
shell: bash
run: |
echo "install_target=$( [[ '${{ inputs.target }}' == '' ]] && echo '.' || echo '.[${{ inputs.target }}]')" >> $GITHUB_ENV
- name: "Install Python library"
if: inputs.skip-install == 'false'
shell: bash
run: pip install ${{ env.install_target }}
- name: "Install wget on Windows"
if: runner.os == 'Windows'
shell: pwsh
run: |
# Check if wget is installed - if not, install it
if (-not (Get-Command wget -ErrorAction SilentlyContinue)) {
Write-Host "wget is not installed. Installing using Chocolatey..."
# Install wget using Chocolatey
choco install wget -y
} else {
Write-Host "wget is already installed."
}
- name: "Update bash on macOS"
if: runner.os == 'macOS'
shell: bash
run: |
brew install bash
- name: "Download the list of accepted and ignored packages"
shell: bash
run: |
wget https://raw.githubusercontent.com/ansys/actions/main/check-licenses/accepted-licenses.txt
wget https://raw.githubusercontent.com/ansys/actions/main/check-licenses/ignored-packages.txt
- name: "Process whitelisted packages provided on input"
shell: bash
run: |
if [[ -n "${{ inputs.whitelist-license-check }}" ]]; then
echo "Whitelisted packages: ${{ inputs.whitelist-license-check }}"
# Split the input string by comma, trim values and append them to the ignored-packages.txt file
IFS=',' read -ra whitelist <<< "${{ inputs.whitelist-license-check }}"
for package in "${whitelist[@]}"; do
echo "Ignoring whitelisted package: $package"
echo "$package" >> ignored-packages.txt
done
fi
- name: "Logging licenses and packages"
shell: bash
run: |
# Load accepted licenses
mapfile licenses_from_txt < accepted-licenses.txt
accepted_licenses='Accepted licenses:\n'
for license in ${licenses_from_txt[*]}; do accepted_licenses+="$license\n"; done
echo "LOG_ACCEPTED_LICENSES=$accepted_licenses" >> $GITHUB_ENV
# Load accepted packages
mapfile ignored_packages_from_txt < ignored-packages.txt
ignored_packages='Ignored packages:\n'
for pckg in ${ignored_packages_from_txt[*]}; do ignored_packages+="$pckg\n"; done
echo "LOG_IGNORED_PACKAGES=$ignored_packages" >> $GITHUB_ENV
- name: Log ignored packages and accepted licenses
uses: ansys/actions/_logging@main
with:
level: "INFO"
message: |
Licenses accepted and packages ignored
----------------------------------------------
${{ env.LOG_ACCEPTED_LICENSES }}
${{ env.LOG_IGNORED_PACKAGES }}
- name: "Check licences of packages"
shell: bash
run: |
# Load accepted licenses
mapfile licenses_from_txt < accepted-licenses.txt
accepted_licenses=''
for license in ${licenses_from_txt[*]}; do accepted_licenses+="$license\|"; done
accepted_licenses=${accepted_licenses::-2}
# Load accepted packages
mapfile ignored_packages_from_txt < ignored-packages.txt
ignored_packages=''
for pckg in ${ignored_packages_from_txt[*]}; do ignored_packages+="$pckg "; done
ignored_packages_from_txt=${ignored_packages_from_txt::-1}
# Verify if the Python environment contains invalid licenses
if [[ -z $(pip-licenses --summary --ignore-packages $ignored_packages | grep '^[[:space:]]*[0-9]' | grep -v $accepted_licenses ) ]]; then
echo "All licenses are valid."
else
echo -e "\nInvalid licenses found:\n"
pip-licenses --ignore-packages $ignored_packages | awk 'NR>1 && NF >= 3 && $2 ~ /^[0-9]+(\.[0-9]+)*$/' | grep -v $accepted_licenses | awk '{ for (i=3; i<=NF; i++) license = license $i (i==NF ? "" : " "); print $1 " " $2 " has " license; license="" }'
# print all packages
echo -e "\n\n"
pip-licenses --ignore-packages $ignored_packages
exit 1
fi