Skip to content

Commit 6ae7920

Browse files
Merge pull request #178 from optimizely/jctong/sdk_deploy
ci(travis): automate sdk release
2 parents cb7ae9d + 19ebaef commit 6ae7920

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

.travis.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,29 @@ jobs:
6767
- <<: *unittests
6868
env: SCHEME=OptimizelySwiftSDK-tvOS TEST_SDK=appletvsimulator PLATFORM='tvOS Simulator' OS=10.2 NAME='Apple TV 1080p'
6969
name: PLATFORM='tvOS Simulator' OS=10.2 NAME='Apple TV 1080p'
70+
71+
- stage: 'Prepare for release'
72+
name: Prepare for release
73+
language: swift
74+
os: osx
75+
osx_image: xcode10.1
76+
env:
77+
- VERSION=3.0.2
78+
install:
79+
# install hub
80+
- wget https://github.com/github/hub/releases/download/v2.11.2/hub-darwin-amd64-2.11.2.tgz -O /tmp/hub-darwin-amd64-2.11.2.tgz && tar -xvf /tmp/hub-darwin-amd64-2.11.2.tgz -C /usr/local/opt && ln -s /usr/local/opt/hub-darwin-amd64-2.11.2/bin/hub /usr/local/bin/hub
81+
script:
82+
- Scripts/run_prep.sh
83+
84+
- stage: 'Release'
85+
name: Push to cocoapods.org
86+
language: minimal
87+
os: osx
88+
osx_image: xcode10.1
89+
env:
90+
- VERSION=3.0.2
91+
install:
92+
# install hub
93+
- wget https://github.com/github/hub/releases/download/v2.11.2/hub-darwin-amd64-2.11.2.tgz -O /tmp/hub-darwin-amd64-2.11.2.tgz && tar -xvf /tmp/hub-darwin-amd64-2.11.2.tgz -C /usr/local/opt && ln -s /usr/local/opt/hub-darwin-amd64-2.11.2/bin/hub /usr/local/bin/hub
94+
script:
95+
- Scripts/run_release.sh

Scripts/run_prep.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Because `hub` is used, this script expects the following environment variables defined in travis job settings:
5+
# GITHUB_TOKEN - github api token with repo permissions (display value in build log setting: OFF)
6+
# GITHUB_USER - github username that GITHUB_TOKEN is associated with (display value in build log setting: ON)
7+
8+
# Additionally, it needs the following environment variables:
9+
# VERSION - defined in .travis.yml
10+
11+
# Variables starting with TRAVIS_ are default environment variables available to all Travis CI builds
12+
13+
COLOR_RESET='\033[0m'
14+
COLOR_MAGENTA='\033[0;35m'
15+
COLOR_CYAN='\033[0;36m'
16+
MYREPO=${HOME}/workdir/${TRAVIS_REPO_SLUG}
17+
AUTOBRANCH=${GITHUB_USER}/prepareRelease${VERSION}
18+
BUILD_OUTPUT=/tmp/build.out
19+
touch $BUILD_OUTPUT
20+
21+
function prep_workspace {
22+
rm -rf ${MYREPO}
23+
mkdir -p ${MYREPO}
24+
git clone -b ${TRAVIS_BRANCH} https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG} ${MYREPO}
25+
cd ${MYREPO}
26+
git checkout -b ${AUTOBRANCH}
27+
}
28+
29+
dump_output() {
30+
echo "last 100 lines of output:"
31+
tail -100 $BUILD_OUTPUT
32+
}
33+
34+
function error_handler() {
35+
echo "ERROR: An error was encountered."
36+
dump_output
37+
exit 1
38+
}
39+
40+
function do_stuff {
41+
# keepalive for Travis
42+
while :; do sleep 10; echo -n .; done &
43+
trap "kill $!" EXIT
44+
trap 'error_handler' ERR
45+
46+
myscripts=( "build_all.sh" "test_all.sh" "update_version.sh ${VERSION}" )
47+
for i in "${myscripts[@]}"; do
48+
echo -n "${i} "
49+
Scripts/${i} >> $BUILD_OUTPUT 2>&1
50+
echo
51+
done
52+
53+
dump_output
54+
kill $! && trap " " EXIT
55+
}
56+
57+
function push_changes {
58+
git config user.email "optibot@users.noreply.github.com"
59+
git config user.name "${GITHUB_USER}"
60+
git add --all && git commit -m "ci(travis): auto release prep for $VERSION"
61+
git push https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG} ${AUTOBRANCH}
62+
PR_URL=$(hub pull-request --no-edit -b ${TRAVIS_BRANCH})
63+
echo -e "${COLOR_CYAN}ATTENTION:${COLOR_RESET} review and merge ${COLOR_CYAN}${PR_URL}${COLOR_RESET}"
64+
echo "then to release to cocoapods use Travis CI's Trigger build with the following payload:"
65+
echo -e "${COLOR_MAGENTA}env:${COLOR_RESET}"
66+
echo -e "${COLOR_MAGENTA} - RELEASE=true${COLOR_RESET}"
67+
}
68+
69+
function main {
70+
prep_workspace
71+
time do_stuff
72+
push_changes
73+
}
74+
75+
main

Scripts/run_release.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Because `hub` is used, this script expects the following environment variables defined in travis job settings:
5+
# GITHUB_TOKEN - github api token with repo permissions (display value in build log setting: OFF)
6+
# GITHUB_USER - github username that GITHUB_TOKEN is associated with (display value in build log setting: ON)
7+
8+
# COCOAPODS_TRUNK_TOKEN - should be defined in job settings so that we can `pod trunk push`
9+
10+
function release_github {
11+
CHANGELOG="CHANGELOG.md"
12+
13+
# check that CHANGELOG.md has been updated
14+
NEW_VERSION_CHECK=$(grep '^## \d\+\.\d\+.\d\+' ${CHANGELOG} | awk 'NR==1' | tr -d '# ')
15+
if [[ ${NEW_VERSION_CHECK} != ${VERSION} ]]; then
16+
echo "ERROR: ${CHANGELOG} has not been updated yet."
17+
exit 1
18+
fi
19+
20+
NEW_VERSION=$(grep '^## \d\+\.\d\+.\d\+' ${CHANGELOG} | awk 'NR==1')
21+
LAST_VERSION=$(grep '^## \d\+\.\d\+.\d\+' ${CHANGELOG} | awk 'NR==2')
22+
23+
DESCRIPTION=$(awk "/^${NEW_VERSION}$/,/^${LAST_VERSION}$/" ${CHANGELOG} | grep -v "^${LAST_VERSION}$")
24+
25+
hub release create v${VERSION} -m "Release ${VERSION}" -m "${DESCRIPTION}"
26+
27+
}
28+
29+
function release_cocoapods {
30+
31+
# ---- Optimizely's pods ----
32+
pods=(OptimizelySwiftSDK);
33+
number_pods=${#pods[@]};
34+
35+
# ---- push podspecs to cocoapods ----
36+
# The podspecs need to be pushed in the correct order because of dependencies!
37+
printf "\n\nPushing podspecs to COCOAPODS.ORG .\n";
38+
for (( i = 0; i < ${number_pods}; i++ ));
39+
do
40+
podname=${pods[i]};
41+
printf "Pushing the ${podname} pod to COCOAPODS.ORG .\n"
42+
pod trunk push --allow-warnings ${podname}.podspec
43+
pod update
44+
done
45+
46+
}
47+
48+
function main {
49+
release_github
50+
release_cocoapods
51+
}
52+
53+
main

0 commit comments

Comments
 (0)