1. Jenkins run reviewdog

pipeline {
    agent { label 'ec2-fleet-l' }

    stages {
        stage('Build name') {
            steps {
                script {
                    currentBuild.displayName = "${BUILD_NUMBER}: ${params.branch}".replace("origin/","")
                }
            }
        }
        stage('Checkout service') {
            steps {
                checkout([$class: 'GitSCM', branches: [[name: "${params.branch}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: "${env.repo_name}"]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${env.repo_name}", url: "[email protected]:${env.owner_name}/${env.repo_name}.git"]]])
            }
        }
        stage('Build golang-reviewdog docker') {
            steps {
                withCredentials([usernamePassword(credentialsId: 'composer-auth', usernameVariable: 'default_user', passwordVariable: 'github_oauth_token')]) {
                    sh """
                        cd ${env.repo_name}
                        GO_VERSION=\$(sed -En 's/^go //p' go.mod)
                        echo "Running Go Linter with Go version \$GO_VERSION..."
                        GIT_COMMIT=\$(git rev-parse HEAD)
                        curl -s -H "Authorization: token \$github_oauth_token" -H 'Accept: application/vnd.github.v3.raw' -O -L https://api.github.com/repos/{owner}/{repo}/contents/{path_to_file}
                        sudo docker build --build-arg GO_VERSION=\$GO_VERSION --build-arg GITHUB_TOKEN=\$github_oauth_token --build-arg REPO_NAME=${env.repo_name} --build-arg GIT_COMMIT=\$GIT_COMMIT -t golang-reviewdog .
                    """
                }
            }
        }
        stage('Lint golang') {
            steps {
                sh """
                    sudo docker run --rm golang-reviewdog
                """
            }
        }
    }
    post { 
        always { 
            dir("${env.repo_name}") {
                sh '''
                    sudo docker ps
                    sudo docker volume prune -f
                    sudo docker image prune --all -f
                '''
            }
            cleanWs()
        }
    }
}