when:
  - event: [cron]
    cron: govulncheck
  - event: [pull_request]
  - event: push
    branch:
      - ${CI_REPO_DEFAULT_BRANCH}

variables:
  - &go_image 'golang:1.22'

steps:
  govulncheck:
    image: *go_image
    pull: true
    commands:
      - make generate
      - go install golang.org/x/vuln/cmd/govulncheck@latest
      - govulncheck ./...

  notify:
    image: deblan/woodpecker-email
    settings:
      from:
        from_secret: email_from
      from.name: Woodpecker
      host:
        from_secret: email_host
      username:
        from_secret: email_username
      password:
        from_secret: email_password
      recipients:
        - notifications@dwysokinski.me
      recipients_only: true
      subject:
        "[govulncheck - {{ build.status }}] {{ repo.owner }}/{{ repo.name }}
        ({{ build.branch }} - {{ truncate build.commit 8 }})"
    when:
      status: [success, failure]
      event: cron
