CircleCI: add Mapping.txt-Upload to appCenter and generated VersionNumbers

This commit is contained in:
Felix 2019-05-05 10:55:20 +02:00
parent f32013a26b
commit 46fca3fb9d
6 changed files with 99 additions and 41 deletions

View file

@ -5,6 +5,9 @@ token=$2
build_path=$3
release_notes_file=$4
destination_name=$5
mapping_path=$6
versionCode=$7
versionName=$8
if [ "$CIRCLE_BRANCH" = "master" ] ; then
app_name=chaosflix
@ -14,32 +17,65 @@ else
exit 0
fi
# Step 1: Create an upload resource and get an upload_url (good for 24 hours)
request_url="https://api.appcenter.ms/v0.1/apps/${owner_name}/${app_name}/release_uploads"
upload_json=$(curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "X-API-Token: ${token}" "${request_url}")
upload_id=$(echo ${upload_json} | \
python3 -c "import sys, json; print(json.load(sys.stdin)['upload_id'])")
upload_url=$(echo ${upload_json} | \
python3 -c "import sys, json; print(json.load(sys.stdin)['upload_url'])")
## Step 1: Create an upload resource and get an upload_url (good for 24 hours)
#request_url="https://api.appcenter.ms/v0.1/apps/${owner_name}/${app_name}/release_uploads"
#upload_json=$(curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" --header "X-API-Token: ${token}" "${request_url}")
#upload_id=$(echo ${upload_json} | \
# python3 -c "import sys, json; print(json.load(sys.stdin)['upload_id'])")
#upload_url=$(echo ${upload_json} | \
# python3 -c "import sys, json; print(json.load(sys.stdin)['upload_url'])")
#
## Step 2: Upload ipa
#curl -F "ipa=@${build_path}" ${upload_url}
#
## Step 3: Upload resource's status to committed and get a release_url
#release_json=$(curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' --header "X-API-Token: ${token}" -d '{ "status": "committed" }' "${request_url}/${upload_id}")
#release_id=$(echo ${release_json} | \
# python3 -c "import sys, json; print(json.load(sys.stdin)['release_id'])")
#
#release_notes=""
#while read -r line; do
# release_notes="${release_notes}* ${line}\n"
#done < "${release_notes_file}"
#release_notes="$(tr '"' "'" <<< $release_notes)"
#release_notes=${release_notes::5000}
#
## Step 4: Distribute the uploaded release to a distribution group"
#release_url="https://api.appcenter.ms/v0.1/apps/${owner_name}/${app_name}/releases/${release_id}"
#data="{ \"destination_name\": \"${destination_name}\", \"release_notes\": \"${release_notes}\" }"
#echo ${data}
#response_json=$(curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' --header "X-API-Token: ${token}" -d "${data}" ${release_url})
#echo ${response_json}
# Step 2: Upload ipa
curl -F "ipa=@${build_path}" ${upload_url}
# Step 3: Upload resource's status to committed and get a release_url
release_json=$(curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' --header "X-API-Token: ${token}" -d '{ "status": "committed" }' "${request_url}/${upload_id}")
release_id=$(echo ${release_json} | \
python3 -c "import sys, json; print(json.load(sys.stdin)['release_id'])")
release_notes=""
while read -r line; do
release_notes="${release_notes}* ${line}\n"
done < "${release_notes_file}"
release_notes="$(tr '"' "'" <<< $release_notes)"
release_notes=${release_notes::5000}
# Step 4: Distribute the uploaded release to a distribution group"
release_url="https://api.appcenter.ms/v0.1/apps/${owner_name}/${app_name}/releases/${release_id}"
data="{ \"destination_name\": \"${destination_name}\", \"release_notes\": \"${release_notes}\" }"
echo ${data}
response_json=$(curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' --header "X-API-Token: ${token}" -d "${data}" ${release_url})
echo ${response_json}
if [ -n "$mapping_path" ]; then
echo "#step 1 get upload id and url"
request_url="https://api.appcenter.ms/v0.1/apps/${owner_name}/${app_name}/symbol_uploads"
data="{\"symbol_type\": \"AndroidProguard\",\"file_name\": \"mapping.txt\",\"build\": \"$versionName\",\"version\": \"$versionCode\"}"
mapping_json=$(curl -X POST \
-d "$data" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--header "X-API-Token: ${token}" \
"${request_url}" 2> /dev/null)
echo $mapping_json
upload_id=$(echo ${mapping_json} | \
python3 -c "import sys, json; print(json.load(sys.stdin)['symbol_upload_id'])")
upload_url=$(echo ${mapping_json} | \
python3 -c "import sys, json; print(json.load(sys.stdin)['upload_url'])")
echo "# step 2 upload mappings"
upload_response=$(curl -X PUT \
--header 'Accept: application/json' \
--header "X-API-Token: ${token}" \
--header "x-ms-blob-type: BlockBlob" \
-F "ipa=@$mapping_path" \
"$upload_url" 2> /dev/null)
echo "# step 3 confirm"
confirm_url="https://api.appcenter.ms/v0.1/apps/${owner_name}/${app_name}/symbol_uploads/${upload_id}"
data="{\"status\": \"committed\"}"
response_json=$(curl -X PATCH \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "X-API-Token: ${token}" \
-d "${data}" \
${confirm_url} 2> /dev/null)
fi

View file

@ -21,7 +21,14 @@ jobs:
key: jars-{{ checksum "build.gradle" }}-{{ checksum "touch/build.gradle" }}-{{ checksum "leanback/build.gradle" }}-{{ checksum "common/build.gradle" }}
- run:
name: Setup env
command: .circleci/setup_env.sh >> $BASH_ENV
command: |
.circleci/setup_env.sh >> $BASH_ENV
echo "VERSION_NAME=${VERSION_NAME}"
echo "STAGE=${STAGE}"
echo "VERSION_NAME=${VERSION_NAME}"
echo "BUILD_TYPE_LOWER=${BUILD_TYPE_LOWER}"
echo "STAGE_LOWER=${STAGE_LOWER}"
echo "LIBS_LOWER=${LIBS_LOWER}"
- run:
name: Download Dependencies
command: ./gradlew $SIGN_CONFIG androidDependencies
@ -35,11 +42,17 @@ jobs:
- run:
name: Build Touch
command: |
./gradlew $SIGN_CONFIG -PversionName=$(.circleci/getVersionCode.sh -t) touch:assemble${STAGE_LOWER}${LIBS}${BUILD_TYPE}
./gradlew $SIGN_CONFIG \
-PversionCode=$(.circleci/getVersionCode.sh -t) \
-PversionName=${VERSION_NAME} \
touch:assemble${STAGE_LOWER}${LIBS}${BUILD_TYPE}
- run:
name: Build Leanback
command: |
./gradlew $SIGN_CONFIG -PversionName=$(.circleci/getVersionCode.sh -l) leanback:assemble${STAGE_LOWER}${LIBS}${BUILD_TYPE}
./gradlew $SIGN_CONFIG \
-PversionCode=$(.circleci/getVersionCode.sh -l) \
-PversionName=${VERSION_NAME} \
leanback:assemble${STAGE_LOWER}${LIBS}${BUILD_TYPE}
- run:
name: Test
command: |
@ -83,7 +96,10 @@ jobs:
$APPCENTER_TOKEN \
"touch/build/outputs/apk/${STAGE_LOWER}${LIBS}/${BUILD_TYPE_LOWER}/touch-${STAGE_LOWER}-${LIBS_LOWER}-${BUILD_TYPE_LOWER}.apk" \
$RELEASENOTES_FILE \
$APPCENTER_GROUP
$APPCENTER_GROUP \
"touch/build/outputs/mapping/${STAGE_LOWER}${LIBS}/${BUILD_TYPE_LOWER}/mapping.txt"\
$(.circleci/getVersionCode.sh -t) \
$VERSION_NAME
- save_cache:
paths:
- ~/.gradle

View file

@ -1,5 +1,6 @@
#!/bin/sh
COUNT=$(git rev-list --count HEAD | tr -d '\n\r')
COUNT=$(expr $COUNT - 800)
if [ $(expr $COUNT % 2) -ne 0 ]; then
COUNT=$(expr $COUNT - 1)
fi

10
.circleci/getVersionName.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
VERSION_FILE="versionfile"
VERSION_NAME=$(cat ${VERSION_FILE} | tr -d '\n\r')
case $1 in
--touch|-t|touch) printf "${VERSION_NAME}-touch" ;;
--leanback|-l|leanback) printf "${VERSION_NAME}-leanback" ;;
--dev) printf "${VERSION_NAME}-develop" ;;
*) printf "${VERSION_NAME}" ;;
esac

