-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-codemagic.sh
executable file
·72 lines (60 loc) · 2.4 KB
/
setup-codemagic.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
. .env
echo "Adding Codemagic application: https://codemagic.io/apps"
CODEMAGIC_RESPONSE=$(curl https://api.codemagic.io/apps \
-H "Content-Type: application/json" \
-H "x-auth-token: $(cat "$CM_API_TOKEN_PATH")" \
-s -d '{
"repositoryUrl": "'"${GIT_REPO_URL}"'",
"sshKey": {
"data": "'"$(base64 -w0 < "$CM_GITHUB_SSH_KEY_PATH")"'",
"passphrase": "'"${CM_GITHUB_SSH_KEY_PASS}"'"
}
}')
CODEMAGIC_APP_ID=$(echo "${CODEMAGIC_RESPONSE}" | jq -r '._id')
echo "Codemagic application ID: ${CODEMAGIC_APP_ID}"
echo "CODEMAGIC_APP_ID=${CODEMAGIC_APP_ID}" >> .env
echo "Adding secrets"
add_codemagic_secret() {
local name="$1"
local value="$2"
if [ -z "$value" ]; then
echo "Error: '$name' environment variable is not set."
exit 1
fi
echo "$name"
curl "https://api.codemagic.io/apps/${CODEMAGIC_APP_ID}/variables" \
-H "Content-type: application/json" \
-H "x-auth-token: $(cat "$CM_API_TOKEN_PATH")" \
-s -o /dev/null \
-d '{
"key": "'"${name}"'",
"value": "'"${value//$'\n'/\\n}"'",
"group": "secrets",
"secure": true
}'
}
# Code signing private key
appKeysDir="${HOME}/.secrets/dev/${APP_NAME_SLUG}"
appKeyFile="${appKeysDir}/certificate_private_key"
if [ ! -f "$appKeyFile" ]; then
mkdir -p "$appKeysDir"
ssh-keygen -t rsa -b 2048 -m PEM -f "$appKeyFile" -q -N ""
fi
add_codemagic_secret "CERTIFICATE_PRIVATE_KEY" "$(cat "$appKeyFile")"
add_codemagic_secret "APP_STORE_CONNECT_ISSUER_ID" "$APP_STORE_CONNECT_ISSUER_ID"
add_codemagic_secret "APP_STORE_CONNECT_KEY_IDENTIFIER" "$APP_STORE_CONNECT_KEY_IDENTIFIER"
add_codemagic_secret "APP_STORE_CONNECT_PRIVATE_KEY" "$(cat "$APP_STORE_CONNECT_PRIVATE_KEY_PATH")"
add_codemagic_secret "SENTRY_ACCESS_TOKEN" "$(cat "$SENTRY_CI_TOKEN_PATH")"
# seems to be only required to 'produce' new app at app store
#add_codemagic_secret "FASTLANE_PASSWORD" "$(cat "$ITUNES_PASSWORD_PATH")"
add_codemagic_secret "DEV_FIRST_NAME", "$DEV_FIRST_NAME"
add_codemagic_secret "DEV_LAST_NAME", "$DEV_LAST_NAME"
add_codemagic_secret "DEV_PHONE", "$DEV_PHONE"
add_codemagic_secret "DEV_EMAIL", "$DEV_EMAIL"
add_codemagic_secret "DEV_ADDRESS_LINE_1", "$DEV_ADDRESS_LINE_1"
add_codemagic_secret "DEV_ADDRESS_LINE_2", "$DEV_ADDRESS_LINE_2"
add_codemagic_secret "DEV_CITY", "$DEV_CITY"
add_codemagic_secret "DEV_STATE", "$DEV_STATE"
add_codemagic_secret "DEV_COUNTRY", "$DEV_COUNTRY"
add_codemagic_secret "DEV_ZIP", "$DEV_ZIP"