Update version #22
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Upload Python Package | |
on: | |
workflow_dispatch: | |
push: | |
tags: | |
- "[0-9][0-9].[0-9][0-9]*" | |
env: | |
MLM_LICENSE_TOKEN: ${{ secrets.MATLAB_BATCH_TOKEN }} | |
permissions: | |
contents: write | |
jobs: | |
compile-and-deploy: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: ['ubuntu-latest'] | |
matlab: ['R2024b'] | |
include: | |
- matlab: "R2020b" | |
python: "2.7" | |
os: 'ubuntu-20.04' | |
- matlab: "R2020b" | |
python: "3.8" | |
py3from: "3.6" | |
py3to: "3.9" | |
- matlab: "R2021a" | |
python: "2.7" | |
os: 'ubuntu-20.04' | |
- matlab: "R2021a" | |
python: "3.8" | |
py3from: "3.7" | |
py3to: "3.9" | |
- matlab: "R2021b" | |
python: "2.7" | |
os: 'ubuntu-20.04' | |
- matlab: "R2021b" | |
python: "3.9" | |
py3from: "3.7" | |
py3to: "3.10" | |
- matlab: "R2022a" | |
python: "2.7" | |
os: 'ubuntu-20.04' | |
- matlab: "R2022a" | |
python: "3.9" | |
py3from: "3.8" | |
py3to: "3.10" | |
- matlab: "R2022b" | |
python: "2.7" | |
os: 'ubuntu-20.04' | |
- matlab: "R2022b" | |
python: "3.10" | |
py3from: "3.8" | |
py3to: "3.11" | |
- matlab: "R2023a" | |
python: "3.10" | |
py3from: "3.8" | |
py3to: "3.11" | |
- matlab: "R2023b" | |
python: "3.11" | |
py3from: "3.9" | |
py3to: "3.12" | |
- matlab: "R2024a" | |
python: "3.11" | |
py3from: "3.9" | |
py3to: "3.12" | |
- matlab: "R2024b" | |
python: "3.12" | |
py3from: "3.9" | |
py3to: "3.13" | |
- matlab: "R2024b" | |
main: "true" | |
python: "3.12" | |
py3from: "3.9" | |
py3to: "3.13" | |
steps: | |
- name: Set up MATLAB | |
uses: matlab-actions/setup-matlab@v2 | |
with: | |
cache: True | |
release: ${{ matrix.matlab }} | |
products: | | |
MATLAB_Compiler | |
MATLAB_Compiler_SDK | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Run MPython | |
uses: matlab-actions/run-command@v2 | |
with: | |
command: | | |
cd('.mpython'); | |
addpath(genpath('.')); | |
spm_make_python('.', true, false); | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install build | |
pip install numpy | |
- name: Setup python version | |
if: ${{ matrix.main }} | |
run: | | |
sed -i 's/\(version = "[^"]*\)"/version = "${{ github.ref_name }}"/' pyproject.toml | |
- name: Add Matlab version specifier | |
if: ${{ !matrix.main }} | |
run: | | |
sed -i 's/\(version = "[^"]*\)"/\1+${{ matrix.matlab }}"/' pyproject.toml | |
- name: Setup Python version (2.7) | |
if: ${{ !matrix.py3from }} | |
run: | | |
sed -i 's/^python-requires = .*/python-requires = ">=2.7,<3.1"/' pyproject.toml | |
echo "[tool.distutils.bdist_wheel]" >> pyproject.toml | |
echo "python-tag = \"2.7\"" >> pyproject.toml | |
cat pyproject.toml | |
- name: Setup Python version (3+) | |
if: ${{ matrix.py3from }} | |
run: | | |
FROM=${{ matrix.py3from }} | |
TO=${{ matrix.py3to }} | |
sed -i 's/^python-requires = .*/python-requires = "$FROM>=,<$TO"/' pyproject.toml | |
tags=$(for i in $(seq ${FROM//3./} $(( ${TO//3./} - 1)) ); do echo -n "py3$i."; done | sed 's/\.$//') | |
echo "[tool.distutils.bdist_wheel]" >> pyproject.toml | |
echo "python-tag = \"$tags\"" >> pyproject.toml | |
cat pyproject.toml | |
- name: Build package | |
run: python -m build --sdist --wheel | |
- name: Extract MATLAB path to file | |
uses: matlab-actions/run-command@v2 | |
with: | |
command: | | |
fileID = fopen('matlab_path.txt', 'w'); | |
matlabpath = matlabroot; | |
matlabpath = strrep(matlabpath, filesep, '/'); | |
matlabpath = strrep(matlabpath, '\', '\\'); | |
matlabpath = strrep(matlabpath, 'C:', '/c/'); | |
matlabpath = strrep(matlabpath, 'D:', '/d/'); | |
fprintf(fileID, matlabpath); | |
fclose(fileID); | |
# sometimes this step hangs when closing matlab, automatically terminating after 2 minutes solves the issue | |
timeout-minutes: 2 | |
continue-on-error: true | |
- name: Set environment variable with MATLAB path | |
shell: bash # Works on Windows as well because of shell: bash | |
run: | | |
matlab_path=$(cat matlab_path.txt) | |
echo "MATLAB_PATH=$matlab_path" >> $GITHUB_ENV | |
- name: Install package | |
run: | | |
python -m pip install $(find ./dist -name "*.whl") | |
- name: Run unit tests | |
run: | | |
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}\ | |
${{ env.MATLAB_PATH }}/runtime/glnxa64:\ | |
${{ env.MATLAB_PATH }}/bin/glnxa64:\ | |
${{ env.MATLAB_PATH }}/sys/os/glnxa64:\ | |
${{ env.MATLAB_PATH }}/extern/bin/glnxa64" | |
python -m unittest discover tests -v | |
- name: Detect pre-release | |
shell: bash | |
run: | | |
if echo "${{ github.ref_name }}" | grep -q '^[0-9][0-9]\.[0-9][0-9]\.[A-Za-z]'; then | |
echo "PRERELEASE=true" >> $GITHUB_ENV | |
else | |
echo "PRERELEASE=false" >> $GITHUB_ENV | |
fi | |
echo PRERELEASE=${{ env.PRERELEASE }} | |
- name: Release package | |
uses: softprops/action-gh-release@v2 | |
with: | |
prerelease: ${{ env.PRERELEASE }} | |
files: ./dist/spm_python*.whl | |
continue-on-error: true | |
- name: Publish package | |
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | |
with: | |
user: __token__ | |
password: ${{ secrets.PYPI_API_TOKEN }} | |