build.sh: save git URL and revision used for the build.
[armband.git] / ci / build.sh
1 #!/bin/bash
2 # Copyright (c) 2016 Enea Software AB
3 # All rights reserved. This program and the accompanying materials
4 # are made available under the terms of the Apache License, Version 2.0
5 # which accompanies this distribution, and is available at
6 # http://www.apache.org/licenses/LICENSE-2.0
7
8 error_exit() {
9     echo "$@" >&2
10     exit 1
11 }
12
13 write_gitinfo() {
14     git_url=$(git config --get remote.origin.url)
15     git_rev=$(git rev-parse HEAD)
16     echo "$git_url: $git_rev"
17 }
18
19 if [ $# -eq 0 ]; then
20     OUTPUT_DIR=$(pwd)
21 else
22     OUTPUT_DIR=$(readlink -f $1)
23     shift
24 fi
25
26 mkdir -p $OUTPUT_DIR || error_exit "Could not create directory $OUTPUT_DIR"
27
28 echo "Building armband, output dir: $OUTPUT_DIR"
29 cd ..
30
31 SCRIPT_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
32 BUILD_BASE="${SCRIPT_DIR}/upstream/fuel/build"
33 RESULT_DIR="${BUILD_BASE}/release"
34
35 make release || error_exit "Make release failed"
36
37 write_gitinfo >> ${BUILD_BASE}/gitinfo.txt
38
39 echo "Copying results to $OUTPUT_DIR"
40 sort ${BUILD_BASE}/gitinfo*.txt > ${OUTPUT_DIR}/gitinfo.txt
41 cp ${RESULT_DIR}/*.iso ${OUTPUT_DIR}/
42 cp ${RESULT_DIR}/*.iso.txt ${OUTPUT_DIR}/