summary: Cross-compile Go snaps using cgo

systems: 
  - ubuntu-16.04-amd64
  - ubuntu-18.04-amd64

environment:
  SNAP_DIR: ../snaps/go-cgo

prepare: |
  #shellcheck source=tests/spread/tools/snapcraft-yaml.sh
  . "$TOOLS_DIR/snapcraft-yaml.sh"
  set_base "$SNAP_DIR/snap/snapcraft.yaml"

restore: |
  #shellcheck source=tests/spread/tools/snapcraft-yaml.sh
  . "$TOOLS_DIR/snapcraft-yaml.sh"
  cd "$SNAP_DIR"
  snapcraft clean
  rm -f ./*.snap
  restore_yaml "snap/snapcraft.yaml"

execute: |
  cd "$SNAP_DIR"

  snapcraft stage --target-arch=armhf

  if ! snap list go; then
    echo "The go snap from the Snap Store should have been installed."
    exit 1
  fi

  # This only works on ubuntu
  if dpkg -s golang-go; then
    echo "The go deb for the system repositories should not have been installed."
    exit 1
  fi

  file stage/bin/go-cgo | MATCH ',\s*ARM\s*,'
