kind: pipeline
name: default

workspace:
  base: /go
  path: src/gitbase.de/apairon/mark2web

steps:
  - name: build for linux
    image: golang:latest
    environment:
      CGO_ENABLED: 0
      GOOS: linux
      GOARCH: amd64
    commands:
      - git submodule update --init --recursive
      - git fetch --tags
      - ./build.sh
    when:
      event: [ push, tag ]

  - name: test with example content
    image: alpine
    commands:
      - ./dist/mark2web-`cat VERSION`-linux-amd64 -version
      - ./dist/mark2web-`cat VERSION`-linux-amd64 -in example -out example_out -create -logLevel debug
    when:
      event: [ push, tag ]

  - name: build for freebsd
    image: golang:latest
    environment:
      CGO_ENABLED: 0
      GOOS: freebsd
      GOARCH: amd64
    commands:
      - ./build.sh
    when:
      event: [ tag ]

  - name: build for macos
    image: golang:latest
    environment:
      CGO_ENABLED: 0
      GOOS: darwin
      GOARCH: amd64
    commands:
      - ./build.sh
    when:
      event: [ tag ]

  - name: build for windows
    image: golang:latest
    environment:
      CGO_ENABLED: 0
      GOOS: windows
      GOARCH: amd64
      FILEEXT: .exe
    commands:
      - ./build.sh
    when:
      event: [ tag ]

  - name: build docker image
    image: docker
    commands:
      - cp dist/mark2web-`cat VERSION`-linux-amd64 mark2web
      - docker build -t apairon/mark2web .
    volumes:
      - name: docker
        path: /var/run/docker.sock
    when:
      branch: [ master ]
      event: [ push ]

  - name: deploy website
    image: apairon/mark2web:latest
    pull: never
    environment:
      RSYNC_PASS:
        from_secret: rsync_pass    
    commands:
      - /mark2web -version
      - /mark2web -in website -out html -create -logLevel debug
      - '
        rsync -rlcgD -i -u -v --stats --progress
          --delete
          -e "sshpass -p $${RSYNC_PASS} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 22222"
          html/
          basiskonfiguration_mark2web_rsync@deploy.bc1.basehosts.de:./'
    when:
      branch: [ master ]
      event: [ promote, push ]
      target: [ website ]

  - name: prepare release
    image: apairon/mark2web:latest
    pull: never
    commands:
      - gzip dist/*
      - ls -la dist/
    when:
      event: [ tag ]

  - name: gitea release
    image: plugins/gitea-release
    settings:
      api_key:
        from_secret: gitea_token
      base_url: https://gitbase.de
      files:
        - dist/*
      title: VERSION
      note: RELEASE.md
      checksum:
        - md5
        - sha256
    when:
      event: [ tag ]

volumes:
  - name: docker
    host:
      path: /var/run/docker.sock