Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 43e078b

Browse files
am11Oleg Ginzburg
andcommitted
Add .cirrus.yml for FreeBSD (amd64, i386) CI/CD
For each pull request, it triggers a job consists of 'node.js version x architecture' matrix. When a tag is pushed, it creates a release idempotently, and publishes artifacts to the release. The versions of node.js and npm packages are selected from package management. This is because node.js official distribution does not (yet) offer FreeBSD binaries and `nvm` spends too much time compiling node.js and npm from source. `pkg` does not support installation of old version of packages with `pkg-install` command, so the `pkg-add` approach has been elected to install older node.js. For that matter, the exact version of node.js and npm packages are resolved using pattern matching. `cbsd` is used to create an i386 jail environment. Co-authored-by: Oleg Ginzburg <[email protected]>
1 parent 44366b3 commit 43e078b

File tree

5 files changed

+227
-3
lines changed

5 files changed

+227
-3
lines changed

.cirrus.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
freebsd_instance:
2+
image: freebsd-11-2-release-amd64
3+
4+
freebsd_build_task:
5+
6+
env:
7+
matrix:
8+
- node_js: "11"
9+
nodePattern: "^node-11.*V8"
10+
npmPattern: "^npm-6\\."
11+
- node_js: "10"
12+
nodePattern: "^node10-.*V8"
13+
npmPattern: "^npm-node10-"
14+
- node_js: "8"
15+
nodePattern: "^node8-.*V8"
16+
npmPattern: "^npm-node8-"
17+
- node_js: "6"
18+
nodePattern: "^node6-.*V8"
19+
npmPattern: "^npm-node6-"
20+
21+
env:
22+
matrix:
23+
- abi: freebsd:11:x86:64
24+
- abi: freebsd:11:x86:32
25+
jailName: j11i386
26+
execPrefix: cbsd jexec jname=j11i386
27+
28+
env:
29+
GH_API_TOKEN: ENCRYPTED[5e482f417304528148bb96eca8d030eacd6ab9972d482485fc4d42907283b995f658b351e0676e9493a37d815398f541]
30+
31+
prepare_script:
32+
- sed -i '' 's/quarterly/latest/g' /etc/pkg/FreeBSD.conf
33+
- |
34+
if test "$abi" = "freebsd:11:x86:32"; then
35+
./scripts/configure_freebsd_ci_jail.sh $jailName $CIRRUS_WORKING_DIR;
36+
$execPrefix sed -i -- '' 's/quarterly/latest/g' /etc/pkg/FreeBSD.conf;
37+
$execPrefix pkg update -f;
38+
$execPrefix pkg install -y python2 > /dev/null;
39+
fi
40+
- $execPrefix pkg install -y c-ares gmake icu libnghttp2 libuv git > /dev/null
41+
- $execPrefix pkg add http://pkg.freebsd.org/$abi/latest/All/$(pkg search node | grep $nodePattern | cut -d' ' -f 1).txz
42+
- $execPrefix pkg add http://pkg.freebsd.org/$abi/latest/All/$(pkg search npm | grep $npmPattern | cut -d' ' -f 1).txz
43+
- $execPrefix node --version
44+
- $execPrefix npm --version
45+
- $execPrefix clang++ --version
46+
47+
build_script:
48+
- |
49+
if test "$abi" = "freebsd:11:x86:32"; then
50+
changeDir="cd /etc/skel &&"
51+
fi
52+
echo "$changeDir npm install --unsafe-perm" | $execPrefix /bin/sh
53+
54+
publish_script:
55+
- |
56+
if test "$CIRRUS_TAG" != ""; then
57+
for file in `ls vendor/**/*.node`; do
58+
parent=${file%/*};
59+
name=${parent##*/};
60+
fullyQualifiedName="$(pwd)/$parent/${name}_binding.node";
61+
mv "$file" "$parent/${name}_binding.node";
62+
echo -e "New filename\072 $fullyQualifiedName";
63+
./scripts/upload-github-release-asset.sh github_api_token=$GH_API_TOKEN owner=am11 repo=node-sass tag=$CIRRUS_TAG filename=$fullyQualifiedName;
64+
done
65+
fi

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
- nodejs_version: 11
167167
GYP_MSVS_VERSION: 2015
168168
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
169-
169+
170170
install:
171171
- ps: Install-Product node $env:nodejs_version $env:platform
172172
- node --version

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
"eslint": "^3.4.0",
7777
"fs-extra": "^0.30.0",
7878
"istanbul": "^0.4.2",
79-
"mocha": "^3.1.2",
80-
"mocha-lcov-reporter": "^1.2.0",
79+
"mocha": "^5.2.0",
80+
"mocha-lcov-reporter": "^1.3.0",
8181
"object-merge": "^2.5.1",
8282
"read-yaml": "^1.0.0",
8383
"rimraf": "^2.5.2",

