Browse Source

update scripts for continuous integration

Keep bare minimum of scripts & configuration files for CI.

Set Travis target language to generic, remove 'Gemfile' and
'Rakefile' since we building *.deb packages and not ruby ones.
Code that determining changes in git repository is reimplemented
in bash.

Disabled packages are excluded from CI tracking as they frequently
cause errors.
android-5
Leonid Plyushch 6 years ago
parent
commit
0950d69987
  1. 15
      .gitlab-ci.yml
  2. 35
      .travis.yml
  3. 4
      Gemfile
  4. 43
      Rakefile
  5. 72
      scripts/build/ci/determine_git_changes.sh
  6. 88
      scripts/ci/gitlab.sh

15
.gitlab-ci.yml

@ -2,23 +2,30 @@ image: termux/package-builder:latest
stages:
- build
- deploy
## Common configuration for all build jobs.
## Variables BINTRAY_* should be unset to
## prevent leaking of sensitive information.
.job_template: &build_job
stage: build
script:
- bash ./scripts/ci/gitlab.sh $TERMUX_ARCH
- unset BINTRAY_USERNAME
- unset BINTRAY_API_KEY
- unset BINTRAY_GPG_SUBJECT
- unset BINTRAY_GPG_PASSPHRASE
- |
for package in $(./scripts/build/ci/determine_git_changes.sh); do
./build-package.sh -q -i -a "$TERMUX_ARCH" "$package" || exit 1
done
retry:
max: 2
when:
- script_failure
- runner_system_failure
- unknown_failure
artifacts:
when: always
paths:
- deb-packages
- debs
## Building packages for AArch64.
build-aarch64:

35
.travis.yml

@ -1,12 +1,29 @@
language: ruby
sudo: required
cache: bundler
language: generic
## Force usage of "Ubuntu Xenial" as on older versions
## program "realpath" is not working for some reason.
os: linux
dist: xenial
services: docker
before_script: mkdir debs && chmod 777 debs
sudo: required
## Split per-architecture builds into separate jobs.
env:
matrix:
- ARGS="-i -a aarch64"
- ARGS="-i -a arm"
- ARGS="-i -a i686"
- ARGS="-i -a x86_64"
script: bundle exec rake build["${ARGS}"]
- TERMUX_ARCH=aarch64
- TERMUX_ARCH=arm
- TERMUX_ARCH=i686
- TERMUX_ARCH=x86_64
## Build modified packages.
## Variables BINTRAY_* should be unset to
## prevent leaking of sensitive information.
script:
- unset BINTRAY_USERNAME
- unset BINTRAY_API_KEY
- unset BINTRAY_GPG_SUBJECT
- unset BINTRAY_GPG_PASSPHRASE
- |
for package in $(./scripts/build/ci/determine_git_changes.sh); do
./scripts/run-docker.sh ./build-package.sh -q -i -a "$TERMUX_ARCH" "$package" || exit 1
done

4
Gemfile

@ -1,4 +0,0 @@
source 'https://rubygems.org'
gem 'rake'
gem 'rugged'

43
Rakefile

@ -1,43 +0,0 @@
require 'rugged'
require 'pty'
task default: %w[build]
task :build, [:options] do |t, args|
repo = Rugged::Repository.new('.')
commit = repo.head.target
parent = commit.parents.first
pkgs = commit.diff(parent).deltas.map { |d| d.new_file[:path] }
# Split paths into arrays
pkgs.map! { |p| Pathname.new(p).each_filename.to_a }
# looking for [disabled-]packages/(package_name)/...
pkgs.select! { |p| p.length > 2 and p[0] =~ /(?<disabled->)packages/ }
# Get package_name
pkgs.map! { |p| p[1] }
# Remove duplicate packages
pkgs.uniq!
pkgs.each do |pkg|
puts "Building #{pkg}"
begin
# Start blocking build loop
PTY.spawn("./scripts/run-docker.sh ./build-package.sh #{args[:options]} #{pkg}") do |stdout, stdin, pid|
begin
stdout.sync
stdout.each { |line| print line }
rescue Errno::EIO => e
puts e
ensure
::Process.wait pid
end
end
rescue PTY::ChildExited => e
puts e
puts "Process exited"
end
# Exit if PTY return a non-zero code
if $?.exitstatus != 0
STDERR.puts("Error building #{pkg}")
exit($?.exitstatus)
end
end
end

72
scripts/build/ci/determine_git_changes.sh