View file

@ -1,25 +1,19 @@
#!/bin/bash
if [ "$CIRCLE_BRANCH" = "master" ] ; then
STAGE=Prod
VERSION_NAME=$(.circleci/getVersionName.sh)
else
STAGE=Dev
VERSION_NAME=$(.circleci/getVersionName.sh --dev)
fi
echo "export STAGE=$STAGE"
echo "export VERSION_NAME=$VERSION_NAME"
echo "export BUILD_TYPE_LOWER=\"$(tr '[:upper:]' '[:lower:]' <<< ${BUILD_TYPE:0:1})${BUILD_TYPE:1}\""
echo "export STAGE_LOWER=\"$(tr '[:upper:]' '[:lower:]' <<< ${STAGE:0:1})${STAGE:1}\""
echo "export LIBS_LOWER=\"$(tr '[:upper:]' '[:lower:]' <<< ${LIBS:0:1})${LIBS:1}\""
echo "$ENCODED_KEYSTORE" | base64 --decode >> ${HOME}/code/keystore.jks
KEYSTORE=${HOME}/code/keystore.jks
#mkdir ~/.gradle
#GRADLEFILE=~/.gradle/gradle.properties
#echo "chaosflixKeystore=$KEYSTORE" >> $GRADLEFILE
#echo "chaosflixStorePassword=$KEYSTORE_PASSWORD" >> $GRADLEFILE
#echo "chaosflixKeyName=$KEY_NAME" >> $GRADLEFILE
#echo "chaosflixKeyPassword=$KEYSTORE_PASSWORD" >> $GRADLEFILE
#echo "appcenterId=\"$APPCENTER_ID\"" >> $GRADLEFILE
#echo "appcenterDevId=\"$APPCENTER_DEV_ID\"" >> $GRADLEFILE
#echo 'export KEYSTORE=${HOME}/code/keystore.jks'
echo "export SIGN_CONFIG=\"-PchaosflixKeystore=$KEYSTORE\
-PchaosflixStorePassword=$KEYSTORE_PASSWORD\

1
versionfile Normal file
View file

@ -0,0 +1 @@
0.5