pipeline {
  agent none
  stages {
    stage('Build') {
      parallel {
        stage('RHEL9') {
          agent { label 'rhel-9-x86_64' }
          stages {
            stage('autoreconf') {
              steps {
                dir("src/linux") {
                  sh 'autoreconf --force --install'
                }
              }
            }
            stage('configure') {
              steps {
                dir("src/linux") {
                  sh './configure'
                }
              }
            }
            stage('make') {
              steps {
                dir("src/linux") {
                  sh 'make'
                }
              }
            }
            stage('make dist') {
              steps {
                dir("src/linux") {
                  sh 'make dist'
                }
              }
            }
            stage('rpmbuild') {
              steps {
                dir("src/linux") {
                  sh 'rpmbuild -tb redwax-signtext-*.tar.bz2'
                }
              }
            }
          }
        }

        stage('Windows11') {
          agent { label 'windows-11-x86_64' }
          stages {
            stage('nuget') {
              steps {
                dir("src/windows/Redwax SignText") {
                  bat 'nuget restore "Redwax SignText.sln"'
                }
              }
            }
            stage('mbsuild') {
              steps {
                dir("src/windows/Redwax SignText") {
                  bat 'msbuild "Redwax SignText.sln" /p:GenerateAppxPackageOnBuild=true'
                }
              }
            }
          }
        }

        stage('MacOS') {
          agent { label 'macos' }
          stages {
            stage('unlock-keychain') {
              steps {
                unlockMacOSKeychain keychainId: 'jenkins-agent-keychain'
              }
            }
            stage('build') {
              steps {
                dir("src/macos/Redwax SignText") {
                  xcodeBuild xcodeWorkspaceFile: 'Redwax SignText.xcodeproj/project',
                             xcodeSchema: 'Redwax SignText',
                             keychainId: 'jenkins-agent-keychain'
                }
              }
            }
          }
        }

      }
    }
  }
}