steps:
- name: 'gcr.io/cloud-builders/gcloud'
  id: decrypt gitkey
  args:
  - kms
  - decrypt
  - --ciphertext-file=cb_rsa.enc
  - --plaintext-file=/root/.ssh/id_rsa
  - --location=global
  - --keyring=my-keyring
  - --key=github-key
  volumes:
  - name: 'ssh'
    path: /root/.ssh
# Set up git with key and domain
- name: 'gcr.io/cloud-builders/git'
  id: setup gitkey
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    chmod 600 /root/.ssh/id_rsa
    cat <<EOF >/root/.ssh/config
    Hostname github.com
    IdentityFile /root/.ssh/id_rsa
    EOF
    cp inst/ssh/known_hosts /root/.ssh/known_hosts
    git config --global user.name "googleCloudRunner"
    git config --global user.email $_BUILD_EMAIL
  volumes:
  - name: 'ssh'
    path: /root/.ssh
- name: 'gcr.io/cloud-builders/git'
  id: clone under new git creds
  args:
  - clone
  - git@github.com:$_GITHUB_REPO
  - repo
  volumes:
  - name: 'ssh'
    path: /root/.ssh
- name: 'gcr.io/gcer-public/packagetools:master'
  id: Build website
  dir: repo
  args:
  - "Rscript"
  - "-e"
  - |
    devtools::install()
    list.files()
    pkgdown::build_site()
# Push build - remember to restrict other builds away from /docs
# otherwise it will trigger again in never ending git commit loop
- name: 'gcr.io/cloud-builders/git'
  id: push website
  dir: repo
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    git add --all && \
    git status && \
    git commit -a -m "[skip travis] Build website from commit ${COMMIT_SHA}: \
                      $(date +"%Y%m%dT%H:%M:%S")" && \
    git push git@github.com:$_GITHUB_REPO
  volumes:
  - name: 'ssh'
    path: /root/.ssh
