kind: pipeline
type: exec
name: default

steps:
- name: build-docs
  commands:
  - make docker-build docker-build-docs
  - cp _scripts/* _build/html
  - cd _build/html && echo "drycc.cc" > CNAME  && echo "www.drycc.cc" >> CNAME && git init
  environment:
    SSH_DEPLOY_KEY:
      from_secret: ssh_deploy_key

- name: publish-docs
  commands:
  - chown -R root:root _build/html
  - docker run --rm
      -e DRONE_COMMIT_AUTHOR="$DRONE_COMMIT_AUTHOR"
      -e DRONE_COMMIT_AUTHOR_EMAIL="$DRONE_COMMIT_AUTHOR_EMAIL"
      -e PLUGIN_SSH_KEY="$SSH_DEPLOY_KEY"
      -e PLUGIN_BRANCH=main
      -e PLUGIN_REMOTE=git@github.com:drycc/www.drycc.cc.git
      -e PLUGIN_FORCE=true
      -e PLUGIN_COMMIT=true
      -e PLUGIN_PATH=_build/html
      -e PLUGIN_COMMIT_MESSAGE="init repo"
      -v "$(pwd):$(pwd)"
      -w "$(pwd)"
      appleboy/drone-git-push
  environment:
    SSH_DEPLOY_KEY:
      from_secret: ssh_deploy_key

- name: publish-charts
  commands:
  - pip install -r requirements.txt
  - python3 _scripts/dependency_update.py "$CHARTMUSEUM_API/$([ -z $DRONE_TAG ] && echo testing || echo stable)" "charts/workflow/Chart.yaml" 
  - helm package charts/workflow -u --version ${DRONE_TAG:-v1.0.0}
  - curl -u $CHARTMUSEUM_USERNAME:$CHARTMUSEUM_PASSWORD -F chart=@workflow-${DRONE_TAG:-v1.0.0}.tgz "$CHARTMUSEUM_API/api/$([ -z $DRONE_TAG ] && echo testing || echo stable)/charts"
  - bash _scripts/generate_cache.sh 
  environment:
    CHARTMUSEUM_API:
      from_secret: chartmuseum_api
    CHARTMUSEUM_USERNAME:
      from_secret: chartmuseum_username
    CHARTMUSEUM_PASSWORD:
      from_secret: chartmuseum_password

trigger:
  event:
  - push
  - tag
