Skip to content

Commit dd1036a

Browse files
committed
Update CI tooling
1 parent 15b8fe3 commit dd1036a

14 files changed

+275
-32
lines changed

.gitlab-ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
image: docker:latest
2+
services:
3+
- docker:dind
4+
cache:
5+
key: ${CI_COMMIT_REF_SLUG}
6+
paths:
7+
- /usr/portage
8+
- /var/portage
9+
- /var/lib/docker
10+
11+
build-ebuilds:
12+
script:
13+
- ./.tools/bin/ci-run-mr

.tools/bin/ci-mkdockercmds

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#! /usr/bin/env sh
2+
3+
set -e
4+
5+
export PATH=$PATH:$(pwd)/.tools/bin
6+
export DEBIAN_FRONTEND=noninteractive
7+
8+
hash -r
9+
10+
{
11+
# We need git for consecutive commands
12+
apt update -qq
13+
apt install -qqy git
14+
15+
# Make sure the latest `master` is also available to diff against
16+
git fetch -a origin
17+
git checkout master
18+
git pull origin master
19+
git checkout -
20+
} > /dev/null
21+
22+
# Generate the testing commands
23+
updated-ebuilds | ebuild2atom | make-docker-commands --root="$1"

.tools/bin/ci-run-mr

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! /usr/bin/env sh
2+
3+
set -e
4+
5+
main()
6+
{
7+
cmds=$(mktemp)
8+
9+
mkdir -p /usr/portage
10+
mkdir -p /var/portage
11+
12+
# Sync latest portage tree
13+
do_cmd docker run -v /usr/portage:/usr/portage gentoo/stage3-amd64 emerge -q --sync
14+
15+
# Run the script to generate the testing commands
16+
do_cmd docker run -w /app -v "$(pwd):/app" rakudo-star sh .tools/bin/ci-mkdockercmds "$(pwd)" > "$cmds"
17+
18+
# Run the testing commands
19+
while read -r cmd
20+
do
21+
do_cmd $cmd
22+
done < "$cmds"
23+
}
24+
25+
do_cmd()
26+
{
27+
printf "> %s\n" "$*" >&2
28+
$@
29+
}
30+
31+
main "$@"

.tools/bin/ebuild2atom

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#! /usr/bin/env perl6
2+
3+
#| Convert a path to an ebuild into an atom that can be passed to emerge.
4+
sub MAIN (*@ebuilds)
5+
{
6+
@ebuilds = $*IN.lines unless @ebuilds;
7+
8+
for @ebuilds {
9+
my $category = $_.split("/").head;
10+
my $package = $_.split("/").tail.IO.extension("").Str;
11+
12+
say "=$category/$package"
13+
}
14+
}

.tools/bin/make-docker-commands

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#! /usr/bin/env perl6
2+
3+
#| Build packages
4+
sub MAIN (
5+
#| Host's path to the Portage tree.
6+
Str:D :$tree = "/usr/portage",
7+
8+
#| Host's path to Portage's var dir. This holds binpkgs and distfiles.
9+
Str:D :$var = "/var/portage",
10+
11+
#| Host's path to the root of the overlay.
12+
Str:D :$root is copy = "",
13+
14+
#| A list of packages to build
15+
*@packages,
16+
) {
17+
@packages = $*IN.lines unless @packages;
18+
$root = shell("git rev-parse --show-toplevel", :out).out.slurp.trim unless $root;
19+
20+
build-pkg($_, :$tree, :$var, root => $root.IO) for @packages;
21+
}
22+
23+
#| Build a given package in a clean Docker container
24+
sub build-pkg (
25+
#| The name of the package to build
26+
Str:D $package,
27+
28+
#| Host's path to the Portage tree.
29+
Str:D :$tree = "/usr/portage",
30+
31+
#| Host's path to Portage's var dir. This holds binpkgs and distfiles.
32+
Str:D :$var = "/var/portage",
33+
34+
#| Path to overlay's root
35+
IO::Path:D :$root,
36+
) {
37+
my Pair @volumes = (
38+
$tree => "/usr/portage",
39+
$var => "/var/portage",
40+
$root.add(".tools").add("etc").absolute => "/etc/portage",
41+
$root.absolute => "/app",
42+
);
43+
44+
my Str @cmd = <
45+
docker
46+
run
47+
>;
48+
49+
for @volumes {
50+
@cmd.push: "-v $_.key():$_.value()";
51+
}
52+
53+
@cmd.push: "gentoo/stage3-amd64";
54+
@cmd.push: "emerge";
55+
@cmd.push: $package;
56+
57+
@cmd.join(" ").say;
58+
}

