From 870088401ebb3efbabdf3a7535298bed065a1e41 Mon Sep 17 00:00:00 2001
From: Patrick Spek
Date: Wed, 21 Nov 2018 22:27:22 +0100
Subject: [PATCH] Add Gitlab CI
---
.gitlab-ci.yml | 23 +++++++++++
.tools/bin/build | 58 +++++++++++++++++++++++++++
.tools/bin/ebuild2atom | 14 +++++++
.tools/bin/mkcommit | 18 +++++++++
.tools/bin/updated-ebuilds | 11 +++++
.tools/etc/make.conf | 33 +++++++++++++++
.tools/etc/make.profile | 1 +
.tools/etc/package.accept_keywords | 1 +
.tools/etc/repo.postsync.d/example | 51 +++++++++++++++++++++++
.tools/etc/repo.postsync.d/q-reinit | 10 +++++
.tools/etc/repos.conf/sk-overlay.conf | 6 +++
.travis.yml | 44 ++++++--------------
12 files changed, 239 insertions(+), 31 deletions(-)
create mode 100644 .gitlab-ci.yml
create mode 100755 .tools/bin/build
create mode 100755 .tools/bin/ebuild2atom
create mode 100755 .tools/bin/mkcommit
create mode 100755 .tools/bin/updated-ebuilds
create mode 100644 .tools/etc/make.conf
create mode 120000 .tools/etc/make.profile
create mode 100644 .tools/etc/package.accept_keywords
create mode 100644 .tools/etc/repo.postsync.d/example
create mode 100755 .tools/etc/repo.postsync.d/q-reinit
create mode 100644 .tools/etc/repos.conf/sk-overlay.conf
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..a43b45d
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,23 @@
+image: ubuntu:latest
+services:
+ - docker:dind
+cache:
+ key: ${CI_COMMIT_REF_SLUG}
+ paths:
+ - /usr/portage
+ - /var/portage
+before_script:
+ - DEBIAN_FRONTEND=noninteractive apt update -qy
+ - DEBIAN_FRONTEND=noninteractive apt install -y docker.io git perl6
+ - git fetch -a origin
+ - git checkout master && git pull origin master && git checkout -
+
+build-ebuilds:
+ script:
+ - groups
+ - ls -lah /etc/init.d
+ - /etc/init.d/docker start
+ - sleep 10
+ - /etc/init.d/docker status
+ - docker ps
+ - ./.tools/bin/updated-ebuilds | ./.tools/bin/ebuild2atom | ./.tools/bin/build
diff --git a/.tools/bin/build b/.tools/bin/build
new file mode 100755
index 0000000..a952cd5
--- /dev/null
+++ b/.tools/bin/build
@@ -0,0 +1,58 @@
+#! /usr/bin/env perl6
+
+#| Build packages
+sub MAIN (
+ #| Host's path to the Portage tree.
+ Str:D :$tree = "/usr/portage",
+
+ #| Host's path to Portage's var dir. This holds binpkgs and distfiles.
+ Str:D :$var = "/var/portage",
+
+ #| A list of packages to build
+ *@packages,
+) {
+ @packages = $*IN.lines unless @packages;
+
+ my $root = shell("git rev-parse --show-toplevel", :out).out.slurp.trim.IO;
+
+ build-pkg($_, :$tree, :$var, :$root) for @packages;
+}
+
+#| Build a given package in a clean Docker container
+sub build-pkg (
+ #| The name of the package to build
+ Str:D $package,
+
+ #| Host's path to the Portage tree.
+ Str:D :$tree = "/usr/portage",
+
+ #| Host's path to Portage's var dir. This holds binpkgs and distfiles.
+ Str:D :$var = "/var/portage",
+
+ #| Path to overlay's root
+ IO::Path:D :$root,
+) {
+ my Pair @volumes = (
+ $tree => "/usr/portage",
+ $var => "/var/portage",
+ $root.add(".tools").add("etc").absolute => "/etc/portage",
+ $root.absolute => "/opt/scriptkitties/overlay",
+ );
+
+ my Str @cmd = <
+ docker
+ run
+ -it
+ >;
+
+ for @volumes {
+ @cmd.push: "-v $_.key():$_.value()";
+ }
+
+ @cmd.push: "gentoo/stage3-amd64";
+ @cmd.push: "emerge";
+ @cmd.push: $package;
+
+ @cmd.join(" ").say;
+ run @cmd;
+}
diff --git a/.tools/bin/ebuild2atom b/.tools/bin/ebuild2atom
new file mode 100755
index 0000000..e229653
--- /dev/null
+++ b/.tools/bin/ebuild2atom
@@ -0,0 +1,14 @@
+#! /usr/bin/env perl6
+
+#| Convert a path to an ebuild into an atom that can be passed to emerge.
+sub MAIN (*@ebuilds)
+{
+ @ebuilds = $*IN.lines unless @ebuilds;
+
+ for @ebuilds {
+ my $category = $_.split("/").head;
+ my $package = $_.split("/").tail.IO.extension("").Str;
+
+ say "=$category/$package"
+ }
+}
diff --git a/.tools/bin/mkcommit b/.tools/bin/mkcommit
new file mode 100755
index 0000000..fecb44b
--- /dev/null
+++ b/.tools/bin/mkcommit
@@ -0,0 +1,18 @@
+#! /usr/bin/env perl6
+
+sub MAIN (
+ *@words,
+) {
+ my @ebuilds = (run « git diff --name-status master », :out).out.lines.grep(*.ends-with(".ebuild"));
+
+ if (@ebuilds.elems != 1) {
+ exit note q:to/EOF/;
+ Committed ebuilds does not equal to 1. Each commit should only
+ contain a single ebuild update.
+ EOF
+ }
+
+ my $ebuild = @ebuilds.head.split("\t").tail.split("/").head(2).join("/");
+
+ run « git commit -S -m "$ebuild: @words.join(" ")" »;
+}
diff --git a/.tools/bin/updated-ebuilds b/.tools/bin/updated-ebuilds
new file mode 100755
index 0000000..71196c0
--- /dev/null
+++ b/.tools/bin/updated-ebuilds
@@ -0,0 +1,11 @@
+#! /usr/bin/env perl6
+
+#| Get a list of all changed package atoms.
+sub MAIN ()
+{
+ (run « git diff --name-status master », :out).out.lines
+ .grep(*.ends-with(".ebuild"))
+ .map(*.split("\t").tail)
+ .map(*.say)
+ ;
+}
diff --git a/.tools/etc/make.conf b/.tools/etc/make.conf
new file mode 100644
index 0000000..7c2bd21
--- /dev/null
+++ b/.tools/etc/make.conf
@@ -0,0 +1,33 @@
+COMMON_FLAGS="-O2 -pipe"
+CFLAGS="${COMMON_FLAGS}"
+CXXFLAGS="${COMMON_FLAGS}"
+FCFLAGS="${COMMON_FLAGS}"
+FFLAGS="${COMMON_FLAGS}"
+
+FEATURES="
+ $FEATURES
+ buildpkg
+ network-sandbox
+ parallel-fetch
+ parallel-install
+ sandbox
+ userfetch
+ userpriv
+ usersandbox
+ usersync
+"
+
+EMERGE_DEFAULT_OPTS="
+ $EMERGE_DEFAULT_OPTS
+ --bindpkg-respect-use=y
+ --binpkg-changed-deps=y
+ --tree
+ --usepkg
+ --verbose
+"
+
+PKGDIR=/var/portage/packages
+DISTDIR=/var/portage/distfiles
+
+LC_MESSAGES=C
+L10N="en"
diff --git a/.tools/etc/make.profile b/.tools/etc/make.profile
new file mode 120000
index 0000000..7026aa3
--- /dev/null
+++ b/.tools/etc/make.profile
@@ -0,0 +1 @@
+../../usr/portage/profiles/default/linux/amd64/17.0/desktop
\ No newline at end of file
diff --git a/.tools/etc/package.accept_keywords b/.tools/etc/package.accept_keywords
new file mode 100644
index 0000000..781677a
--- /dev/null
+++ b/.tools/etc/package.accept_keywords
@@ -0,0 +1 @@
+*/*::sk-overlay ~*
diff --git a/.tools/etc/repo.postsync.d/example b/.tools/etc/repo.postsync.d/example
new file mode 100644
index 0000000..533bf71
--- /dev/null
+++ b/.tools/etc/repo.postsync.d/example
@@ -0,0 +1,51 @@
+#!/bin/sh
+# Example /etc/portage/repo.postsync.d script. Make it executable (chmod +x) for
+# Portage to process it.
+#
+# With portage-2.2.16 and newer, all repo.postsync.d hooks will be called multiple
+# times after syncing each repository.
+#
+# Older versions of Portage support syncing only one repository.
+# In those versions, the postsync.d hooks will be called only once,
+# and they will not be passed any parameters.
+
+# On a repo.postsync.d hook call, positional parameters contain
+# information about the just-synced repository.
+
+# Your hook can control it's actions depending on any of the three
+# parameters passed in to it.
+#
+# They are as follows:
+#
+# The repository name.
+repository_name=${1}
+# The URI to which the repository was synced.
+sync_uri=${2}
+# The path to the repository.
+repository_path=${3}
+
+# Portage assumes that a hook succeeded if it exits with 0 code. If no
+# explicit exit is done, the exit code is the exit code of last spawned
+# command. Since our script is a bit more complex, we want to control
+# the exit code explicitly.
+ret=0
+
+if [ -n "${repository_name}" ]; then
+ # Repository name was provided, so we're in a post-repository hook.
+ echo "* In post-repository hook for ${repository_name}"
+ echo "** synced from remote repository ${sync_uri}"
+ echo "** synced into ${repository_path}"
+
+ # Gentoo comes with pregenerated cache but the other repositories
+ # usually don't. Generate them to improve performance.
+ if [ "${repository_name}" != "gentoo" ]; then
+ if ! egencache --update --repo="${repository_name}" --jobs=4
+ then
+ echo "!!! egencache failed!"
+ ret=1
+ fi
+ fi
+fi
+
+# Return explicit status.
+exit "${ret}"
diff --git a/.tools/etc/repo.postsync.d/q-reinit b/.tools/etc/repo.postsync.d/q-reinit
new file mode 100755
index 0000000..0833c66
--- /dev/null
+++ b/.tools/etc/repo.postsync.d/q-reinit
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+repository_name=$1
+repository_path=$3
+
+if [ -n "${repository_name}" ]; then
+ q ${PORTAGE_QUIET:+-q} --reinitialize="${repository_path}"
+fi
+
+:
diff --git a/.tools/etc/repos.conf/sk-overlay.conf b/.tools/etc/repos.conf/sk-overlay.conf
new file mode 100644
index 0000000..f3ee9d8
--- /dev/null
+++ b/.tools/etc/repos.conf/sk-overlay.conf
@@ -0,0 +1,6 @@
+[sk-overlay]
+priority = 50
+location = /opt/scriptkitties/overlay
+layman-type = git
+auto-sync = No
+
diff --git a/.travis.yml b/.travis.yml
index d0918ae..fb5a7af 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,33 +1,15 @@
-#
-# Run repoman via travis
-# See https://github.com/mrueg/repoman-travis
-#
-language: python
-python:
- - pypy
-env:
- - PORTAGE_VER="2.3.51"
+sudo: required
+language: generic
+services:
+ - docker
+
before_install:
- - sudo apt-get -qq update
- - pip install lxml pyyaml
-before_script:
- - sudo chmod a+rwX /etc/passwd /etc/group /etc /usr
- - mkdir -p travis-overlay /etc/portage /usr/portage/distfiles
- - mv !(travis-overlay) travis-overlay/
- - mv .git travis-overlay/
- - wget "https://raw.githubusercontent.com/mrueg/repoman-travis/master/.travis.yml" -O .travis.yml.upstream
- - wget "https://raw.githubusercontent.com/mrueg/repoman-travis/master/spinner.sh"
- - wget -qO - "https://github.com/gentoo/portage/archive/portage-${PORTAGE_VER}.tar.gz" | tar xz
- - wget -qO - "https://github.com/gentoo-mirror/gentoo/archive/master.tar.gz" | tar xz -C /usr/portage --strip-components=1
- - chmod a+rwx spinner.sh
- - echo "portage:x:250:250:portage:/var/tmp/portage:/bin/false" >> /etc/passwd
- - echo "portage::250:portage,travis" >> /etc/group
- - wget "https://www.gentoo.org/dtd/metadata.dtd" -O /usr/portage/distfiles/metadata.dtd
- - ln -s $TRAVIS_BUILD_DIR/portage-portage-${PORTAGE_VER}/cnf/repos.conf /etc/portage/repos.conf
- - ln -s /usr/portage/profiles/default/linux/amd64/17.0 /etc/portage/make.profile
- - SIZE=$(stat -c %s .travis.yml.upstream)
- - if ! cmp -n $SIZE -s .travis.yml .travis.yml.upstream; then echo -e "\e[31m !!! .travis.yml outdated! Update available https://github.com/mrueg/repoman-travis \e[0m" > /tmp/update ; fi
- - cd travis-overlay
+ - DEBIAN_FRONTEND=noninteractive sudo apt-get update -qy
+ - DEBIAN_FRONTEND=noninteractive sudo apt-get install -y git perl6
+ - git fetch -a origin
+ - git checkout master && git pull origin master && git checkout -
+
script:
- - ./../spinner.sh "python ../portage-portage-${PORTAGE_VER}/repoman/bin/repoman full -d"
-# You can append own scripts after this line
+ - groups
+ - docker ps
+ - ./.tools/bin/updated-ebuilds | ./.tools/bin/ebuild2atom | ./.tools/bin/build