
    REGISTRY=${REGISTRY:-docker.pkg.github.com}
    USERNAME=${USERNAME:-kennethreitz}

//: //system //python
//system:
    lazy_brew pipenv
//python: @skip:key=Pipfile.lock //system
    pipenv install --dev

test: docker/build
    docker-compose run --entrypoint bash bake -c 'set -ex && pip3 install pytest && pytest'
release: test release//warn @confirm:secure release//pypi release//docker
bash: docker//bash

release//warn:
    echo
    echo "$(bake:red 'Warning'): you are about to release a new version of $(bake:red 'bake' --fg green)."
    echo
    echo 'Please do this simple math problem to prove this is not accidental.'
    echo
docker/build:
    # Build the images.
    set -ex && docker-compose build

docker//bash: @interactive docker/build
    docker-compose run --entrypoint bash bake

docker//build/full:
    # Build the images.
    set -ex && docker-compose build --no-cache

release//pypi: @interactive //python
    pipenv run python setup.py upload

release//docker: docker/build release//docker/github

release//docker/github: docker/build
    set -ux

    declare -a IMAGES=('bake:core' 'bake:latest')

    for IMAGE in "${IMAGES[@]}"; do
        REMOTE_IMAGE="$REGISTRY/$USERNAME/bake/$IMAGE"

        # Tag the images for GitHub Registry.
        docker tag "$USERNAME/$IMAGE" "$REMOTE_IMAGE"

        # Push the images to GitHub.
        docker push "$REMOTE_IMAGE"
    done

release/docker/dockerhub: docker/build
    docker-compose push

//ci: //ci/setup
    set -ex && mkdir -p reports/pytest && pytest --junitxml=reports/pytest/report.xml

//ci/setup: @skip:key=Pipfile.lock
    pipenv install --dev --deploy --system

random/python/ip:
    #!/usr/bin/env python
    import requests
    r = requests.get('https://httpbin.org/ip')
    print(r.json()['origin'].split(',')[0])

cli:
    bake:red 'Testing sub–commands.'
    bake:step 'sub-task'
    echo 'I should *not* be red.' | bake:red | bake:indent | bake:notred
    echo 'I *should* be red.' | bake:red --always | bake:indent
    echo "$(echo test $(bake:red test) test | bake:indent)"
    echo

//kr:
    sparkescakesparkles="✨ 🍰 ✨" | pbcopy
    echo "$sparkescakesparkles" | pbcopy
    echo 'KR Copied!' | bake:red --fg cyan

lazy_brew() {
    set -e
    # Install jq if it's not available.

    if ! which jq > /dev/null; then
        set -ex && brew install jq
    fi

    # Install requested packages, if they aren't installed.
    for PACKAGE in "$@"; do
        if ! brew info --installed --json | jq 'map(.name) | index( "$PACKAGE" )' > /dev/null; then
            set -ex && brew install "$PACKAGE" > /dev/null
        fi
    done
}
