#! /bin/sh
# upload dbc to artifactory for sharing
# assumes in bazel root directory before building and uploading as <git head SHA>.tar
# to https://artifactory.zooxlabs.com/artifactory/firmware/build-artifacts/<git head SHA>.tar
# The download link should be:
# https://artifactory.zooxlabs.com/artifactory/firmware-build/build-artifacts/<git head SHA>.tar

set -xe
cd $(bazel info workspace)

# Build the DBCs first
firmware/validation/common/ci/generate_dbc.sh

dbcs="bazel-bin/firmware/common/can/bus_dbcs"
artifactory_url="https://artifactory.zooxlabs.com/artifactory/firmware/build-artifacts/$sha.tar"

if [ -d "$dbcs" ]; then
  echo "uploading artifacts"
  # If for some reason artifactory is down, print error but continue
  tar -C bazel-bin/firmware/common/can/ -cvf /tmp/$sha.tar bus_dbcs || true

  curl -u firmware-dev:UBM52y8z7AUvQ8SLDBES -T /tmp/$sha.tar $artifactory_url || true
fi
bazel shutdown
