distributable:
  url: https://mirror.openshift.com/pub/openshift-v{{version.major}}/clients/ocp/{{version}}/openshift-client-src.tar.gz
  strip-components: 1

versions:
  url: https://mirror.openshift.com/pub/openshift-v4/clients/ocp/
  match: />\d+\.\d+\.\d+</
  strip: [/</, />/]

dependencies:
  kerberos.org: ^1.21

build:
  dependencies:
    go.dev: ^1.21
    linux:
      gnu.org/gcc: '*' # aarch64 wants `ld.gold`
  script:
    # linux builds like to segfault without -buildmode=pie
    - run: sed -i 's/GO_LD_EXTRAFLAGS :=/GO_LD_EXTRAFLAGS :=-buildmode=pie /' Makefile
      if: linux

    - make $ARGS
    - install -D _output/bin/{{hw.platform}}_${ARCH}/oc {{prefix}}/bin/oc
  env:
    # Without declaring ARCH, cross-build-{{hw.platform}}-${ARCH} will execute like cross-build-{{hw.platform}}-
    ARCH:
    x86-64:
      ARCH: amd64
    aarch64:
      ARCH: arm64
    ARGS:
      - cross-build-{{hw.platform}}-${ARCH}
      - OS_GIT_VERSION={{version}}
    linux:
      ARGS:
        # https://github.com/openshift/oc/issues/562
        - SHELL=/bin/bash

provides:
  - bin/oc

test:
  script:
    - touch ./kubeconfig
    - oc version --client --output=json | grep {{version}}
    - oc config set-context foo 2>&1 | grep 'created'
    - oc config get-contexts -o name | grep 'foo'
    - cat kubeconfig | grep 'foo'
  env:
    KUBECONFIG: $PWD/kubeconfig
