Skip to content

Commit 1c6bb3e

Browse files
committed
Add script files to build dmg
1 parent 7d664c2 commit 1c6bb3e

File tree

4 files changed

+226
-0
lines changed

4 files changed

+226
-0
lines changed

JoyfulPlayer.xcodeproj/project.pbxproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
40AE346B22F82D91D4795AE1 /* [CP] Embed Pods Frameworks */,
150150
DD3F137F249F1E97001C26BA /* Embed Frameworks */,
151151
DD3F1381249F1EAF001C26BA /* Copy Carthage Frameworks */,
152+
DDA43C4624D5F098009F480F /* Set build number */,
152153
);
153154
buildRules = (
154155
);
@@ -264,6 +265,24 @@
264265
shellPath = /bin/sh;
265266
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n/usr/local/bin/carthage copy-frameworks\n";
266267
};
268+
DDA43C4624D5F098009F480F /* Set build number */ = {
269+
isa = PBXShellScriptBuildPhase;
270+
buildActionMask = 2147483647;
271+
files = (
272+
);
273+
inputFileListPaths = (
274+
);
275+
inputPaths = (
276+
);
277+
name = "Set build number";
278+
outputFileListPaths = (
279+
);
280+
outputPaths = (
281+
);
282+
runOnlyForDeploymentPostprocessing = 0;
283+
shellPath = /bin/sh;
284+
shellScript = "${SRCROOT}/scripts/set_build_number.sh\n";
285+
};
267286
/* End PBXShellScriptBuildPhase section */
268287

269288
/* Begin PBXSourcesBuildPhase section */
@@ -416,6 +435,7 @@
416435
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
417436
CODE_SIGN_ENTITLEMENTS = JoyfulPlayer/JoyfulPlayer.entitlements;
418437
CODE_SIGN_IDENTITY = "Apple Development";
438+
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
419439
CODE_SIGN_STYLE = Automatic;
420440
COMBINE_HIDPI_IMAGES = YES;
421441
DEVELOPMENT_ASSET_PATHS = "\"JoyfulPlayer/Preview Content\"";
@@ -446,6 +466,7 @@
446466
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
447467
CODE_SIGN_ENTITLEMENTS = JoyfulPlayer/JoyfulPlayer.entitlements;
448468
CODE_SIGN_IDENTITY = "Apple Development";
469+
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
449470
CODE_SIGN_STYLE = Automatic;
450471
COMBINE_HIDPI_IMAGES = YES;
451472
DEVELOPMENT_ASSET_PATHS = "\"JoyfulPlayer/Preview Content\"";