scripts/configure_freebsd_ci_jail.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/usr/bin/env sh
2+
3+
set -o xtrace
4+
5+
jailName=$1
6+
skelDirectory=$2
7+
cbsd_workdir=/usr/jails
8+
jail_arch="i386"
9+
jail_ver="11.2"
10+
11+
echo "Installing build dependencies for cbsd"
12+
pkg install -y libssh2 rsync sqlite3 git pkgconf
13+
14+
echo "Clone and setup cbsd"
15+
git clone https://github.com/cbsd/cbsd.git /usr/local/cbsd --single-branch --branch v12.0.4 --depth 1
16+
17+
cd /usr/local/etc/rc.d
18+
ln -sf /usr/local/cbsd/rc.d/cbsdd
19+
mkdir -p /usr/local/libexec/bsdconfig
20+
cd /usr/local/libexec/bsdconfig
21+
ln -s /usr/local/cbsd/share/bsdconfig/cbsd
22+
pw useradd cbsd -s /bin/sh -d ${cbsd_workdir} -c "cbsd user"
23+
24+
# determine uplink ip address
25+
# determine uplink iface
26+
auto_iface=$( /sbin/route -n get 0.0.0.0 |/usr/bin/awk '/interface/{print $2}' )
27+
my_ipv4=$( /sbin/ifconfig ${auto_iface} | /usr/bin/awk '/inet [0-9]+/{print $2}' )
28+
29+
if [ -z "${my_ipv4}" ]; then
30+
echo "IPv4 not detected"
31+
exit 1
32+
fi
33+
34+
echo "Writing '${jailName}' configuration file"
35+
cat > /tmp/${jailName}.jconf << EOF
36+
jname="${jailName}"
37+
path="${cbsd_workdir}/${jailName}"
38+
host_hostname="${jailName}.my.domain"
39+
ip4_addr="${my_ipv4}"
40+
mount_devfs="1"
41+
allow_mount="1"
42+
allow_devfs="1"
43+
allow_nullfs="1"
44+
allow_raw_sockets="1"
45+
mount_fstab="${cbsd_workdir}/jails-fstab/fstab.${jailName}"
46+
arch="${jail_arch}"
47+
mkhostsfile="1"
48+
devfs_ruleset="4"
49+
ver="${jail_ver}"
50+
basename=""
51+
baserw="0"
52+
mount_src="0"
53+
mount_obj="0"
54+
mount_kernel="0"
55+
mount_ports="1"
56+
astart="1"
57+
data="${cbsd_workdir}/jails-data/${jailName}-data"
58+
vnet="0"
59+
applytpl="1"
60+
mdsize="0"
61+
rcconf="${cbsd_workdir}/jails-rcconf/rc.conf_${jailName}"
62+
floatresolv="1"
63+
exec_poststart="0"
64+
exec_poststop=""
65+
exec_prestart="0"
66+
exec_prestop="0"
67+
exec_master_poststart="0"
68+
exec_master_poststop="0"
69+
exec_master_prestart="0"
70+
exec_master_prestop="0"
71+
pkg_bootstrap="1"
72+
interface="0"
73+
jailskeldir="$skelDirectory"
74+
exec_start="/bin/sh /etc/rc"
75+
exec_stop="/bin/sh /etc/rc.shutdown"
76+
EOF
77+
78+
echo "Initializing cbsd environment"
79+
env workdir=${cbsd_workdir} /usr/local/cbsd/sudoexec/initenv /usr/local/cbsd/share/initenv.conf
80+
81+
echo "Writing 'FreeBSD-bases' configuration file"
82+
cat > ${cbsd_workdir}/etc/FreeBSD-bases.conf << EOF
83+
auto_baseupdate=0
84+
default_obtain_base_method="extract repo"
85+
default_obtain_base_extract_source="/usr/freebsd-dist/base.txz"
86+
default_obtain_base_repo_sources="https://bintray.com/am11/freebsd-dist/download_file?file_path=base-${jail_ver}-${jail_arch}.txz"
87+
EOF
88+
89+
echo "Creating ${jailName}"
90+
cbsd jcreate jconf=/tmp/${jailName}.jconf inter=0
91+
cbsd jailscp /etc/resolv.conf ${jailName}:/etc/resolv.conf
92+
93+
cat > ~cbsd/jails-fstab/fstab.${jailName}.local <<EOF
94+
${skelDirectory} /etc/skel nullfs rw 0 0
95+
EOF
96+
97+
cbsd jstart jname=${jailName} inter=0
98+
99+
echo "${jailName} created"
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env sh
2+
#
3+
# Modified version of: https://gist.github.com/stefanbuck/ce788fee19ab6eb0b4447a85fc99f447
4+
#
5+
#
6+
# This script accepts the following parameters:
7+
#
8+
# * owner
9+
# * repo
10+
# * tag
11+
# * filename
12+
# * github_api_token
13+
#
14+
# Script to upload a release asset using the GitHub API v3.
15+
#
16+
# Example:
17+
#
18+
# upload-github-release-asset.sh github_api_token=TOKEN owner=stefanbuck repo=playground tag=v0.1.0 filename=./build.zip
19+
#
20+
21+
set -e
22+
23+
# Validate settings.
24+
[ "$TRACE" ] && set -x
25+
26+
for line in "$@"; do
27+
eval "$line"
28+
done
29+
30+
# Define variables.
31+
GH_API="https://api.github.com"
32+
GH_REPO="$GH_API/repos/$owner/$repo"
33+
GH_RELEASES="$GH_REPO/releases"
34+
GH_TAGS="$GH_RELEASES/tags/$tag"
35+
AUTH="Authorization: token $github_api_token"
36+
37+
if test "$tag" == "LATEST"; then
38+
GH_TAGS="$GH_REPO/releases/latest"
39+
fi
40+
41+
# Validate token.
42+
curl -o /dev/null -sH "$AUTH" $GH_REPO || { echo "Error: Invalid repo, token or network issue!"; exit 1; }
43+
44+
# Create a release from tag if it does not exist.
45+
curl -s -d "{\"tag_name\":\"$tag\"}" -H "$AUTH" "$GH_RELEASES" > /dev/null
46+
47+
# Read asset tags.
48+
response=$(curl -sH "$AUTH" $GH_TAGS)
49+
50+
# Get ID of the asset based on given filename.
51+
eval "$(echo "$response" | grep -m 1 "id.:" | grep -w id | tr : = | tr -cd '[[:alnum:]]=')"
52+
[ -n "$id" ] || { echo "Error: Failed to get release id for tag: $tag"; echo "$response" | awk 'length($0)<100' >&2; exit 1; }
53+
54+
# Upload asset
55+
echo "Uploading asset... "
56+
57+
# Construct url
58+
GH_ASSET="https://uploads.github.com/repos/$owner/$repo/releases/$id/assets?name=$(basename $filename)"
59+
60+
curl "$GITHUB_OAUTH_BASIC" --data-binary @"$filename" -H "$AUTH" -H "Content-Type: application/octet-stream" $GH_ASSET

0 commit comments

Comments
 (0)