Skip to content

Commit b490098

Browse files
committed
Upload to emergetools
1 parent 8b89eb6 commit b490098

1 file changed

Lines changed: 74 additions & 0 deletions

File tree

ci_scripts/ci_post_xcodebuild.sh

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
required_env_vars=(
6+
"CI_ARCHIVE_PATH"
7+
"CI_BRANCH"
8+
"CI_COMMIT"
9+
"EMERGE_API_KEY"
10+
)
11+
12+
for var in "${required_env_vars[@]}"; do
13+
if [[ -z "${!var}" ]]; then
14+
echo "Environment variable $var is not set"
15+
exit 1
16+
fi
17+
done
18+
19+
brew install jq
20+
21+
zip_path="$CI_ARCHIVE_PATH.zip"
22+
pushd $(dirname $CI_ARCHIVE_PATH)
23+
zip -r --symlinks "$(basename $zip_path)" "$(basename $CI_ARCHIVE_PATH)"
24+
popd
25+
26+
# Update this with your repo
27+
repo_name='IceCubesApp'
28+
29+
tag='release'
30+
if [[ "$CI_XCODE_SCHEME" == "My Debug Archive Scheme" ]]; then
31+
tag='debug'
32+
fi
33+
34+
json_fields=$(cat <<EOF
35+
"filename":"${zip_path}",
36+
"branch":"${CI_BRANCH}",
37+
"sha":"${CI_COMMIT}",
38+
"repoName":"${repo_name}",
39+
"tag":"${tag}"
40+
EOF
41+
)
42+
43+
if [[ -n "${CI_PULL_REQUEST_NUMBER}" ]]; then
44+
pr_required_env_vars=(
45+
"CI_PULL_REQUEST_NUMBER"
46+
"CI_PULL_REQUEST_TARGET_COMMIT"
47+
)
48+
49+
for var in "${pr_required_env_vars[@]}"; do
50+
if [[ -z "${!var}" ]]; then
51+
echo "Environment variable $var is not set"
52+
exit 1
53+
fi
54+
done
55+
56+
json_fields=$(cat <<EOF
57+
${json_fields},
58+
"prNumber":"${CI_PULL_REQUEST_NUMBER}",
59+
"baseSha":"${CI_PULL_REQUEST_TARGET_COMMIT}"
60+
EOF
61+
)
62+
fi
63+
64+
upload_response=$(curl \
65+
--url "https://api.emergetools.com/upload" \
66+
--header 'Accept: application/json' \
67+
--header 'Content-Type: application/json' \
68+
--header "X-API-Token: $EMERGE_API_KEY" \
69+
--data "{$json_fields}")
70+
71+
# Pull the uploadURL field from the response using jq
72+
upload_url=$(echo "$upload_response" | jq -r .uploadURL)
73+
74+
curl -v -H 'Content-Type: application/zip' -T "$zip_path" "$upload_url"

0 commit comments

Comments
 (0)