-
Notifications
You must be signed in to change notification settings - Fork 6
/
action.yml
158 lines (131 loc) · 5.37 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
name: >
Build wheelhouse action
description: |
Generates compressed artifacts for the wheelhouse of a Python library. The
wheelhouse contains all the necessary dependencies to install the project.
This allows for local installations and avoids the need to connect to the
online PyPI index.
.. warning::
Since version 4.1, the input parameter ``library-namespace`` is no longer
required.
inputs:
# Required inputs
library-name:
description: >
Name of the Python library. This is the name used when uploading the wheel
and source distribution as artifacts. The name should be the same one used
in the PyPI index.
required: true
type: string
operating-system:
description: >
Name of the operating system where the library is installed.
required: true
type: string
python-version:
description: >
Python version used for installing and execution of the build wheel process.
required: true
type: string
# Optional inputs
target:
description: >
Optional target used during the building process.
required: false
default: ''
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
check-licenses:
description: >
Whether to check the library's dependencies license or not. If ``true``. the licenses
are checked. If ``false``, no license check is performed. By default it is set to
``true``.
required: false
default: true
type: boolean
runs:
using: "composite"
steps:
- name: "Install Git and clone project"
uses: actions/checkout@v4
- name: "Set up Python ${{ inputs.python-version }}"
uses: ansys/actions/_setup-python@main
with:
python-version: ${{ inputs.python-version }}
use-cache: ${{ inputs.use-python-cache }}
- name: "Update pip and install the build and wheel libraries"
shell: bash
run: |
python -m pip install --upgrade pip build wheel
- name: "Check if specific target is requested"
shell: bash
run: |
echo "install_target=$( [[ '${{ inputs.target }}' == '' ]] && echo '.' || echo '.[${{ inputs.target }}]')" >> $GITHUB_ENV
echo "wheelhouse_target=$( [[ '${{ inputs.target }}' == '' ]] && echo 'wheelhouse' || echo '${{ inputs.target }}-wheelhouse')" >> $GITHUB_ENV
- name: "Install the library"
shell: bash
run: |
python -m pip install ${{ env.install_target }}
- name: "Verify if importlib-metadata needs to be installed"
shell: bash
run: |
python_version="${{ inputs.python-version }}"
minor_python_version=$(echo "$python_version" | awk -F "." '{print $2}')
major_python_version=$(echo "$python_version" | awk -F "." '{print $1}')
if (( $(( $major_python_version == 3 )) )) && (( $(( $minor_python_version < 8 )) )); then
echo "needs_importlib_metadata=true" >> $GITHUB_ENV
elif (( $(( $major_python_version < 3 )) )); then
echo "needs_importlib_metadata=true" >> $GITHUB_ENV
else
echo "needs_importlib_metadata=false" >> $GITHUB_ENV
fi
- name: "Install importlib-metadata (only for Python <= 3.7)"
if: env.needs_importlib_metadata == 'true'
shell: bash
run: |
python -m pip install importlib-metadata
- name: "Verify library is properly installed and get its version number"
shell: bash
run: |
library_name=${{ inputs.library-name }}
if [ ${{ env.needs_importlib_metadata }} == 'true' ]; then
version=$(python -c "import importlib_metadata; print(importlib_metadata.version('$library_name'))")
else
version=$(python -c "import importlib.metadata as importlib_metadata; print(importlib_metadata.version('$library_name'))")
fi
if [ -z "$version" ]; then
echo "Problem getting the library version"
exit 1;
else
echo "The library version is: $version";
fi;
echo "library_version=$version" >> $GITHUB_ENV
- name: "Generate the wheelhouse"
shell: bash
run: |
python -m pip wheel ${{ env.install_target }} -w wheelhouse
- name: "Compress the wheelhouse"
uses: vimtor/[email protected]
with:
files: wheelhouse
dest: ${{ inputs.library-name }}-v${{ env.library_version }}-${{ env.wheelhouse_target }}-${{ inputs.operating-system }}-${{ inputs.python-version }}.zip
- name: "Upload the compressed wheelhouse"
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.library-name }}-v${{ env.library_version }}-${{ env.wheelhouse_target }}-${{ inputs.operating-system }}-${{ inputs.python-version }}
path: ${{ inputs.library-name }}-v${{ env.library_version }}-${{ env.wheelhouse_target }}-${{ inputs.operating-system }}-${{ inputs.python-version }}.zip
retention-days: 7
- name: Check library's dependencies license
uses: ansys/actions/check-licenses@main
if: ${{ inputs.check-licenses == 'true' }}
with:
python-version: ${{ inputs.python-version }}
skip-install: true
checkout: false