Merge pull request #163 from simmsa/hotfix-update-toolbox-binary #2
This file contains hidden or 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: Build Production and Development Release | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - develop | |
| jobs: | |
| build-toolbox: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Verify Version Numbers | |
| run: | | |
| # Extract version from pyproject.toml | |
| PYPROJECT_VERSION=$(grep -Po '(?<=version = ")[^"]*' pyproject.toml) | |
| # Extract version from __init__.py | |
| INIT_PY_VERSION=$(grep -Po '(?<=__version__ = ")[^"]*' mhkit_python_utils/__init__.py) | |
| # Extract version from build_release.m | |
| MATLAB_VERSION=$(grep -Po "(?<=project_version = ')[^']*" scripts/build_release.m) | |
| echo "Versions found:" | |
| echo "pyproject.toml: $PYPROJECT_VERSION" | |
| echo "__init__.py: $INIT_PY_VERSION" | |
| echo "build_release.m: $MATLAB_VERSION" | |
| # Verify all versions match | |
| if [ "$PYPROJECT_VERSION" != "$INIT_PY_VERSION" ] || [ "$PYPROJECT_VERSION" != "$MATLAB_VERSION" ]; then | |
| echo "Error: Version numbers do not match across files!" | |
| echo "Please ensure versions are consistent in:" | |
| echo "- pyproject.toml ($PYPROJECT_VERSION)" | |
| echo "- mhkit_python_utils/__init__.py ($INIT_PY_VERSION)" | |
| echo "- scripts/build_release.m ($MATLAB_VERSION)" | |
| exit 1 | |
| fi | |
| # Set version as environment variable for later use | |
| echo "MHKIT_MATLAB_VERSION=$MATLAB_VERSION" >> $GITHUB_ENV | |
| - name: Check for existing version tag | |
| run: | | |
| if git ls-remote --exit-code --tags origin "refs/tags/v${MHKIT_MATLAB_VERSION}" >/dev/null 2>&1; then | |
| echo "Error: Version v${MHKIT_MATLAB_VERSION} already exists as a tag!" | |
| echo "Please update the version number in:" | |
| echo "- pyproject.toml" | |
| echo "- mhkit_python_utils/__init__.py" | |
| echo "- scripts/build_release.m" | |
| exit 1 | |
| fi | |
| - name: Set environment variables | |
| run: | | |
| echo "SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)" >> $GITHUB_ENV | |
| - name: Set up MATLAB | |
| uses: matlab-actions/setup-matlab@v2 | |
| with: | |
| release: R2024a | |
| - name: Build Toolbox | |
| uses: matlab-actions/run-command@v2 | |
| with: | |
| command: addpath('scripts'); build_release | |
| - name: Rename files for develop branch | |
| if: github.ref != 'refs/heads/master' | |
| run: | | |
| for f in mhkit_v*.mltbx; do | |
| mv "$f" "${f/.mltbx/-dev-${SHORT_SHA}.mltbx}" | |
| done | |
| for f in mhkit_examples_v*.zip; do | |
| mv "$f" "${f/.zip/-dev-${SHORT_SHA}.zip}" | |
| done | |
| for f in mhkit_python_utils*.zip; do | |
| mv "$f" "${f/.zip/-dev-${SHORT_SHA}.zip}" | |
| done | |
| - name: Upload MATLAB Toolbox | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mhkit-toolbox | |
| path: mhkit_v*.mltbx | |
| if-no-files-found: error | |
| - name: Upload Examples | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mhkit-examples | |
| path: mhkit_examples_v*.zip | |
| if-no-files-found: error | |
| - name: Upload mhkit_python_utils | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mhkit-python-utils | |
| path: mhkit_python_utils_v*.zip | |
| if-no-files-found: error | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v1 | |
| if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' | |
| with: | |
| files: | | |
| mhkit_v*.mltbx | |
| mhkit_examples_v*.zip | |
| mhkit_python_utils_v*.zip | |
| name: ${{ github.ref == 'refs/heads/master' && format('MHKiT-MATLAB v{0} Release', env.MHKIT_MATLAB_VERSION) || format('MHKiT-MATLAB v{0} Development Build ({1})', env.MHKIT_MATLAB_VERSION, env.SHORT_SHA) }} | |
| tag_name: ${{ github.ref == 'refs/heads/master' && format('v{0}', env.MHKIT_MATLAB_VERSION) || format('v{0}-dev-{1}', env.MHKIT_MATLAB_VERSION, env.SHORT_SHA) }} | |
| # Release visibility settings: | |
| # - For master branch: Creates a public production release (draft=false) | |
| # - For other branches: Creates a draft release (draft=true) visible only to repository contributors | |
| # This allows the development team to test new builds before making them public. | |
| draft: ${{ github.ref != 'refs/heads/master' }} | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |