image: docker-registry.xx.network/elixxir/sysadmin/backend-ci:go1.17-wasm

before_script:
  - go version || echo "Go executable not found."
  - echo $CI_BUILD_REF
  - echo $CI_PROJECT_DIR
  - echo $PWD
  - eval $(ssh-agent -s)
  - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - ssh-keyscan -t rsa $GITLAB_SERVER > ~/.ssh/known_hosts
  - rm -rf ~/.gitconfig
  - git config --global url."git@$GITLAB_SERVER:".insteadOf "https://gitlab.com/"
  - git config --global url."git@$GITLAB_SERVER:".insteadOf "https://git.xx.network/" --add
  - export PATH=$HOME/go/bin:$PATH

stages:
  - wasm-test
  - go-test
  - build
  - doc-update

build:
  stage: build
  script:
    - go mod vendor -v
    - mkdir -p release
    - GOOS=js GOARCH=wasm go build -ldflags '-w -s' -o release/xxdk.wasm main.go
    - cp wasm_exec.js release/
  artifacts:
    paths:
      - release/

wasm-test:
  stage: wasm-test
  script:
    - export PATH=/root/go/bin:$PATH
    - echo > utils/utils_js.s
    - GOOS=js GOARCH=wasm go test ./... -v

go-test:
  stage: go-test
  script:
    - go mod vendor -v
    - go test ./... -v

# This pipeline job will attempt to have pkg.go.dev update docs for xxdk-wasm.
#
# pkg.go.dev relies on the proxy.golang.org service (go module cache/proxy) to discover versions of
# Go modules to make docs of. The proxy keeps a list of all known versions of Go modules. The go
# mod proxy does cache pulls for about 30 minutes, so if quickly successive commits are done in
# master/release, this will fail to pull the latest client, and the docs will not update.
doc-update:
  stage: doc-update
  image: $DOCKER_IMAGE
  script:
    # We use GOPRIVATE blank because not want to directly pull client, we want to use the public cache.
    - GOOS=js GOARCH=wasm GOPRIVATE="" go install gitlab.com/elixxir/xxdk-wasm@$CI_COMMIT_SHA
  only:
    - release
    - master
