Automatic packages build/upload

This commit is contained in:
Romain Thomas 2017-07-13 08:55:57 +02:00
parent 314bb29ab0
commit 30582874b3
4 changed files with 188 additions and 2 deletions

View File

@ -11,6 +11,10 @@ platform:
- x64
environment:
LIEF_AUTOMATIC_BUILDS_KEY:
secure: TT7SXISIifq2/tf02n2ATgPj+Ky4Cjl3Fg44BAfyI4yRa4i87UAQIx5EFeV63+Xv2rhcU7JcMgl+An7QBrV6ofuQ9jxbuw+Gd1GqcCrAIyY=
LIEF_AUTOMATIC_BUILDS_IV:
secure: /S6Vbt3vEisoC81siFbkqOXQeVnwxLZZPMYp1r79G7h+HFjLlWUZSidxxpsAgHNE
matrix:
# Python 2.7
- PYTHON_VERSION: "2.7"
@ -47,6 +51,7 @@ environment:
PYTHON64_BINARY: "C:\\Python36-x64\\python.exe"
PYTHON64_LIBRARY: "C:\\Python36-x64\\libs\\python36.lib"
matrix:
fast_finish: true # set this flag to immediately finish build once one of the jobs fails.
allow_failures:
@ -83,6 +88,7 @@ after_build:
- python.exe .\setup.py sdist --formats=zip && exit 0 # Ignore warnings...
- ps: gci dist\*.zip | % { rename-item path $_.Fullname Newname ( "windows_" + $env:PLATFORM + "_" + $_.basename + "_py" + $env:PYTHON_VERSION + $_.extension) }
- cd ..\..
- bash ./.github/deploy.sh
artifacts:
- path: '*.zip'

BIN
.github/deploy-key.enc vendored Normal file

Binary file not shown.

178
.github/deploy.sh vendored Normal file
View File

