Jack Lloyd-Walters has proposed merging 
~maas-committers/maas-ci/+git/maas-ci-internal:openapi-github-duplicator into 
~maas-committers/maas-ci/+git/maas-ci-internal:main.

Commit message:
add MAAS OpenApi schema duplicator job

Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~maas-committers/maas-ci/+git/maas-ci-internal/+merge/438449
-- 
Your team MAAS Committers is requested to review the proposed merge of 
~maas-committers/maas-ci/+git/maas-ci-internal:openapi-github-duplicator into 
~maas-committers/maas-ci/+git/maas-ci-internal:main.
diff --git a/jobs/maas-openapi-duplicator.groovy b/jobs/maas-openapi-duplicator.groovy
new file mode 100644
index 0000000..3b665c5
--- /dev/null
+++ b/jobs/maas-openapi-duplicator.groovy
@@ -0,0 +1,82 @@
+pipeline {
+    agent {
+        docker {
+            image 'ubuntu:{{ series }}'
+            registryUrl '{{ docker_registry }}'
+            registryCredentialsId '{{ docker_registry_cred }}'
+            label 'maas-tester'
+            args '-u 0:0'
+            reuseNode true
+        }
+    }
+
+    stages {
+        stage('Prepare') {
+            steps {
+                cleanWs()
+                sh '''
+                if [ ! -z \$http_proxy ]; then
+                    echo "Acquire::http::proxy \\"\$http_proxy\\"\\;" > /etc/apt/apt.conf.d/launchpad-ci-proxy
+                    echo "Acquire::https::proxy \\"\$http_proxy\\"\\;" >> /etc/apt/apt.conf.d/launchpad-ci-proxy
+                  fi
+
+                export DEBIAN_FRONTEND=noninteractive
+                apt update
+                apt install -y devscripts tox python3-pip
+                '''
+            }
+        }
+        stage('Lint Schema') {
+            steps {
+                withCredentials([file(credentialsId: 'lp-lander-sshkey', variable: 'SSHKEY')]) {
+                    withEnv(["GIT_SSH_COMMAND=ssh -i $SSHKEY -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null"]) {
+                        lock(resource: "maas-${LP_BRANCH}") {
+                            sh '''
+                            mkdir -p /run/build
+                            cd /run/build
+                            git clone --depth 1 --single-branch --branch ${LP_BRANCH} git+ssh://maas-lan...@git.launchpad.net/${LP_REPO} maas
+                            cd maas
+                            make lint-oapi
+                         '''
+                        }
+                    }
+                }
+            }
+        }
+        stage('Push Schema') {
+            steps {
+                def schema = readFile(file: "openapi.yaml")
+                    withCredentials([
+                        string(credentialsId: 'jenkins-maas-token', variable: '{{ api_token_env_var }}'),
+                        sshUserPrivateKey(credentialsId: 'maas-lander-ssh-key', keyFileVariable: 'SSHKEY', usernameVariable: 'SSHUSER')
+                    ]) {
+                        script {
+                            sh "git clone {{ GH_REPO }} oapi_folder"
+                            dir("oapi_folder") {
+                                def schema_updated = !fileExists("{{ GH_FILE_LOC }}") || schema != readFile(file: {{ GH_FILE_LOC }}) 
+                                if (schema_updated) {
+                                    writeFile(file: "{{ GH_FILE_LOC }}", text: schema)
+                                    sh """
+                                    git add {{ GH_FILE_LOC }}
+                                    git commit -m "updating openapi schema"
+                                    git push
+                                    """
+                                }
+                            }
+                            sh "rm -rf oapi_folder"
+                        }
+                    }
+            }
+        }
+    }
+    post {
+        success {
+            if (schema_updated) {
+                mattermostSend (color: 'green', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}](${env.BUILD_URL}) :success: updated OpenAPI Schema")
+            }
+        }
+        failure {
+            mattermostSend (color: 'red', message: "[${env.JOB_NAME} #${env.BUILD_NUMBER}](${env.BUILD_URL}) :fire: failed to update OpenAPI Schema")
+        }
+    }
+}
\ No newline at end of file
diff --git a/jobs/maas-openapi-duplicator.yaml b/jobs/maas-openapi-duplicator.yaml
new file mode 100644
index 0000000..99ed66c
--- /dev/null
+++ b/jobs/maas-openapi-duplicator.yaml
@@ -0,0 +1,30 @@
+- project:
+    name: update-openapi-schema
+    jobs:
+      - update-openapi-schema
+
+- job-template:
+    name: update-openapi-schema
+    triggers:
+      - timed: '@daily'
+    parameters:
+        - string:
+            name: LP_REPO
+            description: 'Target git repository'
+            default: '~maas-committers/maas'
+        - string:
+            name: LP_BRANCH
+            description: 'Target git branch'
+            default: 'master'
+        - string:
+            name: GH_REPO
+            description: 'GitHub repository to push schema to'
+            default: 'https://github.com/maas/maas-openapi-yaml'
+        - string:
+            name: GH_FILE_LOC
+            description: 'Location of file in GitHub repo to push schema to'
+            default: 'openapi.yaml'
+    properties:
+      - build-discarder:
+          artifact-num-to-keep: 10
+    dsl: !include-jinja2: update-openapi-schema.groovy
\ No newline at end of file
-- 
Mailing list: https://launchpad.net/~sts-sponsors
Post to     : sts-sponsors@lists.launchpad.net
Unsubscribe : https://launchpad.net/~sts-sponsors
More help   : https://help.launchpad.net/ListHelp

Reply via email to