Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(manager): cleanup and fix Manager build #1497

Merged
merged 6 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions src/server_manager/electron_app/build.action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eux
set -eu

# Electron app root folder
readonly STATIC_DIR="${BUILD_DIR}/server_manager/electron_app/static"
rm -rf "${STATIC_DIR}"
mkdir -p "${STATIC_DIR}"

PLATFORM=$1
STAGING_PERCENTAGE=100
VERSION_NAME='0.0.0-debug'
BUILD_MODE=debug
for i in "$@"; do
Expand All @@ -29,10 +32,6 @@ for i in "$@"; do
VERSION_NAME="${i#*=}"
shift
;;
--stagingPercentage=*)
STAGING_PERCENTAGE="${i#*=}"
shift
;;
--* | -*)
echo "Unknown option: ${i}"
exit 1
Expand All @@ -41,29 +40,28 @@ for i in "$@"; do
esac
done

readonly OUT_DIR="${BUILD_DIR}/server_manager/electron_app"
rm -rf "${OUT_DIR}"

# Electron app root folder
readonly STATIC_DIR="${OUT_DIR}/static"
mkdir -p "${STATIC_DIR}"
if [[ -z "${WEBPACK_MODE:-}" ]]; then
case "${BUILD_MODE}" in
release)
export WEBPACK_MODE="production";;
*)
export WEBPACK_MODE="development";;
esac
fi

# Build the Web App.
run_action server_manager/web_app/build

# Compile the Electron main process and preload to the app root folder.
# Since Node.js on Cygwin doesn't like absolute Unix-style paths,
# we'll use relative paths here.
webpack --config=src/server_manager/electron_main.webpack.mjs ${BUILD_ENV:+--mode=${BUILD_ENV}}
webpack --config=src/server_manager/electron_preload.webpack.mjs ${BUILD_ENV:+--mode=${BUILD_ENV}}
webpack --config=src/server_manager/electron_main.webpack.mjs ${WEBPACK_MODE:+--mode=${WEBPACK_MODE}}
webpack --config=src/server_manager/electron_preload.webpack.mjs ${WEBPACK_MODE:+--mode=${WEBPACK_MODE}}

# Assemble everything together.
mkdir -p "${STATIC_DIR}/server_manager"
cp -r "${BUILD_DIR}/server_manager/web_app/static" "${STATIC_DIR}/server_manager/web_app/"

# TODO(fortuna): Separate the build of Electron main and the Electron package.
# Building the package significantly delays the start action.

# Electron requires a package.json file for the app's name, etc.
# We also need to install NPMs at this location for require()
# in order for require() to work right in the renderer process, which
Expand All @@ -76,9 +74,3 @@ npm ci --prod --ignore-scripts
# Icons.
cd "${ROOT_DIR}"
electron-icon-maker --input=src/server_manager/images/launcher-icon.png --output=build/server_manager/electron_app/static

# TODO(daniellacosse): refactor these scripts into node so we can call the electron builder there directly
# shellcheck disable=SC2046
electron-builder $(node src/server_manager/scripts/get_electron_build_flags.mjs "${PLATFORM}" --buildMode "${BUILD_MODE}")

src/server_manager/scripts/finish_info_files.sh "${PLATFORM}" "${STAGING_PERCENTAGE}"
103 changes: 103 additions & 0 deletions src/server_manager/electron_app/package.action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash -eu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be willing to write this as a node file? Just so we're moving towards cross-platform development instead of away from it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at this point. The effort is not justified. We already have Linux+macOS cross-platform development, we don't develop the Manager on Windows.
I just want to move forward and go back to the SDK. I did remove over 112 net lines in this PR though, so I claim the state is better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mm, alright. Thanks for doing this!

#
# Copyright 2024 The Outline Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eu

SCRIPT_DIR="$(dirname "$0")"
PROJECT_DIR="${BUILD_DIR}/server_manager/electron_app/static"
BUILD_MODE=debug
PLATFORM=

function package_electron() {
declare -a electron_builder_cmd=(
electron-builder
--projectDir="${PROJECT_DIR}"
--config="${SCRIPT_DIR}/electron_builder.json"
--publish=never
)

case "${PLATFORM}" in
linux)
electron_builder_cmd+=(--linux);;
windows)
electron_builder_cmd+=(--win --ia32);;
macos)
electron_builder_cmd+=(--mac);;
*)
echo "Unsupported platform ${PLATFORM}" >&2 && exit 1
esac

if [[ "${BUILD_MODE}" == "release" ]]; then
electron_builder_cmd+=(
--config.generateUpdatesFilesForAllChannels=true
--config.publish.provider=generic
--config.publish.url=https://s3.amazonaws.com/outline-releases/manager/
)
fi

"${electron_builder_cmd[@]}"
}

function finish_yaml_files() {
declare -r staging_percentage="${1?Staging percentage missing}"

local release_channel
release_channel=$(node_modules/node-jq/bin/jq -r '.version' src/server_manager/package.json | cut -s -d'-' -f2)
# If this isn't an alpha or beta build, `cut -s` will return an empty string
if [[ -z "${release_channel}" ]]; then
release_channel=latest
fi
echo "stagingPercentage: ${staging_percentage}" >> "${PROJECT_DIR}/dist/${release_channel}${PLATFORM}.yml"

# If we cut a staged mainline release, beta testers will take the update as well.
if [[ "${release_channel}" == "latest" ]]; then
echo "stagingPercentage: ${staging_percentage}" >> "${PROJECT_DIR}/dist/beta${PLATFORM}.yml"
fi

# We don't support alpha releases
rm -f "${PROJECT_DIR}/dist/alpha${PLATFORM}.yml"
}

function main() {
declare staging_percentage=100
declare version_name='0.0.0-debug'
for i in "$@"; do
case "${i}" in
--buildMode=*)
BUILD_MODE="${i#*=}"
shift
;;
--versionName=*)
version_name="${i#*=}"
shift
;;
--stagingPercentage=*)
staging_percentage="${i#*=}"
shift
;;
--* | -*)
echo "Unknown option: ${i}"
exit 1
;;
*) ;;
esac
done
PLATFORM="${1?Platform missing}"
run_action server_manager/electron_app/build --buildMode="${BUILD_MODE}" --versionName="${version_name}"
package_electron
finish_yaml_files "${staging_percentage}"
}

main "$@"
2 changes: 1 addition & 1 deletion src/server_manager/electron_app/start.action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

run_action server_manager/electron_app/build "$1"
run_action server_manager/electron_app/build "$@"

cd "${BUILD_DIR}/server_manager/electron_app/static"

Expand Down
57 changes: 0 additions & 57 deletions src/server_manager/scripts/fill_packaging_opts.sh

This file was deleted.

33 changes: 0 additions & 33 deletions src/server_manager/scripts/finish_info_files.sh

This file was deleted.

59 changes: 0 additions & 59 deletions src/server_manager/scripts/get_electron_build_flags.mjs

This file was deleted.

22 changes: 0 additions & 22 deletions src/server_manager/scripts/get_manager_release_channel.sh

This file was deleted.

Loading
Loading