@ -0,0 +1,178 @@
#! /bin/bash
## vim:set ts=4 sw=4 et:
#
# Automatic build of LIEF
# Repo: https://github.com/lief-project/packages
# Mostly inspired by https://github.com/upx/upx-automatic-builds
set -e; set -o pipefail
if [[ $TRAVIS_OS_NAME == osx ]]; then
argv0=$0; argv0abs=$(greadlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
else
argv0=$0; argv0abs=$(readlink -en -- "$0"); argv0dir=$(dirname "$argv0abs")
fi
set -x # debug
if [[ $TRAVIS_OS_NAME == osx ]]; then
# use GNU coreutils ("brew install coreutils")
date() {
gdate "$@"
}
readlink() {
greadlink "$@"
}
sha256sum() {
gsha256sum "$@"
}
fi
if [[ -n $APPVEYOR_JOB_ID ]]; then
openssl() {
/usr/bin/openssl "$@"
}
sort() {
/usr/bin/sort "$@"
}
fi
fix_home_ssh_perms() {
if [[ -d ~/.ssh ]]; then
if [[ -x /usr/sbin/restorecon ]]; then
/usr/sbin/restorecon -v -R ~/.ssh || true
fi
chmod -c -R go-rwx ~/.ssh || true
fi
}
# =================
# SETUP BRANCH NAME
# =================
branch=
if [[ -n $APPVEYOR_JOB_ID ]]; then
branch=$APPVEYOR_REPO_BRANCH
if [[ -n $APPVEYOR_PULL_REQUEST_NUMBER ]]; then exit 0; fi
else
branch=$TRAVIS_BRANCH
if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then exit 0; fi
fi
case $branch in
devel*) ;;
master*) ;;
deploy*) ;;
*) exit 0;;
esac
# get $rev, $branch and $git_user
LIEF_SRCDIR=
[[ -z $LIEF_SRCDIR ]] && LIEF_SRCDIR=$(readlink -mn -- $argv0dir/..)
cd / && cd $LIEF_SRCDIR || exit 1
rev=$(git rev-parse --verify HEAD)
timestamp=$(git log -n1 --format='%at' $rev)
date=$(TZ=UTC0 date -d "@$timestamp" '+%Y%m%d-%H%M%S')
#branch="$branch-$date-${rev:0:6}"
branch="lief-$branch-latest"
if [[ -n $APPVEYOR_JOB_ID ]]; then
branch="$branch"
git_user="AppVeyor CI"
else
branch="$branch"
git_user="Travis CI"
fi
unset timestamp date
# ========================
# SETUP 'deploy' DIRECTORY
# ========================
if [[ -n $APPVEYOR_JOB_ID ]]; then
[[ -z $LIEF_BUILDDIR ]] && LIEF_BUILDDIR=$(readlink -mn -- .)
else
[[ -z $LIEF_BUILDDIR ]] && LIEF_BUILDDIR=$(readlink -mn -- ./build)
fi
echo $LIEF_BUILDDIR
cd / && cd $LIEF_BUILDDIR || exit 1
mkdir deploy || exit 1
chmod 700 deploy
cd deploy || exit 1
# ==================
# CLONE - ADD - PUSH
# ==================
new_branch=0
if ! git clone -b "$branch" --depth 3 --single-branch https://github.com/lief-project/packages.git; then
git clone -b master --depth 3 --single-branch https://github.com/lief-project/packages.git
new_branch=1
fi
cd packages || exit 1
chmod 700 .git
git config user.name "$git_user"
git config user.email "lief@quarkslab.com"
if [[ $new_branch == 1 ]]; then
git checkout --orphan "$branch"
git reset --hard || true
fi
git ls-files -v
if [[ -n $APPVEYOR_JOB_ID ]]; then
/bin/cp -rf $LIEF_BUILDDIR/api/python/dist/*.zip .
/bin/cp -rf $LIEF_BUILDDIR/*.zip .
else
/bin/cp -rf $LIEF_BUILDDIR/api/python/dist/*.tar.gz .
/bin/cp -rf $LIEF_BUILDDIR/*.tar.gz .
fi
git add .
if git diff --cached --exit-code --quiet >/dev/null; then
# nothing to do ???
exit 0
fi
now=$(date '+%s')
git commit --date="$now" -m "Automatic build - ${rev:0:7} - Python ${PYTHON_VERSION}"
git ls-files -v
git log --pretty=fuller
umask 077
[[ -d ~/.ssh ]] || mkdir ~/.ssh
fix_home_ssh_perms
repo=$(git config remote.origin.url)
ssh_repo=${repo/https:\/\/github.com\//git@github.com:}
eval $(ssh-agent -s)
set +x # IMPORTANT
openssl aes-256-cbc -K $LIEF_AUTOMATIC_BUILDS_KEY -iv $LIEF_AUTOMATIC_BUILDS_IV -in "$LIEF_SRCDIR/.github/deploy-key.enc" -out .git/deploy-key -d
set -x
chmod 600 .git/deploy-key
ssh-add .git/deploy-key
fix_home_ssh_perms
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
fix_home_ssh_perms
#
let i=0 || true
while true; do
if [[ $i -ge 10 ]]; then
echo "ERROR: git push failed"
exit 1
fi
if [[ $new_branch == 1 ]]; then
if git push -u $ssh_repo "$branch"; then break; fi
else
if git push $ssh_repo "$branch"; then break; fi
fi
git branch -a -v
git fetch -v origin "$branch"
git branch -a -v
git rebase -s recursive -X theirs FETCH_HEAD
git branch -a -v
sleep $((RANDOM % 5 + 1))
let i+=1
done
exit 0

View File

@ -14,7 +14,7 @@ matrix:
env: [ CXX_COMPILER=g++-5, C_COMPILER=gcc-5, PYTHON_VERSION=2.7, PYTHON_INCLUDE_DIR=/usr/include/python2.7, PYTHON_LIBRARY=/usr/lib/libpython2.7.so, PYTHON_BINARY=/usr/bin/python2.7 ]
## Linux gcc 5.0 - Python 3.5
# Linux gcc 5.0 - Python 3.5
- os: linux
dist: trusty
compiler: gcc
@ -129,7 +129,7 @@ install:
script:
- cmake -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER -DPYTHON_VERSION=$PYTHON_VERSION -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DPYTHON_LIBRARY=$PYTHON_LIBRARY -DPYTHON_EXECUTABLE=$PYTHON_BINARY -DLIEF_TESTS=on -DLIEF_DOC=${LIEF_DOC:-OFF} ..
- cmake -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER -DPYTHON_VERSION=$PYTHON_VERSION -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DPYTHON_LIBRARY=$PYTHON_LIBRARY -DPYTHON_EXECUTABLE=$PYTHON_BINARY -DLIEF_TESTS=on -DLIEF_PYTHON_API=on -DLIEF_DOC=${LIEF_DOC:-OFF} ..
- make -j2
- sudo make check-lief
@ -141,6 +141,8 @@ after_success:
- $PYTHON_BINARY setup.py sdist
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "linux_${f%.tar.gz}_py${PYTHON_VERSION}.tar.gz"; done' ;fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "osx_${f%.tar.gz}_py$PYTHON_VERSION.tar.gz"; done' ;fi
- cd $TRAVIS_BUILD_DIR
- bash ./.github/deploy.sh
deploy: