variables:
  - &platforms 'linux/arm64,linux/amd64'
  - &docker_creds
    username: 
      from_secret: hub_username_cybercinch
    password:
      from_secret: docker_password_cybercinch
  - &pypi_creds
    username: 
      from_secret: hub_username_cybercinch
    password:
      from_secret: docker_password_cybercinch
  - build_args: &build_args
      - TAG: ${CI_COMMIT_TAG}
clone:
  git:
    image: woodpeckerci/plugin-git
    settings:
      partial: false
      tags: true
   
steps:
  build-release:
    image: docker.io/cybercinch/go-semrelease:golang1.20
    pull: true
    commands:
      - > 
          GOOS=linux 
          GOARCH=amd64 
          CGO_ENABLED=0 
          GOFLAGS=-mod=vendor 
          go build -o build/go-semantic-release.linux_amd64 -ldflags "-w -s --X main.version=`go-semantic-release next`" 
          ./cmd/go-semantic-release/
      - > 
          GOOS=linux 
          GOARCH=arm64 
          CGO_ENABLED=0 
          GOFLAGS=-mod=vendor 
          go build -o build/go-semantic-release.linux_arm64 -ldflags "-w -s --X main.version=`go-semantic-release next`" 
          ./cmd/go-semantic-release/
      - >
          GOOS=windows 
          GOARCH=386 
          CGO_ENABLED=0 
          GOFLAGS=-mod=vendor 
          go build -o build/go-semantic-release.windows_i386.exe -ldflags "-w -s -X main.version=`go-semantic-release next`" 
          ./cmd/go-semantic-release/
      - >
          GOOS=windows 
          GOARCH=amd64 
          CGO_ENABLED=0 
          GOFLAGS=-mod=vendor 
          go build -o build/go-semantic-release.windows_amd64.exe -ldflags "-w -s -X main.version=`go-semantic-release next`" 
          ./cmd/go-semantic-release/
      - >
          GOOS=darwin 
          GOARCH=amd64 
          CGO_ENABLED=0 
          GOFLAGS=-mod=vendor 
          go build -o build/go-semantic-release.darwin_amd64 -ldflags "-w -s -X main.version=`go-semantic-release next`" 
          ./cmd/go-semantic-release/
      - go-semantic-release --loglevel debug release # Actually make the release on Gitea.  Uploading assets
    environment:
      GITEA_TOKEN:
        from_secret: gitea_token
      GITEA_URL:
        from_secret: gitea_server_url
    when:
      branch: ${CI_REPO_DEFAULT_BRANCH}
      event: 
        - push
        - manual

  publish-docker-tagged:
    image: woodpeckerci/plugin-docker-buildx
    pull: true
    settings:
      <<: *docker_creds
      registry: hub.cybercinch.nz
      repo: hub.cybercinch.nz/cybercinch/${CI_REPO_NAME}
      dockerfile: Dockerfile
      platforms: *platforms
      build_args:
        - TAG=${CI_COMMIT_TAG}
      tags:
        - latest
        - ${CI_COMMIT_TAG}
    when:
      branch: ${CI_REPO_DEFAULT_BRANCH}
      event: 
        - tag

  publish-docker-develop:
    image: docker.io/cybercinch/woodpecker-plugin-depot
    pull: true
    settings:
      <<: *docker_creds
      token: 
        from_secret: depot_token
      repohost: hub.cybercinch.nz
      repo: cybercinch/${CI_REPO_NAME}
      project: 
        from_secret: depot_project
      dockerfile: Dockerfile.dev
      push: true
      platforms: linux/amd64
      tags: ["develop"]
    when:
      branch: develop
      event: 
        - push
        - manual
