#!/bin/bash # This is to serve as a Plugin for Woodpecker to enable running of builds on depot.dev set -eo pipefail shopt -s nullglob # check to see if this file is being run or sourced from another script _is_sourced() { # https://unix.stackexchange.com/a/215279 [ "${#FUNCNAME[@]}" -ge 2 ] \ && [ "${FUNCNAME[0]}" = '_is_sourced' ] \ && [ "${FUNCNAME[1]}" = 'source' ] } # logging functions drone_log() { local type="$1"; shift # accept argument string or stdin local text="$*"; if [ "$#" -eq 0 ]; then text="$(cat)"; fi local dt; dt="$(date -D 'YYYY-MM-DD hh:mm[:ss]')" printf '%s [%s] [woodpecker-depot]: %s\n' "$dt" "$type" "$text" } woodpecker_note() { drone_log Note "$@" } woodpecker_warn() { drone_log Warn "$@" >&2 } woodpecker_error() { drone_log ERROR "$@" >&2 exit 1 } # Verify that the minimally required password settings are set for operation. function verify_minimum_env { if [ -z "$PLUGIN_PROJECT" ]; then woodpecker_warn "token setting is required for plugin operation" fi if [ -z "$PLUGIN_TOKEN" ]; then woodpecker_warn "token setting is required for plugin operation" fi if [ -z "$PLUGIN_REPO" ]; then woodpecker_warn "repo setting is required for plugin operation" fi if [ -z "$PLUGIN_TAG" ]; then woodpecker_warn "tag setting is required for plugin operation" fi if [ -z "$PLUGIN_REPOHOST" ]; then woodpecker_warn "repohost setting is required for plugin operation" fi if [ -z "$PLUGIN_PLATFORMS" ]; then woodpecker_warn "platforms setting is required for plugin operation" fi if [ "${PLUGIN_REPOHOST}" == "docker.io" ] then if [ -z "$PLUGIN_USERNAME" ] || [ -z "$PLUGIN_PASSWORD" ] then woodpecker_warn "username and password are required for plugin operation" fi fi if [ -z "$PLUGIN_PROJECT" ] || [ -z "$PLUGIN_TOKEN" ] || [ -z "$PLUGIN_REPO" ] || [ -z "$PLUGIN_TAGS" ] || [ -z "$PLUGIN_REPOHOST" ] || [ -z "$PLUGIN_PLATFORMS" ] ; then woodpecker_error <<-'EOF' You need to specify one/all of the following settings: - token - project - repo - tag - repohost - platforms - username - password EOF fi woodpecker_note "Sufficient configuration" } function parse_tags { # set (,) as delimiter IFS=',' read -ra TAGS_ARRAY <<< "$PLUGIN_TAGS" TAGS_LENGTH=${#TAGS_ARRAY[@]} for (( i=0; i/dev/null ) woodpecker_note "${LOGON}" woodpecker_note "Building and pushing with Depot..." # Build and push with depot #parse_tags # Build the Commandline parameters build_cli DEPOT_TOKEN=${PLUGIN_TOKEN} depot build "${options[@]}" woodpecker_note "Build completed" fi } _main() { woodpecker_note "Starting" verify_minimum_env "$@" woodpecker_note "$@" woodpecker_note "Depot version is: $(depot --version)" build_on_depot "$@" } # If we are sourced from elsewhere, don't perform any further actions if ! _is_sourced; then _main "$@" fi