From ad381733f6fb506087699677719d7075b3a7f385 Mon Sep 17 00:00:00 2001 From: Christian Fersch Date: Wed, 7 Sep 2022 13:47:13 +0200 Subject: [PATCH] Add github workflow for windows installer creation --- .github/workflows/build_installer.yml | 63 ++++++++++++++++++++++++ other_resources/installer/build.sh | 53 ++++++++++++++++++++ other_resources/installer/build_win.sh | 6 +++ other_resources/installer/construct.yaml | 22 +++++++++ 4 files changed, 144 insertions(+) create mode 100644 .github/workflows/build_installer.yml create mode 100644 other_resources/installer/build.sh create mode 100644 other_resources/installer/build_win.sh create mode 100644 other_resources/installer/construct.yaml diff --git a/.github/workflows/build_installer.yml b/.github/workflows/build_installer.yml new file mode 100644 index 000000000..ca8b0fd52 --- /dev/null +++ b/.github/workflows/build_installer.yml @@ -0,0 +1,63 @@ +name: Build installer +on: + workflow_dispatch: + inputs: + version: + description: 'Build installer for version (e.g. "1.0.4")' + required: true + type: string + release: + description: 'Upload as release artifact' + required: true + type: boolean + +jobs: + build: + name: ActivitySim-${{ matrix.OS_NAME }}-${{ matrix.ARCH }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + ARCH: x86_64 + TARGET_PLATFORM: win-64 + OS_NAME: "Windows" + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - uses: conda-incubator/setup-miniconda@35d1405e78aa3f784fe3ce9a2eb378d5eeb62169 + with: + miniconda-version: "latest" + if: contains(matrix.OS_NAME, 'Windows') + + - name: Build installer + env: + ARCH: ${{ matrix.ARCH }} + OS_NAME: ${{ matrix.OS_NAME }} + TARGET_PLATFORM: ${{ matrix.TARGET_PLATFORM }} + run: | + export ACTIVITYSIM_VERSION=${{ inputs.version }} + export EXT=exe + source /c/Miniconda3/Scripts/activate; + source other_resources/installer/build_win.sh; + ls -alh build + shell: bash + + - name: Upload installer to Github artifact + uses: actions/upload-artifact@v3 + with: + path: build/Activitysim-${{ inputs.version }}-${{ matrix.OS_NAME }}-${{ matrix.ARCH }}* + name: Activitysim-${{ inputs.version }}-${{ matrix.OS_NAME }}-${{ matrix.ARCH }} + + - name: Upload installer to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build/Activitysim* + tag: v${{ inputs.version }} + overwrite: true + file_glob: true + if: inputs.release diff --git a/other_resources/installer/build.sh b/other_resources/installer/build.sh new file mode 100644 index 000000000..e30ce1a99 --- /dev/null +++ b/other_resources/installer/build.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +set -xe + +env | sort + +echo "***** Start: Building Activitysim installer *****" +CONSTRUCT_ROOT="${CONSTRUCT_ROOT:-${PWD}}" + +cd "${CONSTRUCT_ROOT}" + +# Constructor should be latest for non-native building +# See https://github.com/conda/constructor +echo "***** Install constructor *****" +conda install -y "constructor>=3.3.1" jinja2 curl libarchive -c conda-forge --override-channels + +if [[ "$(uname)" == "Darwin" ]]; then + conda install -y coreutils -c conda-forge --override-channels +fi +# shellcheck disable=SC2154 +if [[ "${TARGET_PLATFORM}" == win-* ]]; then + conda install -y "nsis=3.01" -c conda-forge --override-channels +fi +# pip install git+git://github.com/conda/constructor@3.3.1#egg=constructor --force --no-deps +conda list + +echo "***** Make temp directory *****" +TEMP_DIR=$(mktemp -d --tmpdir=C:/Users/RUNNER~1/AppData/Local/Temp/); + +echo "***** Copy file for installer construction *****" +cp -R other_resources/installer "${TEMP_DIR}/" +cp LICENSE.txt "${TEMP_DIR}/installer/" + +ls -al "${TEMP_DIR}" + +echo "***** Construct the installer *****" +# Transmutation requires the current directory is writable +cd "${TEMP_DIR}" +# shellcheck disable=SC2086 +constructor "${TEMP_DIR}/installer/" --output-dir "${TEMP_DIR}" +cd - + +cd "${TEMP_DIR}" + +# This line will break if there is more than one installer in the folder. +INSTALLER_PATH=$(find . -name "Activitysim*.${EXT}" | head -n 1) + +echo "***** Move installer to build folder *****" +mkdir -p "${CONSTRUCT_ROOT}/build" +mv "${INSTALLER_PATH}" "${CONSTRUCT_ROOT}/build/" + +echo "***** Done: Building ActivitySim installer *****" +cd "${CONSTRUCT_ROOT}" diff --git a/other_resources/installer/build_win.sh b/other_resources/installer/build_win.sh new file mode 100644 index 000000000..433462c02 --- /dev/null +++ b/other_resources/installer/build_win.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -ex + +conda install posix --yes +source other_resources/installer/build.sh diff --git a/other_resources/installer/construct.yaml b/other_resources/installer/construct.yaml new file mode 100644 index 000000000..dd8f72e84 --- /dev/null +++ b/other_resources/installer/construct.yaml @@ -0,0 +1,22 @@ +{% set version = os.environ.get("ACTIVITYSIM_VERSION", "0.42.0-0") %} + +name: Activitysim +version: {{ version }} + +initialize_by_default: false +register_python_default: false + +license_file: LICENSE.txt + +menu_packages: [] + +installer_type: exe + +channels: + - conda-forge + +specs: + - python 3.9.* + - conda + - activitysim {{ version }} + - pip