@ -0,0 +1,72 @@
#!/bin/bash
##
## Script for detecting modified packages.
## Designed for use with Travis or Gitlab CI.
##
## Leonid Plyushch <leonid.plyushch@gmail.com> (C) 2019
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
REPO_DIR=$(realpath "$(dirname "$(realpath "$0")")/../../../")
cd "$REPO_DIR" || {
echo "[!] Failed to cd into '$REPO_DIR'." >&2
exit 1
}
if [ -n "$TRAVIS_COMMIT_RANGE" ]; then
# We are on Travis CI.
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "${TRAVIS_COMMIT_RANGE//.../..}" 2>/dev/null | grep -P "packages/")
elif [ -n "$CI_COMMIT_SHA" ]; then
# We are on Gitlab CI.
# Make sure that we can use commit range.
if [ -z "$CI_COMMIT_BEFORE_SHA" ]; then
echo "[!] CI_COMMIT_BEFORE_SHA is not set." >&2
exit 1
fi
if [ "$CI_COMMIT_BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "$CI_COMMIT_SHA" 2>/dev/null | grep -P "packages/")
else
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "${CI_COMMIT_BEFORE_SHA}..${CI_COMMIT_SHA}" 2>/dev/null | grep -P "packages/")
fi
else
# Something wrong.
echo "[!] Cannot determine git commit range." >&2
echo " Did you executed this script under CI ?" >&2
exit 1
fi
## Determine modified packages.
existing_dirs=""
for dir in $(echo "$UPDATED_FILES" | grep -oP "packages/[a-z0-9+._-]+" | sort | uniq); do
if [ -d "$REPO_DIR/$dir" ]; then
existing_dirs+=" $dir"
fi
done
PACKAGE_DIRS="$existing_dirs"
unset dir existing_dirs
## Get names of modified packages.
PACKAGE_NAMES=$(echo "$PACKAGE_DIRS" | sed 's/packages\///g')
if [ -z "$PACKAGE_NAMES" ]; then
echo "[*] No modified packages found." >&2
exit 0
fi
## Print names of modified packages.
for pkg in $PACKAGE_NAMES; do
echo "$pkg"
done

88
scripts/ci/gitlab.sh

@ -1,88 +0,0 @@
#!/bin/bash
##
## Determine updated packages, build them and upload to bintray.com
## if requested. This script should be used with GitLab CI.
##
## Leonid Plyushch <leonid.plyushch@gmail.com> (C) 2019
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
REPO_DIR=$(realpath "$(dirname "$(realpath "$0")")/../../")
DEBS_DIR="$REPO_DIR/deb-packages"
cd "$REPO_DIR" || {
echo "[!] Failed to cd into '$REPO_DIR'."
exit 1
}
## Create directory where *.deb files will be placed.
if ! mkdir -p "$DEBS_DIR" > /dev/null 2>&1; then
echo "[!] Failed to create directory '$DEBS_DIR'."
exit 1
fi
## Verify that script is running under CI (GitLab).
if [ -z "${CI_COMMIT_BEFORE_SHA}" ]; then
echo "[!] CI_COMMIT_BEFORE_SHA is not set !"
exit 1
fi
if [ -z "${CI_COMMIT_SHA}" ]; then
echo "[!] CI_COMMIT_SHA is not set !"
exit 1
fi
## Check for updated files.
if [ "$CI_COMMIT_BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "${CI_COMMIT_SHA}" | grep -P "packages/")
else
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "${CI_COMMIT_BEFORE_SHA}..${CI_COMMIT_SHA}" | grep -P "packages/")
fi
## Determine modified packages.
existing_dirs=""
for dir in $(echo "$UPDATED_FILES" | grep -oP "packages/[a-z0-9+._-]+" | sort | uniq); do
if [ -d "$REPO_DIR/$dir" ]; then
existing_dirs+=" $dir"
fi
done
PACKAGE_DIRS="$existing_dirs"
unset dir existing_dirs
## Get names of modified packages.
PACKAGE_NAMES=$(echo "$PACKAGE_DIRS" | sed 's/packages\///g')
if [ -z "$PACKAGE_NAMES" ]; then
echo "[*] No modified packages found."
exit 0
fi
## Handle arguments.
## Script expects only one command line argument.
## It should be either architecture (aarch64, arm, i686, x86_64)
## or '--upload'.
if [ $# -ge 1 ]; then
if [ "$1" = "--upload" ]; then
exec "$REPO_DIR/scripts/bintray-add-package.sh" --path "$DEBS_DIR" $PACKAGE_NAMES
else
TERMUX_ARCH="$1"
unset BINTRAY_USERNAME
unset BINTRAY_API_KEY
fi
else
TERMUX_ARCH="aarch64"
fi
echo "[@] Building packages for architecture '$TERMUX_ARCH':"
for pkg in $PACKAGE_NAMES; do
./build-package.sh -i -f -o "$DEBS_DIR" -a "$TERMUX_ARCH" "$(basename "$pkg")"
done
Loading…
Cancel
Save