From a67cfa15f1bcbf2672a2cb1a24288c5723a23140 Mon Sep 17 00:00:00 2001
From: Alexander Bokovoy <abokovoy@redhat.com>
Date: Apr 10 2019 14:47:03 +0000
Subject: Test with azure pipelines


Add pipeline definition that can be used to run build and test jobs in
dev.azure.com environment.

---

diff --git a/.copr/Makefile b/.copr/Makefile
index f92ac36..b0d0513 100644
--- a/.copr/Makefile
+++ b/.copr/Makefile
@@ -1,8 +1,9 @@
 VERSION != grep AC_INIT configure.ac|cut -d, -f2|tr -d ")"
 outdir=.
+SUDO=
 
 srpm:
-	dnf -y install rpm-build autoconf automake libtool \
+	$(SUDO) dnf -y install rpm-build autoconf automake libtool \
 		/usr/bin/rpcgen 389-ds-base-devel libnsl2-devel \
 		libsss_nss_idmap-devel nspr-devel nss-devel \
 		openldap-devel pam-devel ; \
diff --git a/tests/azure/README.md b/tests/azure/README.md
new file mode 100644
index 0000000..c72043d
--- /dev/null
+++ b/tests/azure/README.md
@@ -0,0 +1,27 @@
+Test with azure pipelines
+
+Add pipeline definition that can be used to run build and test jobs in
+dev.azure.com environment.
+
+Following needs to be done to use the Azure Pipelines definition for
+slapi-nis:
+
+- Configure Azure DevOps organization
+- Create public project there
+- Clone your Git repository for slapi-nis from pagure.io
+- On Azure side, navigate to Repos -> Files, choose your repo top
+  directory and click 'Clone'
+- The 'Clone Repository' dialog will show how to clone the repository
+  with HTTPS or SSH. Choose SSH tab and note the URL.
+- Set mirroring hook on Pagure's project site (Settings -> Hooks ->
+  Mirroring) by providing this URL
+- Return back to the hook settings in Pagure and copy public SSH key
+  from there
+- Choose 'Manage SSH keys' in the 'Clone Repository' dialog and add a
+  public SSH key there
+
+After these actions a push to pagure project will automatically be
+mirrored to Azure Repos repository.
+
+Now a pipeline can be set up in Azure by picking up azure-pipelines.yml
+file from the repo.
diff --git a/tests/azure/azure-pipelines.yml b/tests/azure/azure-pipelines.yml
new file mode 100644
index 0000000..a407e5a
--- /dev/null
+++ b/tests/azure/azure-pipelines.yml
@@ -0,0 +1,70 @@
+jobs:
+- job: Build
+  pool:
+    vmImage: 'Ubuntu-16.04'
+  variables:
+    builddir: /__w/1/s
+  container:
+    image: f30/fedora-toolbox
+    endpoint: fedora-project-registry
+  steps:
+    - script: |
+        sudo rm -rf /var/cache/dnf/*
+        cd $(builddir)
+        sudo dnf makecache || :
+        sudo dnf -y install dnf-plugins-core rpm-build autoconf automake libtool \
+                /usr/bin/rpcgen 389-ds-base-devel libnsl2-devel \
+                libsss_nss_idmap-devel nspr-devel nss-devel \
+                openldap-devel pam-devel gdb gcc annobin make
+        sudo dnf builddep -y --spec slapi-nis.spec --best --allowerasing --setopt=install_weak_deps=False
+      displayName: Prepare build environment
+    - script: |
+        mkdir -p $(builddir)/dist
+        make -f .copr/Makefile outdir=$(builddir)/dist SUDO=sudo srpm
+        rpmbuild --rebuild \
+                --define "_topdir $(builddir)/build" \
+                --define "_sourcedir $(builddir)/build" \
+                --define "_specdir $(builddir)/build" \
+                --define "_builddir $(builddir)/build" \
+                --define "_srcrpmdir $(builddir)/dist" \
+                --define "_rpmdir $(builddir)/dist" \
+                $(builddir)/dist/*.src.rpm
+      displayName: Build packages
+    - script: |
+        mv $(builddir)/dist/*/*.rpm $(builddir)/dist/
+        ls -la $(builddir)/dist
+      displayName: List packages
+    - task: PublishPipelineArtifact@0
+      displayName: Publish packages
+      inputs:
+        artifactName: 'packages-$(Build.BuildId)-$(Agent.OS)-$(Agent.OSArchitecture)'
+        targetPath: $(Build.Repository.LocalPath)/dist
+      condition: always()
+
+- job: Install_with_FreeIPA_packages
+  dependsOn: Build
+  condition: succeeded()
+  pool:
+    vmImage: 'Ubuntu-16.04'
+  variables:
+    builddir: /__w/1/s
+  container:
+    image: f30/fedora-toolbox
+    endpoint: fedora-project-registry
+  steps:
+    - checkout: none
+    - task: DownloadPipelineArtifact@0
+      displayName: Download pre-built packages
+      inputs:
+        artifactName: 'packages-$(Build.BuildId)-$(Agent.OS)-$(Agent.OSArchitecture)'
+        targetPath: $(Build.Repository.LocalPath)/dist
+    - script: |
+        rm -f $(builddir)/dist/*.src.rpm
+      displayName: Remove source package
+    - script: |
+        sudo rm -rf /var/cache/dnf/*
+        cd $(builddir)
+        sudo dnf makecache || :
+        sudo dnf -y install freeipa-server-dns freeipa-server $(builddir)/dist/*.rpm 
+      displayName: Attempt package installation
+

