on-demand-deployment #22
Workflow file for this run
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: on-demand-deployment | |
| on: | |
| release: | |
| types: [edited] | |
| jobs: | |
| setup: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| run-installer: ${{ steps.set-matrix.outputs.run-installer }} | |
| steps: | |
| - name: Get the tag | |
| id: get-tag | |
| shell: bash | |
| run: | | |
| echo "Setting tag as: ${GITHUB_REF#refs/tags/}" | |
| echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Get the release name | |
| id: get-release-name | |
| shell: bash | |
| run: | | |
| tag=${GITHUB_REF#refs/tags/} | |
| bare_tag=${tag/v/} | |
| IFS='.' read -ra bare_tag_parts <<< "$bare_tag" | |
| name="${bare_tag_parts[0]}.${bare_tag_parts[1]}.${bare_tag_parts[2]}" | |
| echo "Setting name as: ${name}" | |
| echo "name=$name" >> $GITHUB_OUTPUT | |
| - name: Determine required assets | |
| id: req-assets | |
| shell: cmake -P {0} | |
| run: | | |
| set(RELEASE_BODY "${{ github.event.release.body }}") | |
| string(REPLACE "\n" ";" _PARTS "${RELEASE_BODY}") | |
| foreach(_PART ${_PARTS}) | |
| string(STRIP "${_PART}" _PART) | |
| if ("${_PART}" STREQUAL "[odd release with installer]") | |
| message(STATUS "Require a C3D-Parser installer.") | |
| file(APPEND $ENV{GITHUB_OUTPUT} "include_installer=true\n") | |
| endif() | |
| endforeach() | |
| - name: set_matrix | |
| id: set-matrix | |
| run: | | |
| function join_by { local IFS="$1"; shift; echo "$*"; } | |
| matrixElements=() | |
| if [ "${{ steps.req-assets.outputs.include_installer }}" == "true" ]; then | |
| matrixElements+=('{"os":"windows-2022","tag":"${{ steps.get-tag.outputs.tag }}","release-name":"${{ steps.get-release-name.outputs.name }}","python-version":"3.11"}') | |
| fi | |
| if [ "${#matrixElements[@]}" -eq "0" ]; then | |
| echo run-installer=false >> $GITHUB_OUTPUT | |
| else | |
| echo run-installer=true >> $GITHUB_OUTPUT | |
| fi | |
| content=`join_by , ${matrixElements[@]}` | |
| echo "{\"include\":[$content]}" | |
| echo "matrix={\"include\":[$content]}" >> $GITHUB_OUTPUT | |
| installer: | |
| needs: setup | |
| name: installer | |
| if: needs.setup.outputs.run-installer == 'true' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: ${{fromJson(needs.setup.outputs.matrix)}} | |
| steps: | |
| - name: Install create-dmg | |
| if: runner.os == 'macOS' | |
| shell: bash | |
| run: brew install create-dmg | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Setup scripts | |
| uses: actions/checkout@v3 | |
| with: | |
| path: scripts | |
| - name: Create installer asset | |
| id: create-installer | |
| shell: bash | |
| run: | | |
| echo "Creating installer asset" | |
| python -m venv venv | |
| if [ "$RUNNER_OS" == "macOS" ]; then | |
| python_exe=$GITHUB_WORKSPACE/venv/bin/python | |
| pip_exe=$GITHUB_WORKSPACE/venv/bin/pip | |
| # source venv/bin/activate | |
| elif [ "$RUNNER_OS" == "Windows" ]; then | |
| python_exe=$GITHUB_WORKSPACE/venv/Scripts/python.exe | |
| pip_exe=$GITHUB_WORKSPACE/venv/Scripts/pip.exe | |
| # source venv/Scripts/activate | |
| else | |
| echo "$RUNNER_OS not supported" | |
| exit 1 | |
| fi | |
| cd $GITHUB_WORKSPACE | |
| cd scripts | |
| # Manually install PyInstaller rather than use the dev install requires from setup.py. | |
| $pip_exe install pyinstaller | |
| $python_exe res/prepare_release.py ${{ matrix.tag }} | |
| if [ "$RUNNER_OS" == "macOS" ]; then | |
| #echo "Have to find out how to modify a finder window in headless mode with AppleScript." | |
| #echo "Asset not ready for $RUNNER_OS" | |
| asset=$GITHUB_WORKSPACE/scripts/res/macos/C3D-Parser-${{ matrix.release-name }}.dmg | |
| echo $asset | |
| echo "file=$asset" >> $GITHUB_OUTPUT | |
| elif [ "$RUNNER_OS" == "Windows" ]; then | |
| ls -lh package | |
| asset=$GITHUB_WORKSPACE/scripts/package/C3D-Parser-${{ matrix.release-name }}.exe | |
| asset=${asset//\\//} | |
| echo $asset | |
| echo "file=$asset" >> $GITHUB_OUTPUT | |
| else | |
| echo "$RUNNER_OS not supported" | |
| exit 1 | |
| fi | |
| # echo $asset | |
| echo "Upload it ..." | |
| - name: Define asset | |
| id: define-asset | |
| if: false | |
| shell: cmake -P {0} | |
| run: | | |
| set(ASSET_PATH "${{ steps.create-installer.outputs.file }}") | |
| file(TO_NATIVE_PATH "${ASSET_PATH}" _NATIVE_PATH) | |
| message(STATUS "file: ${_NATIVE_PATH}") | |
| file(APPEND $ENV{GITHUB_OUTPUT} "file=${_NATIVE_PATH}") | |
| - name: Upload asset | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| files: ${{ steps.create-installer.outputs.file }} | |
| tag_name: ${{ matrix.tag }} |