add travis autobuild scripts (courtesy of EmuTOS project)

This commit is contained in:
Markus Fröschle
2017-12-25 11:44:39 +01:00
parent 94ae80ac3d
commit 114d9c6fc5
7 changed files with 216 additions and 0 deletions

47
.travis.yml Normal file
View File

@@ -0,0 +1,47 @@
# BaS_gcc build script for Travis CI
# This will automatically be run on every push to GitHub
# Build History: https://travis-ci.org/firebee-org/BaS_gcc/builds/
language: c
os: linux
dist: trusty
sudo: required
before_install:
# Install our SSH key pair
- .travis/install_ssh_id.sh
- unset SSH_ID
# Register third-party APT repositories
- sudo .travis/register_apt_repositories.sh
# Install additional packages
- sudo apt-get install -y cross-mint-essential dos2unix lftp
# Display packages versions
- git --version
- make --version
- ld --version
- gcc --version
- m68k-atari-mint-ld --version
- m68k-atari-mint-gcc --version
- tar --version
- unix2dos --version
- lftp --version
script:
# Set FIXED_TRAVIS_COMMIT_RANGE
- . .travis/fix_travis_commit_range.sh
# Build binaries
- export VERSION=$(date -u +%Y%m%d-%H%M%S)-$(git rev-parse --short $TRAVIS_COMMIT)
- make clean
- make all
# Add README.txt
- .travis/generate-readme.sh >release-archives/README.md
# Display resulting tree
- ls -l release-archives
deploy:
skip_cleanup: true
provider: script
script: .travis/deploy.sh
on:
repo: firebee-org/BaS_gcc
branch: master

5
.travis/deploy.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash -eu
# -e: Exit immediately if a command exits with a non-zero status.
# -u: Treat unset variables as an error when substituting.
echo "no deployment step implemented (yet)"

View File

@@ -0,0 +1,35 @@
# This script fragment must be sourced by the main script file
# in order to define the FIXED_TRAVIS_COMMIT_RANGE variable
# . .travis/fix_travis_commit_range.sh
# TRAVIS_COMMIT_RANGE uses triple-dot syntax to specify which commits have
# triggered the build. This is wrong. In case of forced push, the previous
# commit is not an ancestor of the last commit, so it is not present in the
# cloned repository. And also, the range contains unrelated commits.
# https://docs.travis-ci.com/user/environment-variables/
# https://git-scm.com/book/tr/v2/Git-Tools-Revision-Selection
# https://github.com/travis-ci/travis-ci/issues/4596
#
# The solution is to use double-dot syntax instead.
# In case of forced push, we can't know the previous commit. So we just use
# the parent commit as previous one.
echo TRAVIS_COMMIT_RANGE=$TRAVIS_COMMIT_RANGE
PREVIOUS_COMMIT=$(echo $TRAVIS_COMMIT_RANGE | sed 's/\.\.\..*//')
CURRENT_COMMIT=$TRAVIS_COMMIT
if ! git merge-base --is-ancestor $PREVIOUS_COMMIT $CURRENT_COMMIT 2>/dev/null
then
# Forced push: use parent commit as previous commit
PREVIOUS_COMMIT=$CURRENT_COMMIT~
fi
# Normalize commits
PREVIOUS_COMMIT=$(git rev-parse --short $PREVIOUS_COMMIT)
CURRENT_COMMIT=$(git rev-parse --short $CURRENT_COMMIT)
export FIXED_TRAVIS_COMMIT_RANGE=$PREVIOUS_COMMIT..$CURRENT_COMMIT
echo FIXED_TRAVIS_COMMIT_RANGE=$FIXED_TRAVIS_COMMIT_RANGE
unset PREVIOUS_COMMIT CURRENT_COMMIT

