diff --git a/Jenkinsfile b/Jenkinsfile index 47b6b1f..2d0e2cd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,105 +1,101 @@ #!groovy /* The MIT License Copyright (c) 2015-, CloudBees, Inc., and a number of other of contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ pipeline { agent { node { label 'linux' } } environment { WORKSPACE=pwd() PATH="/opt/usr/bin:$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH" JOB_NAME="tests" RBENV_VERSION="2.5.0" } options { disableConcurrentBuilds() timestamps() buildDiscarder(logRotator(numToKeepStr: '3', artifactNumToKeepStr: '3')) } triggers { pollSCM('H */4 * * 1-5') } stages { stage( 'Checkout' ) { steps { checkout scm } } stage( 'Setup' ) { steps { sh 'echo "gem: --no-rdoc --no-ri" >> $HOME/.gemrc' sh ''' echo "BUNDLE_PATH: ~/vendor/bundle" >> $HOME/.bundle/config echo 'BUNDLE_DISABLE_SHARED_GEMS: "1"' >> $HOME/.bundle/config ''' sh '''#!/usr/bin/env bash set -e echo $PATH if [[ ! -d ~/.rbenv ]] ; then git clone https://github.com/sstephenson/rbenv.git ~/.rbenv git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build git clone git://github.com/carsomyr/rbenv-bundler.git ~/.rbenv/plugins/bundler rbenv init - rbenv install 2.5.0 rbenv rehash else echo "Rbenv exists, moving on" if [[ ! -d $HOME/.rbenv/versions/2.5.0 ]] ; then rbenv install 2.5.0 rbenv rehash fi fi echo 'eval "$(rbenv init -)"' >> $HOME/.bashrc && rbenv init - ''' sh '''#!/usr/bin/env bash set -e export RBENV_ROOT=$HOME/.rbenv rbenv rehash if [[ ! -d $HOME/.gem ]] ; then rm -rfv $HOME/.gem fi which ruby ruby -v gem install --no-ri --no-rdoc bundler && rbenv rehash ''' } } stage( 'Build' ) { steps { sh 'rbenv init -' sh 'which ruby && ruby -v' sh '''#!/usr/bin/env bash set -e echo $PATH pwd chmod +x tests/setup.sh bundle bundle show rspec rbenv rehash bundle list --paths bundle env bundle exec ruby tests/deploy.rb ''' } } - stage('Tests') { - steps { - step([$class: 'LogParserPublisher', failBuildOnError: true, projectRulePath: "$JOB_NAME/appimage-template/parser.rules", showGraphs: true, unstableOnWarning: true, useProjectRule: true]) - } } } } diff --git a/tests/tooling.rb b/tests/tooling.rb index 7513620..a5a8038 100644 --- a/tests/tooling.rb +++ b/tests/tooling.rb @@ -1,205 +1,205 @@ #!/usr/bin/env ruby # frozen_string_literal: true # # Copyright (C) 2016 Scarlett Clark # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) version 3, or any # later version accepted by the membership of KDE e.V. (or its # successor approved by the membership of KDE e.V.), which shall # act as a proxy defined in Section 6 of version 3 of the license. # # This library 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 # Lesser General Public License fo-r more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library. If not, see . require 'test/unit' require 'yaml' require 'fileutils' require 'tty-command' require_relative '../libs/sources' require_relative '../libs/build' require_relative '../libs/setup' require_relative '../libs/builddocker.rb' # Test yaml data class TestSources < Test::Unit::TestCase def project_name Dir.chdir('/in') setup = Setup.new( File.join(File.dirname(__FILE__), 'data/metadata.yml') ) setup.set_main_vars assert_equal('appimage-packaging', setup.metadata['name']) end def test_env Dir.chdir('/in') env = Setup.new( File.join(File.dirname(__FILE__), 'data/metadata.yml') ) env.set_env assert_equal( '/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', ENV.fetch('PATH') ) end def test_data Dir.chdir('/in') setup = Setup.new( File.join(File.dirname(__FILE__), 'data/metadata.yml') ) setup.set_main_vars assert_equal(setup.scm, 'git', setup.scm) setup.set_dep_vars(setup.dependencies[0]) assert_equal(setup.depname, 'grantlee') setup.set_dep_vars(setup.dependencies[0]) assert_equal(setup.scm, 'git') assert_equal(setup.buildoptions, '-DCMAKE_INSTALL_PREFIX:PATH=/opt/usr CMAKE_BUILD_TYPE=Release') end def test_apt Dir.chdir('/in') setup = Setup.new( File.join(File.dirname(__FILE__), 'data/metadata.yml') ) setup.set_main_vars setup.install_packages(setup.packages) assert(setup.status.to_s.include?('exit 0')) assert(system('dpkg -l qt5-qmake')) end def test_fetch_tarball fetch = Sources.new('/app/src') fetch.fetch_tarball('https://download.kde.org/stable/applications/18.08.2/src/akonadi-notes-18.08.2.tar.xz') assert(File.file?('akonadi-notes-18.08.2.tar.xz'), 'Nothing was downloaded') assert(fetch.check_md5sum('akonadi-notes-18.08.2.tar.xz', '485fa04d3d46be2188fa262e5ee53654'), 'md5sum failed') FileUtils.rm('akonadi-notes-18.08.2.tar.xz') end def test_git clone = Sources.new('/app/src') clone.clone_git('https://anongit.kde.org/akonadi-notes', 'Applications/18.08') assert(File.exist?('/app/src/akonadi-notes'), 'Git clone failed') FileUtils.rm_rf('/app/src/akonadi-notes') end def test_unpack_tarball unpack = Sources.new('/app/src') unpack.fetch_tarball('https://download.kde.org/stable/applications/18.08.2/src/akonadi-notes-18.08.2.tar.xz') assert(File.file?('akonadi-notes-18.08.2.tar.xz'), 'Nothing was downloaded') system('file akonadi-notes-18.08.2.tar.xz') assert_equal(File.extname('akonadi-notes-18.08.2.tar.xz').delete('.'), 'xz') unpack.unpack_tarball('akonadi-notes-18.08.2.tar.xz', 'akonadi-notes-18.08.2') assert(File.exist?('/app/src/akonadi-notes-18.08.2'), 'Unpack failed') Build.new('/app/src/akonadi-notes-18.08.2', false, true) cmd = TTY::Command.new working_dir = cmd.run('pwd') assert(working_dir, '/app/src/akonadi-notes-18.08.2') assert(File.exist?('/app/src/akonadi-notes-18.08.2/CMakeLists.txt')) FileUtils.rm('/app/src/akonadi-notes-18.08.2.tar.xz') FileUtils.rm_rf('akonadi-notes-18.08.2') end def test_in_source clone = Sources.new('/app/src') insource = true clone.clone_git('https://anongit.kde.org/akonadi-notes') Build.new('/app/src/akonadi-notes', false, insource) assert(File.dirname(__FILE__), 'akonadi-notes') insource = false Build.new('/app/src/akonadi-notes', false, insource) assert(File.dirname(__FILE__), 'build') FileUtils.rm_rf('/app/src/akonadi-notes') end def test_cmake_build Dir.chdir('/in') data = Setup.new( File.join(__dir__, 'data/metadata.yml') ) data.set_main_vars insource = true options = data.buildoptions buildsystem = data.buildsystem Sources.new('/app/src') FileUtils.cp_r('/in/tests/data/cmake/.', '/app/src/cmake') build = Build.new('/app/src/cmake', false, insource) build.run_build(buildsystem, options) assert(build.status.to_s.include?('exit 0')) FileUtils.rm_rf('/app/src/cmake') end def test_make_build Dir.chdir('/in') insource = true options = '--prefix=/opt/usr' Sources.new('/app/src') FileUtils.cp_r('/in/tests/data/make/.', '/app/src/make') FileUtils.chmod 0755, '/app/src/make/configure' build = Build.new('/app/src/make', false, insource) build.run_build('make', options) assert(build.status.to_s.include?('exit 0')) FileUtils.rm_rf('/app/src/make') end def test_qmake_build Dir.chdir('/in') insource = true options = 'PREFIX += /opt/usr' Sources.new('/app/src') FileUtils.cp_r('/in/tests/data/qmake/.', '/app/src/qmake') build = Build.new('/app/src/qmake', false, insource) build.build_qmake(options, 'hello.pro') build.build_make assert(build.status.to_s.include?('exit 0')) FileUtils.rm_rf('/app/src/make') end def test_autoconf_build Dir.chdir('/in') insource = false options = '--prefix=/opt/usr' Sources.new('/app/src') FileUtils.cp_r('/in/tests/data/autoconf/.', '/app/src/autoconf') build = Build.new('/app/src/autoconf', false, insource) build.build_autoconf assert(File.exist?('/app/src/autoconf/configure'), 'Autoconf failed') build.build_configure(options) build.build_make assert(build.status.to_s.include?('exit 0')) FileUtils.rm_rf('/app/src/autoconf') end def test_custom_build Dir.chdir('/in') insource = true options = 'sh hello.sh' Sources.new('/app/src') FileUtils.cp_r('/in/tests/data/custom/.', '/app/src/custom') build = Build.new('/app/src/custom', false, insource) build.build_custom(options) assert(build.status.to_s.include?('exit 0')) FileUtils.rm_rf('/app/src/custom') end def test_apply_patch Dir.chdir('/in') insource = true options = '-DCMAKE_INSTALL_PREFIX=/opt/usr' Sources.new('/app/src') FileUtils.cp_r('/in/tests/data/cmake/.', '/app/src/cmake') - FileUtils.cp_r('/in/tests/patches/.', '/app/src/cmake/patches') + FileUtils.cp_r('/in/tests/patches/.', '/in/patches') build = Build.new('/app/src/cmake', true, insource) build.apply_patch('patches/test.patch') build.run_build('cmake', options) assert(build.status.to_s.include?('exit 0')) FileUtils.rm_rf('/app/src/cmake') end end