pipeline {
    environment {
        ORG = "go"
        APP = "archiver"
        GIT_REPO_OWNER = "go"
        GIT_REPO_NAME = "archiver"
    }

    agent {
        docker {
            image 'docker.sportwanninger.de/infrastructure/golang-mingw:1.23.1'
            args  "${dindArgs()}"
        }
    }

    options {
        buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5'))
        disableConcurrentBuilds()
    }

    stages {
        stage('Build') {
            environment {
                CGO_ENABLED = "1"
                GOOS = "linux"
                CXX = "g++"
                CC = "gcc"
            }
            steps {
                ansiColor('xterm') {
                    sh "go test ./..."
                }
            }
        }
        stage('Build Win') {
            environment {
                CGO_ENABLED = "1"
                GOOS = "windows"
                CXX = "x86_64-w64-mingw32-g++"
                CC = "x86_64-w64-mingw32-gcc"
            }
            steps {
                ansiColor('xterm') {
                    sh "go test -exec wine64 -ldflags \"-extldflags '-static -fstack-protector'\" ./..."
                }
            }
        }
    }
    post {
        always {
            script {
                sendBuildMessage();
            }
        }
    }
}