53
.travis/generate-purge.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/bash -u
# -u: Treat unset variables as an error when substituting.
# Purpose: Purge old snapshots
# Input: output of lftp "ls" command
# Output: lftp "rm -r" commands
# Number of days of retention before purge
days_retention=7
# But always keep a minimal number of snapshots
min_keep=5
# Every snapshot up to this day will be purged
last_day_purge=$(date -u +%Y%m%d --date "$days_retention days ago")
# Current number of snapshots kept
n=0
# Read each remote file, as output from lftp "ls" command
while read flags links user group size month day hour f
do
# Skip non-snapshots
if [[ ! $f =~ ^[0-9]*-[0-9]*-[0-9a-z]* ]]
then
continue
fi
echo $f
# Then reverse sort to have last snapshots first
done | sort -r | while read f
do
# This is one more snapshot
(( n++ ))
# Do not purge until minimal number of snapshots
if [ $n -le $min_keep ]
then
echo "echo '#keep $f'"
continue
fi
# Purge old snapshots
day=$(echo $f | cut -d - -f 1)
if [ $day -le $last_day_purge ]
then
echo "echo 'rm -r $f'"
echo "rm -r $f"
else
echo "echo '#keep $f'"
fi
done

20
.travis/generate-readme.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash -eu
# -e: Exit immediately if a command exits with a non-zero status.
# -u: Treat unset variables as an error when substituting.
# See .travis/fix_travis_commit_range.sh for details about the commit range.
# The argument for GitHub /compare/ requires 3 dots.
COMPARE_ARG=$(echo $FIXED_TRAVIS_COMMIT_RANGE | sed 's/\.\./.../')
echo "These binaries have been produced by"
echo "[Travis CI Build #$TRAVIS_BUILD_NUMBER](https://travis-ci.org/firebee-org/BaS_gcc/builds/$TRAVIS_BUILD_ID)"
echo "for commits [$FIXED_TRAVIS_COMMIT_RANGE](https://github.com/firebee-org/BaS_gcc/compare/$COMPARE_ARG)."
echo
# Generate log as preformatted text with hyperlinks
git log --name-status $FIXED_TRAVIS_COMMIT_RANGE -- | sed \
-e 's|.*|``&`` |' \
-e 's|[a-z]\+://[^ `]*|``\[&\](&)``|g' \
-e 's|commit \([0-9a-f]\+\)|commit`` \[\1\](https://github.com/firebee-org/BaS_gcc/commit/\1) ``|g' \
-e 's|````||g'

37
.travis/install_ssh_id.sh Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash -eu
# -e: Exit immediately if a command exits with a non-zero status.
# -u: Treat unset variables as an error when substituting.
# This installs an SSH private/public key pair on the build system,
# so ssh can connect to remote servers without password.
# Important: for passwordless connection to succeed, our public key must be
# manually authorized on the remote server.
# Our private key is the critical security component, it must remain secret.
# We store it in the SSH_ID environment variable in Travis CI project settings.
# As environment variables can only contain text, our key files are transformed
# like this: tar, xz, base64. Then then can be decoded here. This is safe as
# Travis CI never shows the contents of secure variables.
# To generate the contents of the SSH_ID variable:
# Be sure to be in an empty, temporary directory.
#
# mkdir .ssh
# ssh-keygen -t rsa -b 4096 -C travis-ci.org/firebee-org/BaS_gcc -N '' -f .ssh/id_rsa
# tar Jcvf id_firebee-org_BaS_gcc.tar.xz .ssh
# base64 -w 0 id_firebee-org_BaS_gcc.tar.xz
#
# Select the resulting encoded text (several lines) to copy it to the clipboard.
# Then go to the Travis CI project settings:
# https://travis-ci.org/firebee-org/BaS_gcc/settings
# Create a new environment variable named SSH_ID, and paste the value.
# The script below will recreate the key files from that variable contents.
if [ -z ${SSH_ID+x} ]
then
echo "error: SSH_ID is undefined" >&2
exit 1
fi
echo $SSH_ID | base64 -d | tar -C ~ -Jx
ls -l ~/.ssh

View File

@@ -0,0 +1,19 @@
#!/bin/bash -eu
# -e: Exit immediately if a command exits with a non-zero status.
# -u: Treat unset variables as an error when substituting.
if [ $UID != 0 ]
then
echo "error: This script needs to be run with root access rights." 2>&1
exit 1
fi
# Display expanded script commands
set -x
# Vincent Rivière's m68k-atari-mint cross-tools
# http://vincent.riviere.free.fr/soft/m68k-atari-mint/ubuntu.php
sudo add-apt-repository -y ppa:vriviere/ppa
# Update the packages list
apt-get update -qq