Murat Parlakisik | f95672c | 2016-12-05 00:53:17 -0800 | [diff] [blame] | 1 | #!/bin/bash -eux |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 2 | |
| 3 | # Push the loxigen artifacts to a dedicated git repository, |
| 4 | # along with a nice commit message and a tag |
| 5 | |
| 6 | ARTIFACT_REPO_URL="$1" |
| 7 | if [[ ! $ARTIFACT_REPO_URL ]]; then |
| 8 | echo "Call syntax: $0 <artifact_repo_url>" >&2 |
| 9 | exit 1 |
| 10 | fi |
| 11 | |
Rich Lane | 7c5b6a6 | 2014-12-03 12:49:04 -0800 | [diff] [blame] | 12 | ARTIFACT_REPO_BRANCH=${2-master} |
Murat Parlakisik | f95672c | 2016-12-05 00:53:17 -0800 | [diff] [blame] | 13 | ARTIFACT_TARGET_BRANCH=${3-master} |
| 14 | |
| 15 | MAKE=${MAKE-make} |
Rich Lane | 7c5b6a6 | 2014-12-03 12:49:04 -0800 | [diff] [blame] | 16 | |
Andreas Wundsam | 77d0425 | 2013-11-20 11:02:45 -0800 | [diff] [blame] | 17 | ARTIFACT_REPO=$(mktemp -d --tmpdir "push-artifacts-repo.XXXXXXX") |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 18 | |
Rich Lane | 7c5b6a6 | 2014-12-03 12:49:04 -0800 | [diff] [blame] | 19 | git clone ${ARTIFACT_REPO_URL} ${ARTIFACT_REPO} -b ${ARTIFACT_REPO_BRANCH} |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 20 | |
Murat Parlakisik | f95672c | 2016-12-05 00:53:17 -0800 | [diff] [blame] | 21 | find ${ARTIFACT_REPO} -mindepth 1 -maxdepth 1 -type d \! -name '.*' -print0 | xargs -0 rm -r |
| 22 | ${MAKE} LOXI_OUTPUT_DIR=${ARTIFACT_REPO} clean all |
| 23 | |
| 24 | loxi_branch=$(git rev-parse --abbrev-ref HEAD) |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 25 | loxi_head=$(git rev-parse HEAD) |
| 26 | last_loxi_log=$(git log --format=oneline -1) |
Andreas Wundsam | 77d0425 | 2013-11-20 11:02:45 -0800 | [diff] [blame] | 27 | git_log_file=$(mktemp --tmpdir "git-log-file.XXXXXXX") |
| 28 | |
Andreas Wundsam | 71178d1 | 2013-11-20 11:38:38 -0800 | [diff] [blame] | 29 | last_loxi_revision="" |
| 30 | |
Andreas Wundsam | 77d0425 | 2013-11-20 11:02:45 -0800 | [diff] [blame] | 31 | if [[ -e "${ARTIFACT_REPO}/loxi-revision" ]]; then |
| 32 | last_loxi_revision=$(cat "${ARTIFACT_REPO}/loxi-revision" | cut -d ' ' -f 1) |
Andreas Wundsam | 71178d1 | 2013-11-20 11:38:38 -0800 | [diff] [blame] | 33 | if [[ $(git cat-file -t "$last_loxi_revision" 2>/dev/null) != "commit" ]]; then |
| 34 | echo "Last loxi revision ${last_loxi_revision} specified in ${ARTIFACT_REPO_URL}/loxi-revision not found in loxigen repo" |
| 35 | last_loxi_revision="" |
| 36 | fi |
| 37 | fi |
| 38 | |
| 39 | if [[ $last_loxi_revision ]]; then |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 40 | echo "Last loxi revision committed: $last_loxi_revision" |
Andreas Wundsam | 71178d1 | 2013-11-20 11:38:38 -0800 | [diff] [blame] | 41 | git log $last_loxi_revision..${loxi_head} >>$git_log_file |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 42 | loxi_github_url="https://github.com/floodlight/loxigen/compare/${last_loxi_revision}...${loxi_head}" |
| 43 | else |
| 44 | echo "No Previous loxi revision info found" |
| 45 | git log -1 HEAD >>$git_log_file |
| 46 | loxi_github_url="https://github.com/floodlight/loxigen/commit/${loxi_head}" |
| 47 | fi |
| 48 | |
| 49 | |
| 50 | ( |
| 51 | set -xe |
| 52 | cd $ARTIFACT_REPO |
| 53 | echo $last_loxi_log >loxi-revision |
| 54 | git add -A |
| 55 | |
| 56 | ( |
Murat Parlakisik | f95672c | 2016-12-05 00:53:17 -0800 | [diff] [blame] | 57 | echo "Artifacts from ${loxi_github_url} (Branch ${loxi_branch})" |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 58 | echo |
Andreas Wundsam | 77d0425 | 2013-11-20 11:02:45 -0800 | [diff] [blame] | 59 | echo "Loxigen Head commit floodlight/loxigen@${loxi_head}" |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 60 | cat $git_log_file |
| 61 | ) | git commit --file=- |
| 62 | |
| 63 | git tag -a -f "loxi/${loxi_head}" -m "Tag Loxigen Revision ${loxi_head}" |
Murat Parlakisik | f95672c | 2016-12-05 00:53:17 -0800 | [diff] [blame] | 64 | git push --tags -f |
| 65 | if [[ $ARTIFACT_TARGET_BRANCH != $ARTIFACT_REPO_BRANCH ]]; then |
| 66 | git push -f origin HEAD:${ARTIFACT_TARGET_BRANCH} |
| 67 | else |
| 68 | git push origin HEAD |
| 69 | fi |
Andreas Wundsam | d0b06f4 | 2013-11-19 17:18:14 -0800 | [diff] [blame] | 70 | ) |
| 71 | |
| 72 | rm -rf ${ARTIFACT_REPO} |