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

Autobuild: Combine and simplify Mac build scripts #2514

Merged
merged 1 commit into from
Mar 16, 2022
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
87 changes: 87 additions & 0 deletions .github/autobuild/mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
set -eu

QT_DIR=/usr/local/opt/qt
AQTINSTALL_VERSION=2.0.6

if [[ ! ${QT_VERSION:-} =~ [0-9]+\.[0-9]+\..* ]]; then
echo "Environment variable QT_VERSION must be set to a valid Qt version"
exit 1
fi
if [[ ! ${jamulus_buildversionstring:-} =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "Environment variable jamulus_buildversionstring has to be set to a valid version string"
exit 1
fi

setup() {
if [[ -d "${QT_DIR}" ]]; then
echo "Using Qt installation from previous run (actions/cache)"
else
echo "Install dependencies..."
python3 -m pip install "aqtinstall==${AQTINSTALL_VERSION}"
python3 -m aqt install-qt --outputdir "${QT_DIR}" mac desktop "${QT_VERSION}" --archives qtbase qttools qttranslations qtmacextras
fi

# Add the qt binaries to the PATH.
# The clang_64 entry can be dropped when Qt <6.2 compatibility is no longer needed.
export PATH="${QT_DIR}/${QT_VERSION}/macos/bin:${QT_DIR}/${QT_VERSION}/clang_64/bin:${PATH}"
echo "::set-env name=PATH::${PATH}"
}

prepare_signing() {
[[ "${SIGN_IF_POSSIBLE:-0}" == "1" ]] || return 1

# Signing was requested, now check all prerequisites:
[[ -n "${MACOS_CERTIFICATE:-}" ]] || return 1
[[ -n "${MACOS_CERTIFICATE_ID:-}" ]] || return 1
[[ -n "${MACOS_CERTIFICATE_PWD:-}" ]] || return 1
[[ -n "${NOTARIZATION_PASSWORD:-}" ]] || return 1
[[ -n "${KEYCHAIN_PASSWORD:-}" ]] || return 1

echo "Signing was requested and all dependencies are satisfied"

# Put the cert to a file
echo "${MACOS_CERTIFICATE}" | base64 --decode > certificate.p12

# Set up a keychain for the build:
security create-keychain -p "${KEYCHAIN_PASSWORD}" build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "${KEYCHAIN_PASSWORD}" build.keychain
security import certificate.p12 -k build.keychain -P "${MACOS_CERTIFICATE_PWD}" -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "${KEYCHAIN_PASSWORD}" build.keychain

# Tell Github Workflow that we need notarization & stapling:
echo "::set-output name=macos_signed::true"
return 0
}

build_app_as_dmg_installer() {
# Mac's bash version considers BUILD_ARGS unset without at least one entry:
BUILD_ARGS=("")
if prepare_signing; then
BUILD_ARGS=("-s" "${MACOS_CERTIFICATE_ID}")
fi
./mac/deploy_mac.sh "${BUILD_ARGS[@]}"
}

pass_artifact_to_job() {
artifact_deploy_filename="jamulus_${jamulus_buildversionstring}_mac${ARTIFACT_SUFFIX:-}.dmg"
echo "Moving build artifact to deploy/${artifact_deploy_filename}"
mv ./deploy/Jamulus-*installer-mac.dmg "./deploy/${artifact_deploy_filename}"
echo "::set-output name=artifact_1::${artifact_deploy_filename}"
}

case "${1:-}" in
setup)
setup
;;
build)
build_app_as_dmg_installer
;;
get-artifacts)
pass_artifact_to_job
;;
*)
echo "Unknown stage '${1:-}'"
exit 1
esac
12 changes: 6 additions & 6 deletions .github/workflows/autobuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,18 @@ jobs:
target_os: macos
# Stay on 10.15 as long as we use dmgbuild which does not work with 11's hdiutil (?):
building_on_os: macos-10.15
cmd1_prebuild: "./autobuild/mac/autobuild_mac_1_prepare.sh 5.15.2"
cmd2_build: "./autobuild/mac/autobuild_mac_2_build.sh sign_if_possible"
cmd3_postbuild: "./autobuild/mac/autobuild_mac_3_copy_files.sh"
cmd1_prebuild: "QT_VERSION=5.15.2 SIGN_IF_POSSIBLE=1 ./.github/autobuild/mac.sh setup"
cmd2_build: "QT_VERSION=5.15.2 SIGN_IF_POSSIBLE=1 ./.github/autobuild/mac.sh build"
cmd3_postbuild: "QT_VERSION=5.15.2 SIGN_IF_POSSIBLE=1 ./.github/autobuild/mac.sh get-artifacts"
run_codeql: true
xcode_version: 12.1.1

- config_name: MacOS Legacy (artifacts)
target_os: macos
building_on_os: macos-10.15
cmd1_prebuild: "./autobuild/mac/autobuild_mac_1_prepare.sh 5.9.9"
cmd2_build: "./autobuild/mac/autobuild_mac_2_build.sh do_not_sign"
cmd3_postbuild: "./autobuild/mac/autobuild_mac_3_copy_files.sh legacy"
cmd1_prebuild: "QT_VERSION=5.9.9 SIGN_IF_POSSIBLE=0 ARTIFACT_SUFFIX=_legacy ./.github/autobuild/mac.sh setup"
cmd2_build: "QT_VERSION=5.9.9 SIGN_IF_POSSIBLE=0 ARTIFACT_SUFFIX=_legacy ./.github/autobuild/mac.sh build"
cmd3_postbuild: "QT_VERSION=5.9.9 SIGN_IF_POSSIBLE=0 ARTIFACT_SUFFIX=_legacy ./.github/autobuild/mac.sh get-artifacts"
Comment on lines +118 to +120
Copy link
Member Author

@hoffie hoffie Mar 16, 2022

Choose a reason for hiding this comment

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

I chose to go with inline environment variables here.

For context:

  • Windows uses PowerShell's argument parsing
  • Linux doesn't require any parameters (yet)

So, the possibilities for Mac would be:

  1. Implement a argument parsing loop via getopts to (closely) match PowerShell (longer)
  2. Set environment variables via workflow (downside: needs duplication in multiple places and needs consistent updates regarding cache key)
  3. Use positional arguments like we used to (downside: with the combination of all steps, we would already be using 3+1 arguments; it's getting harder to keep track of the proper order)

Among those, the most-readable and yet simplest implementation is the usage of inline environment variables.

I also thought about converting Windows/PowerShell to environment variables, but it seems that setting this inline is not as nice as on *nix.

run_codeql: false
# For Qt5 on Mac, we need to ensure SDK 10.15 is used, and not SDK 11.x.
# Xcode 12.1 is the most-recent release which still ships SDK 10.15:
Expand Down
35 changes: 0 additions & 35 deletions autobuild/mac/autobuild_mac_1_prepare.sh

This file was deleted.

50 changes: 0 additions & 50 deletions autobuild/mac/autobuild_mac_2_build.sh

This file was deleted.

48 changes: 0 additions & 48 deletions autobuild/mac/autobuild_mac_3_copy_files.sh

This file was deleted.