Skip to content

Commit

Permalink
Support multiple distro CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Medeiros committed Jan 20, 2020
1 parent ae24f73 commit acc6c01
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 54 deletions.
77 changes: 77 additions & 0 deletions .github/scripts/setup_instance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

set -euxo pipefail

DISKS="gcloud compute disks"
IMAGES="gcloud compute images"
INSTANCES="gcloud compute instances"
VMX="https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
DEFAULT_ZONE=us-central1-a

function createDisk() {
# Create disk
#
# $1: disk name
# $2: image project
# $3: image-family
# $4: zone
zone=${4:-$DEFAULT_ZONE}

diskName=$1
${DISKS} create $diskName \
--image-project $2 \
--image-family $3 \
--size 20GB \
--zone $zone
}

function createImage() {
# Create image with nested virtualization
#
# $1: image name
# $2: disk name
# $3: zone
zone=${3:-$DEFAULT_ZONE}

imageName=$1
${IMAGES} create $imageName \
--source-disk $2 \
--source-disk-zone $zone \
--licenses "${VMX}"
}

function createVM() {
# Create VM with nested virtualization
#
# $1: VM name
# $2: image name
# $3: zone
zone=${3:-$DEFAULT_ZONE}

instanceName=$1
${INSTANCES} create $1 \
--zone $zone \
--min-cpu-platform "Intel Haswell" \
--image $2
}

# Entrypoint
#
# $1: vm name
# $2: image project
# $3: image family
# $4: zone
vmName=$1
imageProject=$2
imageFamily=$3
zone=${4:-$DEFAULT_ZONE}

# create disk
createDisk $vmName $imageProject $imageFamily $zone

# create image
imageName=$vmName-image
createImage $imageName $vmName $zone

# create vm
createVM $1 $imageName $zone
97 changes: 97 additions & 0 deletions .github/scripts/setup_wok.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

set -euxo pipefail


function get_deps() {
echo $(python3 -c "import yaml;print(' '.join(yaml.load(open('dependencies.yaml'), Loader=yaml.FullLoader)[\"$1\"][\"$2\"]))")
}

function install_PyYAML() {
pip3 install PyYAML==5.2
}

function install_python_deps() {
pip3 install -r requirements-dev.txt
pip3 install -r requirements-CI.txt
}

function build(){
# autogen and make
./autogen.sh --system
make
}

function setup_ubuntu(){
# install pyyaml and its dependencies
sudo apt update
sudo apt install -y python3-setuptools python3-dev python3-pip
install_PyYAML

# install deps
sudo apt install -y $(get_deps development-deps common)
sudo apt install -y $(get_deps development-deps ubuntu)
sudo apt install -y $(get_deps runtime-deps common)
sudo apt install -y $(get_deps runtime-deps ubuntu | sed 's/python3-cheetah//')

# install python deps and build
install_python_deps
build
}

function setup_debian(){
# install pyyaml and its dependencies
sudo apt update
sudo apt install -y python3-setuptools python3-dev python3-pip
install_PyYAML

# install deps
sudo apt install -y $(get_deps development-deps common)
sudo apt install -y $(get_deps development-deps debian)
sudo apt install -y $(get_deps runtime-deps common)
sudo apt install -y $(get_deps runtime-deps debian)

# install python deps and build
install_python_deps
build
}

function setup_fedora(){
# install pyyaml and its dependencies
sudo dnf update
sudo dnf install -y python3-setuptools python3-devel python3-pip
install_PyYAML

# install deps
sudo dnf install -y $(get_deps development-deps common)
sudo dnf install -y $(get_deps development-deps fedora)
sudo dnf install -y $(get_deps runtime-deps common)
sudo dnf install -y $(get_deps runtime-deps fedora)

# install python deps and build
install_python_deps
build
}

function setup_opensuse(){
# install pyyaml and its dependencies
sudo zypper update
sudo zypper install -y python3-setuptools python3-dev python3-pip
install_PyYAML

# install deps
sudo zypper install -y $(get_deps development-deps common)
sudo zypper install -y $(get_deps development-deps opensuse-leap)
sudo zypper install -y $(get_deps runtime-deps common)
sudo zypper install -y $(get_deps runtime-deps opensuse-leap)

# install python deps and build
install_python_deps
build
}

if [ $# -eq 0 ]; then
echo "No distro specified. Pick one: ubuntu, debian, fedora or opensuse-leap"
fi

setup_$1
29 changes: 0 additions & 29 deletions .github/scripts/setup_wok_ubuntu.sh

This file was deleted.

68 changes: 68 additions & 0 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: wok-build-test
on: ["push"]

jobs:
ubuntu:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v1

- name: setup deps and make
run: |
bash .github/scripts/setup_wok.sh ubuntu
shell: bash

- name: run tests
working-directory: ./tests
run: |
sudo make check-local
sudo make check
shell: bash

debian:
env:
VM_NAME: debian-${{ github.sha }}
ZONE: us-central1-a
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
WOK_DIR: wok

runs-on: ubuntu-latest
steps:

- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '270.0.0'
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
- run: gcloud config set project $PROJECT_ID

- uses: actions/checkout@v2-beta

- name: create instance
run: bash .github/scripts/setup_instance.sh $VM_NAME debian-cloud debian-10
shell: bash

- name: checkout repos
run: |
gcloud compute ssh $VM_NAME --zone=$ZONE --command "sudo apt update -y; sudo apt install git -y"
gcloud compute ssh $VM_NAME --zone=$ZONE --command "git clone https://github.com/$GITHUB_REPOSITORY"
gcloud compute ssh $VM_NAME --zone=$ZONE --command "cd $WOK_DIR; git checkout $GITHUB_SHA"
shell: bash

- name: setup wok deps
run: |
gcloud compute ssh $VM_NAME --zone=$ZONE --command "cd $WOK_DIR; bash .github/scripts/setup_wok.sh debian"
shell: bash

- name: run tests
run: gcloud compute ssh $VM_NAME --zone=$ZONE --command "cd $WOK_DIR; sudo make check-local; sudo make check"
shell: bash

- name: Cleanup instance
if: always()
run: |
gcloud compute instances delete ${VM_NAME} --delete-disks=all --zone=$ZONE -q || true
gcloud compute images delete ${VM_NAME}-image -q || true
gcloud compute disks delete ${VM_NAME}-disk --zone=$ZONE -q || true
shell: bash
25 changes: 0 additions & 25 deletions .github/workflows/CI.yml

This file was deleted.

0 comments on commit acc6c01

Please sign in to comment.