scripts/build_dmg.sh

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#!/bin/bash
2+
3+
# Codesign and build a dmg file
4+
5+
if [ $# -lt 1 ]; then
6+
echo "usage: $0 <app_path>"
7+
exit 1
8+
fi
9+
10+
SRC_APP_PATH="${1}"
11+
APP_NAME=`basename "${SRC_APP_PATH}"`
12+
if [ "${APP_NAME}" != "JoyfulPlayer.app" ]; then
13+
echo "error: App name must be 'JoyfulPlayer.app'"
14+
exit 2
15+
fi
16+
17+
VERSION=`git describe --tags --abbrev=0 --match "v*.*.*"`
18+
if [ "${VERSION}" == "" ]; then
19+
echo "error: version tag not found"
20+
exit 3
21+
fi
22+
23+
echo "Source app path: ${SRC_APP_PATH}"
24+
25+
PROJECT_ROOT="`dirname $0`/.."
26+
TMP_DIR="${PROJECT_ROOT}/dmg"
27+
APP_PATH="${TMP_DIR}/JoyfulPlayer.app"
28+
APP_ENTITLEMENTS="${PROJECT_ROOT}/JoyfulPlayer/JoyfulPlayer.entitlements"
29+
DMG_PATH="${TMP_DIR}/JoyfulPlayer-${VERSION}.dmg"
30+
BUNDLE_ID="jp.0spec.JoyfulPlayer"
31+
32+
if [ "${APP_API_USER}" == "" ]; then
33+
read -p "App Connect User: " APP_API_USER
34+
fi
35+
36+
if [ "${APP_API_ISSUER}" == "" ]; then
37+
read -p "App Connect Issuer: " APP_API_ISSUER
38+
fi
39+
40+
if [ "${APP_API_KEY_ID}" == "" ]; then
41+
read -p "App Connect Key ID: " APP_API_KEY_ID
42+
fi
43+
44+
# Copy App
45+
echo "Copying app..."
46+
rm -rf "${TMP_DIR}"
47+
mkdir "${TMP_DIR}"
48+
cp -Rp "${SRC_APP_PATH}" "${APP_PATH}"
49+
50+
# Verify
51+
echo "Verifying..."
52+
codesign -dv --verbose=4 "${APP_PATH}"
53+
if [ $? -ne 0 ]; then
54+
echo "error: The app is not correctly signed"
55+
exit 4
56+
fi
57+
58+
# Create a dmg file
59+
echo "Creating a dmg file at ${DMG_PATH}"
60+
dmgbuild -s "${PROJECT_ROOT}/scripts/dmg_settings.py" JoyfulPlayer "${DMG_PATH}"
61+
if [ $? -ne 0 ]; then
62+
echo "error: Failed to build a dmg file"
63+
exit 5
64+
fi
65+
66+
echo "Code signing to the dmg file..."
67+
codesign -f -o runtime --timestamp -s "Developer ID Application" "${DMG_PATH}"
68+
if [ $? -ne 0 ]; then
69+
echo "error: Failed to sign to the dmg file"
70+
exit 6
71+
fi
72+
73+
# Notarize the dmg file
74+
echo "Notarizing the dmg file..."
75+
RESULT=`xcrun altool --notarize-app \
76+
--primary-bundle-id "${BUNDLE_ID}" \
77+
-u "${APP_API_USER}" \
78+
--apiKey "${APP_API_KEY_ID}" \
79+
--apiIssuer "${APP_API_ISSUER}" \
80+
-t osx -f "${DMG_PATH}"`
81+
82+
echo "${RESULT}"
83+
REQUEST_UUID=`echo "${RESULT}" | grep "RequestUUID = " | sed "s/RequestUUID = \(.*\)$/\1/"`
84+
if [ "${REQUEST_UUID}" == "" ]; then
85+
echo "error: Failed to notarize the dmg file"
86+
exit 7
87+
fi
88+
89+
echo "Waiting for the approval..."
90+
echo "It would take few minutes"
91+
RETRY=20
92+
APPROVED=false
93+
for i in `seq ${RETRY}`; do
94+
sleep 30
95+
RESULT=`xcrun altool --notarization-history 0 \
96+
-u "${APP_API_USER}" \
97+
--apiKey "${APP_API_KEY_ID}" \
98+
--apiIssuer "${APP_API_ISSUER}"`
99+
STATUS=`echo "${RESULT}" | grep "${REQUEST_UUID}" | cut -f 5- -d " "`
100+
101+
if `echo "${STATUS}" | grep "Package Approved" > /dev/null`; then
102+
APPROVED=true
103+
break
104+
elif [ "${STATUS}" == "" ]; then
105+
echo "waiting for updating the notarization history..."
106+
elif `echo "${STATUS}" | grep "in progress" > /dev/null`; then
107+
echo "in progress..."
108+
else
109+
echo "${RESULT}"
110+
echo "error: Invalid notarization status: ${STATUS}"
111+
exit 8
112+
fi
113+
done
114+
115+
echo "${RESULT}"
116+
if [ ${APPROVED} = false ] ; then
117+
echo "error: Approval timeout"
118+
exit 9
119+
fi
120+
121+
# Staple a ticket to the dmg file
122+
xcrun stapler staple "${DMG_PATH}"
123+
if [ $? -ne 0 ]; then
124+
echo "error: Failed to staple a ticket"
125+
exit 10
126+
fi
127+
128+
echo "Done."

scripts/dmg_settings.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from __future__ import unicode_literals
2+
3+
import biplist
4+
import os.path
5+
6+
app = defines.get('app', './dmg/JoyfulPlayer.app')
7+
appname = os.path.basename(app)
8+
9+
# Basics
10+
11+
format = defines.get('format', 'UDZO')
12+
size = defines.get('size', None)
13+
files = [ app ]
14+
15+
icon_locations = {
16+
appname: (160, 160),
17+
}
18+
19+
# Window configuration
20+
21+
show_status_bar = False
22+
show_tab_view = False
23+
show_toolbar = False
24+
show_pathbar = False
25+
show_sidebar = False
26+
sidebar_width = 180
27+
28+
window_rect = ((322, 331), (320, 362))
29+
30+
defaullt_view = 'icon_view'
31+
32+
# Icon view configuration
33+
34+
arrange_by = None
35+
grid_offset = (0, 0)
36+
grid_spacing = 100
37+
scrolll_position = (0, 0)
38+
label_pos = 'bottom'
39+
text_size = 12
40+
icon_size = 164
41+

scripts/set_build_number.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Set the number of git commits to Xcode build number
4+
# The source code is based on https://leenarts.net/2020/02/11/git-based-build-number-in-xcode/
5+
6+
GIT=`sh /etc/profile; which git`
7+
8+
LATEST_TAG=`git describe --tags --abbrev=0 --match "v*.*.*"`
9+
if [ "${LATEST_TAG}" == "" ]; then
10+
echo "error: Version tag not found"
11+
exit 1
12+
fi
13+
14+
VERSION=`echo "${LATEST_TAG}" | cut -c 2-`
15+
16+
NUM_COMMITS=`"${GIT}" rev-list HEAD --count`
17+
18+
TARGET_PLIST="${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
19+
DSYM_PLIST="${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist"
20+
21+
for PLIST in "${TARGET_PLIST}" "${DSYM_PLIST}"; do
22+
if [ -f "${PLIST}" ]; then
23+
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${VERSION}" "${PLIST}"
24+
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ${NUM_COMMITS}" "${PLIST}"
25+
fi
26+
done
27+
28+
ROOT_PLIST="${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Settings.bundle/Root.plist"
29+
30+
if [ -f "${ROOT_PLIST}" ]; then
31+
SETTINGS_VERSION="${APP_MARKETING_VERSION} (${NUM_COMMITS})"
32+
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue ${SETTINGS_VERSION}" "${ROOT_PLIST}"
33+
else
34+
echo "Could not find: ${ROOT_PLIST}"
35+
exit 0
36+
fi

0 commit comments

Comments
 (0)