.tools/bin/mkcommit

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#! /usr/bin/env perl6
2+
3+
sub MAIN (
4+
*@words,
5+
) {
6+
my @ebuilds = (run « git diff --name-status master », :out).out.lines.grep(*.ends-with(".ebuild"));
7+
8+
if (@ebuilds.elems != 1) {
9+
exit note q:to/EOF/;
10+
Committed ebuilds does not equal to 1. Each commit should only
11+
contain a single ebuild update.
12+
EOF
13+
}
14+
15+
my $ebuild = @ebuilds.head.split("\t").tail.split("/").head(2).join("/");
16+
17+
run « git commit -S -m "$ebuild: @words.join(" ")" »;
18+
}

.tools/bin/updated-ebuilds

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#! /usr/bin/env perl6
2+
3+
#| Get a list of all changed package atoms.
4+
sub MAIN ()
5+
{
6+
(run « git diff --name-status master », :out).out.lines
7+
.grep(*.ends-with(".ebuild"))
8+
.map(*.split("\t").tail)
9+
.map(*.say)
10+
;
11+
}

.tools/etc/make.conf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
COMMON_FLAGS="-O2 -pipe"
2+
CFLAGS="${COMMON_FLAGS}"
3+
CXXFLAGS="${COMMON_FLAGS}"
4+
FCFLAGS="${COMMON_FLAGS}"
5+
FFLAGS="${COMMON_FLAGS}"
6+
7+
FEATURES="
8+
$FEATURES
9+
buildpkg
10+
network-sandbox
11+
parallel-fetch
12+
parallel-install
13+
sandbox
14+
userfetch
15+
userpriv
16+
usersandbox
17+
usersync
18+
"
19+
20+
EMERGE_DEFAULT_OPTS="
21+
$EMERGE_DEFAULT_OPTS
22+
--binpkg-respect-use=y
23+
--binpkg-changed-deps=y
24+
--tree
25+
--usepkg
26+
--verbose
27+
"
28+
29+
PKGDIR=/var/portage/packages
30+
DISTDIR=/var/portage/distfiles
31+
32+
LC_MESSAGES=C
33+
L10N="en"

.tools/etc/make.profile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../usr/portage/profiles/default/linux/amd64/17.0/desktop

