Skip to content

A peer-to-peer stack for code collaboration

Google Cloud Build

Tomás Senartfa56876d2409
diff --git a/cloudbuild.yaml b/cloudbuild.yaml
new file mode 100644
index 0000000..22ca6bb
--- /dev/null
+++ b/cloudbuild.yaml
@@ -0,0 +1,46 @@
+timeout: 1800s # Cache misses are slow to rebuild
+steps:
+ - id: "Load cache"
+ name: gcr.io/cloud-builders/gsutil
+ entrypoint: 'bash'
+ args:
+ - '-c'
+ - |
+ source scripts/ci.sh
+ load-cache
+
+ - id: "Build deps"
+ name: 'haskell:8.4.3'
+ env: ['STACK_ROOT=/workspace/.stack']
+ entrypoint: 'bash'
+ args:
+ - '-c'
+ - |
+ stack config set system-ghc --global true
+ stack config set install-ghc --global false
+ stack install stylish-haskell hlint
+
+ - id: "Format"
+ name: 'haskell:8.4.3'
+ env: ['STACK_ROOT=/workspace/.stack']
+ args: ['./scripts/check-fmt.sh']
+
+ - id: "Lint"
+ name: 'haskell:8.4.3'
+ env: ['STACK_ROOT=/workspace/.stack']
+ args: ['stack', 'exec', '--', 'hlint', '.']
+
+ - id: "Test & Build"
+ name: 'haskell:8.4.3'
+ env: ['STACK_ROOT=/workspace/.stack']
+ args: ['stack', 'build', '--fast', '--test', '--no-terminal', '--pedantic']
+
+ - id: "Save cache"
+ name: gcr.io/cloud-builders/gsutil
+ entrypoint: 'bash'
+ args:
+ - '-c'
+ - |
+ source scripts/ci.sh
+ save-cache
+
diff --git a/scripts/check-fmt.sh b/scripts/check-fmt.sh
new file mode 100755
index 0000000..da37cdf
--- /dev/null
+++ b/scripts/check-fmt.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+shopt -s globstar
+
+base=$(mktemp -d "/tmp/oscoin-base.XXXXX")
+for f in **/**.hs; do
+ path=$base/$(dirname $f)
+ mkdir -p $path
+ cp $f $path
+done
+
+formatted=$(mktemp -d "/tmp/oscoin-formatted.XXXXX")
+cp -R $base/* $formatted
+
+stack exec -- stylish-haskell $formatted/**/**.hs --inplace
+
+diff -rq $base $formatted
diff --git a/scripts/ci.sh b/scripts/ci.sh
new file mode 100755
index 0000000..6d4529c
--- /dev/null
+++ b/scripts/ci.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+set -euo pipefail
+
+function load-cache() {
+ bucket="gs://radicle-build-cache"
+ key="stack-work-$(cat stack.yaml | sha256sum | cut -d ' ' -f 1)".tar.gz
+ gsutil -m cp -r "$bucket/v1/*" "$bucket/$key" . || true
+ for f in stack.tar.gz $key; do
+ if [[ -e $f ]]; then
+ tar xzf $f
+ fi
+ done
+}
+
+function save-cache() {
+ bucket="gs://radicle-build-cache"
+ key="stack-work-$(cat stack.yaml | sha256sum | cut -d ' ' -f 1)".tar.gz
+ if ! gsutil ls "$bucket/$key"; then
+ tar czf $key .stack-work
+ gsutil -m cp $key "$bucket/$key" || true
+ fi
+
+ rm -rf .stack/indices/Hackage/00-index.tar*
+ tar czf stack.tar.gz .stack
+
+ if ! sha256sum --check stack.tar.gz.sha256; then
+ sha256sum stack.tar.gz >stack.tar.gz.sha256
+ gsutil -m cp stack.tar.gz* "$bucket/v1/" || true
+ fi
+}