Skip to content

on-demand-deployment #91

on-demand-deployment

on-demand-deployment #91

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 mapping tools]")
message(STATUS "Require a MAP Client mapping tools variant.")
file(APPEND $ENV{GITHUB_OUTPUT} "include_mapping_tools=true\n")
endif()
if ("${_PART}" STREQUAL "[odd release with installer]")
message(STATUS "Require a MAP Client 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-2019","variant":"mapclient","tag":"${{ steps.get-tag.outputs.tag }}","release-name":"${{ steps.get-release-name.outputs.name }}","python-version":"3.9"}')
matrixElements+=('{"os":"macos-11","variant":"mapclient","tag":"${{ steps.get-tag.outputs.tag }}","release-name":"${{ steps.get-release-name.outputs.name }}","python-version":"3.9"}')
fi
if [ "${{ steps.req-assets.outputs.include_mapping_tools }}" == "true" ]; then
matrixElements+=('{"os":"windows-2019","variant":"mapping-tools","tag":"${{ steps.get-tag.outputs.tag }}","release-name":"${{ steps.get-release-name.outputs.name }}","python-version":"3.9"}')
matrixElements+=('{"os":"macos-11","variant":"mapping-tools","tag":"${{ steps.get-tag.outputs.tag }}","release-name":"${{ steps.get-release-name.outputs.name }}","python-version":"3.9"}')
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:
repository: hsorby/mapclientreleasescripts
path: scripts
ref: v0.19.0
- 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
# ${{ steps.get_tag.outputs.tag }}
# Manually install PyInstaller rather than use the dev install requires from setup.py.
$pip_exe install pyinstaller
if [ "${{ matrix.variant }}" == "mapclient" ]; then
$python_exe prepare_mapclient_release.py ${{ matrix.tag }}
variant=
elif [ "${{ matrix.variant }}" == "mapping-tools" ]; then
$python_exe prepare_mapclient_release.py ${{ matrix.tag }} -v mapping-tools -p plugin_listing.txt -w workflow_listing.txt
variant="-${{ matrix.variant }}"
else
echo "Variant not supported"
exit 2
fi
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/mapclient/res/macos/MAP-Client${variant}-${{ matrix.release-name }}.dmg
echo $asset
echo "file=$asset" >> $GITHUB_OUTPUT
elif [ "$RUNNER_OS" == "Windows" ]; then
ls -lh mapclient/package
asset=$GITHUB_WORKSPACE/scripts/mapclient/package/MAP-Client${variant}-${{ matrix.release-name }}.exe
# asset=`ls -1 "$GITHUB_WORKSPACE"/mapclient/package/MAP-Client*.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 }}