.tools/etc/package.accept_keywords

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/*::sk-overlay ~*

.tools/etc/repo.postsync.d/example

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
# Example /etc/portage/repo.postsync.d script. Make it executable (chmod +x) for
3+
# Portage to process it.
4+
#
5+
# With portage-2.2.16 and newer, all repo.postsync.d hooks will be called multiple
6+
# times after syncing each repository.
7+
#
8+
# Older versions of Portage support syncing only one repository.
9+
# In those versions, the postsync.d hooks will be called only once,
10+
# and they will not be passed any parameters.
11+
12+
# On a repo.postsync.d hook call, positional parameters contain
13+
# information about the just-synced repository.
14+
15+
# Your hook can control it's actions depending on any of the three
16+
# parameters passed in to it.
17+
#
18+
# They are as follows:
19+
#
20+
# The repository name.
21+
repository_name=${1}
22+
# The URI to which the repository was synced.
23+
sync_uri=${2}
24+
# The path to the repository.
25+
repository_path=${3}
26+
27+
# Portage assumes that a hook succeeded if it exits with 0 code. If no
28+
# explicit exit is done, the exit code is the exit code of last spawned
29+
# command. Since our script is a bit more complex, we want to control
30+
# the exit code explicitly.
31+
ret=0
32+
33+
if [ -n "${repository_name}" ]; then
34+
# Repository name was provided, so we're in a post-repository hook.
35+
echo "* In post-repository hook for ${repository_name}"
36+
echo "** synced from remote repository ${sync_uri}"
37+
echo "** synced into ${repository_path}"
38+
39+
# Gentoo comes with pregenerated cache but the other repositories
40+
# usually don't. Generate them to improve performance.
41+
if [ "${repository_name}" != "gentoo" ]; then
42+
if ! egencache --update --repo="${repository_name}" --jobs=4
43+
then
44+
echo "!!! egencache failed!"
45+
ret=1
46+
fi
47+
fi
48+
fi
49+
50+
# Return explicit status.
51+
exit "${ret}"

.tools/etc/repo.postsync.d/q-reinit

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
repository_name=$1
4+
repository_path=$3
5+
6+
if [ -n "${repository_name}" ]; then
7+
q ${PORTAGE_QUIET:+-q} --reinitialize="${repository_path}"
8+
fi
9+
10+
:

.tools/etc/repos.conf/sk-overlay.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[sk-overlay]
2+
priority = 50
3+
location = /app
4+
layman-type = git
5+
auto-sync = No

.travis.yml

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
1-
#
2-
# Run repoman via travis
3-
# See https://github.com/mrueg/repoman-travis
4-
#
5-
language: python
6-
python:
7-
- pypy
8-
env:
9-
- PORTAGE_VER="2.3.51"
10-
before_install:
11-
- sudo apt-get -qq update
12-
- pip install lxml pyyaml
13-
before_script:
14-
- sudo chmod a+rwX /etc/passwd /etc/group /etc /usr
15-
- mkdir -p travis-overlay /etc/portage /usr/portage/distfiles
16-
- mv !(travis-overlay) travis-overlay/
17-
- mv .git travis-overlay/
18-
- wget "https://raw.githubusercontent.com/mrueg/repoman-travis/master/.travis.yml" -O .travis.yml.upstream
19-
- wget "https://raw.githubusercontent.com/mrueg/repoman-travis/master/spinner.sh"
20-
- wget -qO - "https://github.com/gentoo/portage/archive/portage-${PORTAGE_VER}.tar.gz" | tar xz
21-
- wget -qO - "https://github.com/gentoo-mirror/gentoo/archive/master.tar.gz" | tar xz -C /usr/portage --strip-components=1
22-
- chmod a+rwx spinner.sh
23-
- echo "portage:x:250:250:portage:/var/tmp/portage:/bin/false" >> /etc/passwd
24-
- echo "portage::250:portage,travis" >> /etc/group
25-
- wget "https://www.gentoo.org/dtd/metadata.dtd" -O /usr/portage/distfiles/metadata.dtd
26-
- ln -s $TRAVIS_BUILD_DIR/portage-portage-${PORTAGE_VER}/cnf/repos.conf /etc/portage/repos.conf
27-
- ln -s /usr/portage/profiles/default/linux/amd64/17.0 /etc/portage/make.profile
28-
- SIZE=$(stat -c %s .travis.yml.upstream)
29-
- 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
30-
- cd travis-overlay
1+
sudo: required
2+
language: generic
3+
services:
4+
- docker
5+
316
script:
32-
- ./../spinner.sh "python ../portage-portage-${PORTAGE_VER}/repoman/bin/repoman full -d"
33-
# You can append own scripts after this line
7+
- ./.tools/bin/ci-run-mr

0 commit comments

Comments
 (0)