steps:
  - name: build-release
    image: golang
    when:
      - event: tag
    commands:
      - GOOS=linux GOARCH=amd64 go build -o build/${CI_REPO_NAME}.linux.amd64
      - GOOS=windows GOARCH=amd64 go build -o build/${CI_REPO_NAME}.windows.amd64.exe
      - GOOS=darwin GOARCH=amd64 go build -o build/${CI_REPO_NAME}.darwin.amd64

  - name: deploy-build
    image: alpine
    when:
      - event: tag
    environment:
      GITEATKN:
        from_secret: GITEA_TOKEN
      GOTOKEN:
        from_secret: GOTIFY_TOKEN
    depends_on: build-release
    commands:
      - apk add tea
      - apk add wget
      - tea login add --name=temp --url=https://git.vertinext.com/ --token=$GITEATKN
      - tea releases create --asset "build/${CI_REPO_NAME}.linux.amd64" --asset "build/${CI_REPO_NAME}.windows.amd64.exe" --asset "build/${CI_REPO_NAME}.darwin.amd64" --tag ${CI_COMMIT_TAG} --title "Latest Compiled Release" --note "Testing GO Build CI"
      - wget "https://gotify.vertinext.com/message?token=$GOTOKEN" --post-data "title=${CI} - ${CI_REPO_NAME}&message=New release ${CI_COMMIT_TAG} built and deployed.&priority=0" -O /dev/null

  - name: notify-on-branch-push
    image: alpine
    when:
      - event: [push, pull_request, tag, release]
      - status: [success, failure]
    environment:
      GOTOKEN:
        from_secret: GOTIFY_TOKEN
    commands:
      - apk add wget
      - wget "https://gotify.vertinext.com/message?token=$GOTOKEN" --post-data "title=${CI} - ${CI_REPO_NAME}&message=New ${CI_PIPELINE_EVENT} to ${CI_REPO_NAME}/${CI_COMMIT_BRANCH}.&priority=0" -O /dev/null