# https://docs.gitea.com/next/usage/actions/quickstart
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context

name: Build Docker and Deploy
run-name: Build & Deploy ${{ gitea.ref }} on ${{ gitea.actor }}

on:
  push:
    branches:
      - '*'
      - '**'


jobs:
  run_tests:
    name: Run goext test-suite  
    runs-on: bfb-cicd-latest
    steps:

      - name: Check out code
        uses: actions/checkout@v3

      - name: Setup go
        uses: actions/setup-go@v4
        with:
          go-version-file: '${{ gitea.workspace }}/go.mod'

      - name: Setup packages
        uses: awalsh128/cache-apt-pkgs-action@latest
        with:
          packages: curl python3
          version: 1.0

      - name: go version
        run: go version

      - name: Run tests
        run: cd "${{ gitea.workspace }}" && make test

      - name: Send failure mail
        if: failure()
        uses: dawidd6/action-send-mail@v3
        with:
          server_address: smtp.fastmail.com
          server_port: 465
          secure: true
          username: ${{secrets.MAIL_USERNAME}}
          password: ${{secrets.MAIL_PASSWORD}}
          subject: Pipeline on '${{ gitea.repository }}' failed
          to: ${{ steps.commiter_info.outputs.MAIL }}
          from: Gitea Actions <gitea_actions@blackforestbytes.de>
          body: "Go to https://gogs.blackforestbytes.com/${{ gitea.repository }}/actions"