diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 00000000..cea99809
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,54 @@
+name: "Code scanning - action"
+
+on:
+ push:
+ branches: ["v31"]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: ["v31"]
+ schedule:
+ - cron: '0 19 * * 1'
+
+jobs:
+ CodeQL-Build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ with:
+ # We must fetch at least the immediate parents so that if this is
+ # a pull request then we can checkout the head.
+ fetch-depth: 2
+
+ # If this run was triggered by a pull request event, then checkout
+ # the head of the pull request instead of the merge commit.
+ - run: git checkout HEAD^2
+ if: ${{ github.event_name == 'pull_request' }}
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v3
+ # Override language selection by uncommenting this and choosing your languages
+ with:
+ languages: java
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v3
+
+ # âšī¸ Command-line programs to run using the OS shell.
+ # đ https://git.io/JvXDl
+
+ # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v3
diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml
new file mode 100644
index 00000000..f67f5a42
--- /dev/null
+++ b/.github/workflows/dependency-review.yml
@@ -0,0 +1,16 @@
+name: 'Dependency Review'
+on: [pull_request]
+
+permissions:
+ contents: read
+
+jobs:
+ dependency-review:
+ runs-on: ubuntu-latest
+ steps:
+ - name: 'Checkout Repository'
+ uses: actions/checkout@v4
+ - name: Dependency Review
+ uses: actions/dependency-review-action@v3
+ with:
+ fail-on-severity: high
diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml
new file mode 100644
index 00000000..f99f7245
--- /dev/null
+++ b/.github/workflows/deploy-docker.yml
@@ -0,0 +1,134 @@
+name: Deploy Docker
+
+on:
+ workflow_dispatch:
+ branches: ["v31"]
+ inputs:
+ tag:
+ description: tag/version to deploy
+ required: true
+jobs:
+ deploy:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: deploy docker
+ run: |
+ SC_RELEASE_TAG="${{ env.TAG }}"
+ echo "$SC_RELEASE_TAG"
+
+ TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}"
+ RANCHER_HOST="rancher.tools.swagger.io"
+ CLUSTER_ID="c-n8zp2"
+ NAMESPACE_NAME="swagger-oss"
+ K8S_OBJECT_TYPE="daemonsets"
+ K8S_OBJECT_NAME="swagger-petstore-31"
+ DEPLOY_IMAGE="swaggerapi/petstore31:$SC_RELEASE_TAG"
+
+ workloadStatus=""
+ getStatus() {
+ echo "Getting update status..."
+ if ! workloadStatus="$(curl -s -X GET \
+ -H "Authorization: Bearer ${TOKEN}" \
+ -H 'Content-Type: application/json' \
+ "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")"
+ then
+ echo 'ERROR - get status k8s API call failed!'
+ echo "Exiting build"...
+ exit 1
+ fi
+ }
+
+ # $1 = image to deploy
+ updateObject() {
+ local image="${1}"
+ echo "Updating image value..."
+
+ if ! curl -s -X PATCH \
+ -H "Authorization: Bearer ${TOKEN}" \
+ -H 'Content-Type: application/json-patch+json' \
+ "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \
+ -d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}]"
+ then
+ echo 'ERROR - image update k8s API call failed!'
+ echo "Exiting build..."
+ exit 1
+ fi
+ }
+
+
+ # Check that the TAG is valid
+ if [[ $SC_RELEASE_TAG =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
+ echo ""
+ echo "This is a Valid TAG..."
+
+ # Get current image/tag in case we need to rollback
+ getStatus
+ ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')"
+ echo ""
+ echo "Current image: ${ROLLBACK_IMAGE}"
+
+ # Update image and validate response
+ echo ""
+ updateObject "${DEPLOY_IMAGE}"
+ echo ""
+
+ echo ""
+ echo "Waiting for pods to start..."
+ echo ""
+ sleep 60s
+
+ # Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error
+ getStatus
+ status="$(echo "${workloadStatus}" | jq '.status')"
+ echo ""
+ echo "${status}"
+ echo ""
+
+ numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
+ numberReady="$(echo "${status}" | jq -r '.numberReady')"
+
+ if (( numberReady == numberDesired )); then
+ echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}"
+
+ # If pods are not starting, rollback the upgrade and exit the build with error
+ else
+ echo "state = error...rolling back upgrade"
+ updateObject "${ROLLBACK_IMAGE}"
+ echo ""
+
+ echo ""
+ echo "Waiting for rollback pods to start..."
+ echo ""
+ sleep 60s
+
+ getStatus
+ status="$(echo "${workloadStatus}" | jq '.status')"
+ echo ""
+ echo "${status}"
+ echo ""
+
+ numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
+ numberReady="$(echo "${status}" | jq -r '.numberReady')"
+
+ if (( numberReady == numberDesired )); then
+ echo "Rollback to ${ROLLBACK_IMAGE} completed."
+ else
+ echo "FATAL - rollback failed"
+ fi
+ echo "Exiting Build..."
+ exit 1
+ fi
+
+ else
+ echo "This TAG is not in a valid format..."
+ echo "Exiting Build..."
+ exit 0
+ fi
+ echo "Exiting Build..."
+ exit 0
+ env:
+ ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ TAG: ${{ github.event.inputs.tag }}
diff --git a/.github/workflows/dockerhub-release.yaml b/.github/workflows/dockerhub-release.yaml
new file mode 100644
index 00000000..ba70583a
--- /dev/null
+++ b/.github/workflows/dockerhub-release.yaml
@@ -0,0 +1,61 @@
+name: Docker Release
+
+on:
+ workflow_dispatch:
+ branches: ["v31"]
+ inputs:
+ tag:
+ description: tag/version to release
+ required: true
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Python 3.10
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.10'
+ - name: Set up Java 11
+ uses: actions/setup-java@v1
+ with:
+ java-version: 11
+ - name: Run pre release script
+ id: preRelease
+ run: |
+ # export GPG_TTY=$(tty)
+ export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+ if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
+ then
+ echo "not releasing snapshot version: " ${MY_POM_VERSION}
+ echo "RELEASE_OK=no" >> $GITHUB_ENV
+ else
+ . ./CI/pre-release.sh
+ echo "RELEASE_OK=yes" >> $GITHUB_ENV
+ fi
+ echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
+ echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
+ echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV
+ - name: docker login
+ run: |
+ docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }}
+ set -e
+ - name: Build generator image and push
+ if: env.RELEASE_OK == 'yes'
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ push: true
+ platforms: linux/amd64
+ provenance: false
+ tags: swaggerapi/petstore31:${{ env.TAG }}
+ env:
+ ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ SC_VERSION:
+ SC_NEXT_VERSION:
+ TAG: ${{ github.event.inputs.tag }}
+
diff --git a/.github/workflows/maven-pulls.yml b/.github/workflows/maven-pulls.yml
new file mode 100644
index 00000000..248ab120
--- /dev/null
+++ b/.github/workflows/maven-pulls.yml
@@ -0,0 +1,30 @@
+name: Build Test PR
+
+on:
+ pull_request:
+ branches: ["v31"]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ java: [ 11 ]
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Java
+ uses: actions/setup-java@v1
+ with:
+ java-version: ${{ matrix.java }}
+ - name: Cache local Maven repository
+ uses: actions/cache@v2
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Build with Maven
+ run: |
+ mvn --no-transfer-progress -B install --file pom.xml
\ No newline at end of file
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
new file mode 100644
index 00000000..3f40ba0d
--- /dev/null
+++ b/.github/workflows/maven.yml
@@ -0,0 +1,36 @@
+name: Build Test master
+
+on:
+ push:
+ branches: ["v31"]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ java: [ 11 ]
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up Java
+ uses: actions/setup-java@v1
+ with:
+ java-version: ${{ matrix.java }}
+ server-id: ossrh
+ server-username: MAVEN_USERNAME
+ server-password: MAVEN_PASSWORD
+ - name: Cache local Maven repository
+ uses: actions/cache@v2
+ with:
+ path: ~/.m2/repository
+ key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
+ restore-keys: |
+ ${{ runner.os }}-maven-
+ - name: Build with Maven
+ run: |
+ mvn --no-transfer-progress -B install --file pom.xml
+ env:
+ MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
+ MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
\ No newline at end of file
diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml
new file mode 100644
index 00000000..17d48d67
--- /dev/null
+++ b/.github/workflows/prepare-release.yml
@@ -0,0 +1,54 @@
+name: Prepare Release
+
+on:
+ workflow_dispatch:
+ branches: ["v31"]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - uses: tibdex/github-app-token@v1
+ id: generate-token
+ with:
+ app_id: ${{ secrets.APP_ID }}
+ private_key: ${{ secrets.APP_PRIVATE_KEY }}
+ - name: Set up Python 3.10
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.10'
+ - name: Set up Java 11
+ uses: actions/setup-java@v1
+ with:
+ java-version: 11
+ - name: Run prepare release script
+ id: prepare-release
+ run: |
+ export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+ if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
+ then
+ . ./CI/prepare-release.sh
+ echo "PREPARE_RELEASE_OK=yes" >> $GITHUB_ENV
+ else
+ echo "not preparing release for release version: " ${MY_POM_VERSION}
+ echo "PREPARE_RELEASE_OK=no" >> $GITHUB_ENV
+ fi
+ echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
+ echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
+ - name: Create Prepare Release Pull Request
+ uses: peter-evans/create-pull-request@v4
+ if: env.PREPARE_RELEASE_OK == 'yes'
+ with:
+ token: ${{ steps.generate-token.outputs.token }}
+ commit-message: prepare release ${{ env.SC_VERSION }}
+ title: 'prepare release ${{ env.SC_VERSION }}'
+ branch: prepare-release-${{ env.SC_VERSION }}
+ env:
+ ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ SC_VERSION:
+ SC_NEXT_VERSION:
+
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
new file mode 100644
index 00000000..ec993c1c
--- /dev/null
+++ b/.github/workflows/release.yml
@@ -0,0 +1,190 @@
+name: Release
+
+on:
+ workflow_dispatch:
+ branches: ["v31"]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - uses: tibdex/github-app-token@v1
+ id: generate-token
+ with:
+ app_id: ${{ secrets.APP_ID }}
+ private_key: ${{ secrets.APP_PRIVATE_KEY }}
+ - name: Set up Python 3.10
+ uses: actions/setup-python@v4
+ with:
+ python-version: '3.10'
+ - name: Set up Java 11
+ uses: actions/setup-java@v1
+ with:
+ java-version: 11
+ - name: Run pre release script
+ id: preRelease
+ run: |
+ # export GPG_TTY=$(tty)
+ export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+ if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
+ then
+ echo "not releasing snapshot version: " ${MY_POM_VERSION}
+ echo "RELEASE_OK=no" >> $GITHUB_ENV
+ else
+ . ./CI/pre-release.sh
+ echo "RELEASE_OK=yes" >> $GITHUB_ENV
+ fi
+ echo "SC_VERSION=$SC_VERSION" >> $GITHUB_ENV
+ echo "SC_NEXT_VERSION=$SC_NEXT_VERSION" >> $GITHUB_ENV
+ echo "SC_LAST_RELEASE=$SC_LAST_RELEASE" >> $GITHUB_ENV
+ - name: configure git user email
+ run: |
+ git config --global user.email "action@github.com"
+ git config --global user.name "GitHub Action"
+ git config --global hub.protocol https
+ git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:x-oauth-basic@github.com/swagger-api/swagger-petstore.git
+ - name: docker login
+ run: |
+ docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }}
+ set -e
+ - name: Docker build and push
+ id: docker_build_push
+ if: env.RELEASE_OK == 'yes'
+ run: |
+ . ./CI/docker-release.sh
+ - name: Run post release script
+ id: postRelease
+ if: env.RELEASE_OK == 'yes'
+ run: |
+ . ./CI/post-release.sh
+ - name: Create Next Snapshot Pull Request
+ uses: peter-evans/create-pull-request@v4
+ if: env.RELEASE_OK == 'yes'
+ with:
+ token: ${{ steps.generate-token.outputs.token }}
+ commit-message: bump snapshot ${{ env.SC_NEXT_VERSION }}-SNAPSHOT
+ title: 'bump snapshot ${{ env.SC_NEXT_VERSION }}-SNAPSHOT'
+ branch: bump-snap-${{ env.SC_NEXT_VERSION }}-SNAPSHOT
+ - name: deploy docker
+ run: |
+ SC_RELEASE_TAG="${{ env.SC_VERSION }}"
+ echo "$SC_RELEASE_TAG"
+
+ TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}"
+ RANCHER_HOST="rancher.tools.swagger.io"
+ CLUSTER_ID="c-n8zp2"
+ NAMESPACE_NAME="swagger-oss"
+ K8S_OBJECT_TYPE="daemonsets"
+ K8S_OBJECT_NAME="swagger-petstore-31"
+ DEPLOY_IMAGE="swaggerapi/petstore31:$SC_RELEASE_TAG"
+
+ workloadStatus=""
+ getStatus() {
+ echo "Getting update status..."
+ if ! workloadStatus="$(curl -s -X GET \
+ -H "Authorization: Bearer ${TOKEN}" \
+ -H 'Content-Type: application/json' \
+ "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")"
+ then
+ echo 'ERROR - get status k8s API call failed!'
+ echo "Exiting build"...
+ exit 1
+ fi
+ }
+
+ # $1 = image to deploy
+ updateObject() {
+ local image="${1}"
+ echo "Updating image value..."
+
+ if ! curl -s -X PATCH \
+ -H "Authorization: Bearer ${TOKEN}" \
+ -H 'Content-Type: application/json-patch+json' \
+ "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \
+ -d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}]"
+ then
+ echo 'ERROR - image update k8s API call failed!'
+ echo "Exiting build..."
+ exit 1
+ fi
+ }
+
+
+ # Check that the TAG is valid
+ if [[ $SC_RELEASE_TAG =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
+ echo ""
+ echo "This is a Valid TAG..."
+
+ # Get current image/tag in case we need to rollback
+ getStatus
+ ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')"
+ echo ""
+ echo "Current image: ${ROLLBACK_IMAGE}"
+
+ # Update image and validate response
+ echo ""
+ updateObject "${DEPLOY_IMAGE}"
+ echo ""
+
+ echo ""
+ echo "Waiting for pods to start..."
+ echo ""
+ sleep 60s
+
+ # Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error
+ getStatus
+ status="$(echo "${workloadStatus}" | jq '.status')"
+ echo ""
+ echo "${status}"
+ echo ""
+
+ numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
+ numberReady="$(echo "${status}" | jq -r '.numberReady')"
+
+ if (( numberReady == numberDesired )); then
+ echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}"
+
+ # If pods are not starting, rollback the upgrade and exit the build with error
+ else
+ echo "state = error...rolling back upgrade"
+ updateObject "${ROLLBACK_IMAGE}"
+ echo ""
+
+ echo ""
+ echo "Waiting for rollback pods to start..."
+ echo ""
+ sleep 60s
+
+ getStatus
+ status="$(echo "${workloadStatus}" | jq '.status')"
+ echo ""
+ echo "${status}"
+ echo ""
+
+ numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
+ numberReady="$(echo "${status}" | jq -r '.numberReady')"
+
+ if (( numberReady == numberDesired )); then
+ echo "Rollback to ${ROLLBACK_IMAGE} completed."
+ else
+ echo "FATAL - rollback failed"
+ fi
+ echo "Exiting Build..."
+ exit 1
+ fi
+
+ else
+ echo "This TAG is not in a valid format..."
+ echo "Exiting Build..."
+ exit 0
+ fi
+ echo "Exiting Build..."
+ exit 0
+ env:
+ ACTIONS_ALLOW_UNSECURE_COMMANDS: true
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ SC_VERSION:
+ SC_NEXT_VERSION:
diff --git a/.gitignore b/.gitignore
index 313c82f0..62050086 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,5 @@ target
atlassian-ide-plugin.xml
*.iml
.java-version
+dependency-reduced-pom.xml
+*.pyc
\ No newline at end of file
diff --git a/CI/docker-release.sh b/CI/docker-release.sh
new file mode 100755
index 00000000..0cbf0212
--- /dev/null
+++ b/CI/docker-release.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+CUR=$(pwd)
+
+SC_RELEASE_TAG="$SC_VERSION"
+
+echo "docker tag:"
+echo "$SC_RELEASE_TAG"
+
+export DOCKER_PETSTORE_IMAGE_NAME=swaggerapi/petstore31
+docker build --rm=false -t $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG .
+docker tag $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG $DOCKER_PETSTORE_IMAGE_NAME:latest
+docker push $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG
+docker push $DOCKER_PETSTORE_IMAGE_NAME:latest
+echo "docker images:"
+docker images | grep -i petstore31
diff --git a/CI/ghApiClient.py b/CI/ghApiClient.py
new file mode 100755
index 00000000..fcec1eac
--- /dev/null
+++ b/CI/ghApiClient.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+import os
+import time
+import urllib.request, urllib.error, urllib.parse
+import http.client
+import json
+
+GH_BASE_URL = "https://api.github.com/"
+
+GH_TOKEN = os.environ['GH_TOKEN']
+GH_AUTH = "Bearer %s" % GH_TOKEN
+
+def readUrl(name):
+ try:
+ request = urllib.request.Request(GH_BASE_URL + name)
+ request.add_header("Authorization", GH_AUTH)
+ content = urllib.request.urlopen(request).read()
+ jcont = json.loads(content)
+ return jcont
+ except urllib.error.HTTPError as e:
+ print(('HTTPError = ' + str(e.code)))
+ raise e
+ except urllib.error.URLError as e:
+ print(('URLError = ' + str(e.reason)))
+ raise e
+ except http.client.HTTPException as e:
+ print(('HTTPException = ' + str(e)))
+ raise e
+ except Exception:
+ import traceback
+ print(('generic exception: ' + traceback.format_exc()))
+ raise IOError
+
+def postUrl(name, body):
+ global GH_BASE_URL
+ try:
+ time.sleep(0.05)
+ request = urllib.request.Request(GH_BASE_URL + name)
+ request.add_header("Authorization", GH_AUTH)
+ request.add_header("Accept", "application/vnd.github.v3+json")
+ data = body.encode('utf-8')
+ content = urllib.request.urlopen(request, data).read()
+ jcont = json.loads(content)
+ return jcont
+ except urllib.error.HTTPError as e:
+ print(('HTTPError = ' + str(e.code)))
+ print((str(e)))
+ raise e
+ except urllib.error.URLError as e:
+ print(('URLError = ' + str(e.reason)))
+ raise e
+ except http.client.HTTPException as e:
+ print(('HTTPException = ' + str(e)))
+ raise e
+ except Exception:
+ import traceback
+ print(('generic exception: ' + traceback.format_exc()))
+ raise IOError
diff --git a/CI/lastRelease.py b/CI/lastRelease.py
new file mode 100755
index 00000000..04782cca
--- /dev/null
+++ b/CI/lastRelease.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import ghApiClient
+
+def getLastReleaseTag():
+ content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases')
+ for l in content:
+ draft = l["draft"]
+ tag = l["tag_name"]
+ if str(draft) != 'True' and tag.startswith("swagger-petstore-v31-"):
+ return tag
+ print ("NO RELEASE TAG FOUND, using default swagger-petstore-v31-1.0.3")
+ return "swagger-petstore-v31-1.0.3"
+# main
+def main():
+ result = getLastReleaseTag()
+ print (result)
+
+# here start main
+main()
diff --git a/CI/post-release.sh b/CI/post-release.sh
new file mode 100755
index 00000000..ea734254
--- /dev/null
+++ b/CI/post-release.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+CUR=$(pwd)
+TMPDIR="$(dirname -- "${0}")"
+
+SC_RELEASE_TAG="swagger-petstore-v31-$SC_VERSION"
+
+#####################
+### publish pre-prepared release (tag is created)
+#####################
+python $CUR/CI/publishRelease.py "$SC_RELEASE_TAG"
+
+#####################
+### update the version to next snapshot in maven project with set version
+#####################
+mvn versions:set -DnewVersion="${SC_NEXT_VERSION}-SNAPSHOT"
+mvn versions:commit
+
+#####################
+### update all other versions in files around to the next snapshot or new release, including readme and gradle ###
+#####################
+
+sc_find="version: $SC_VERSION"
+sc_replace="version\: $SC_NEXT_VERSION\-SNAPSHOT"
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/webapp/design-first/petstore.yaml
+
+
+sc_find="version: $SC_VERSION"
+sc_replace="version\: $SC_NEXT_VERSION\-SNAPSHOT"
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/webapp/code-first/openapi.yaml
+
+
+sc_find="\"version\" \: \"$SC_VERSION\""
+sc_replace="\"version\" \: \"$SC_NEXT_VERSION\-SNAPSHOT\""
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/webapp/code-first/openapi.json
+
+sc_find="version \= \"$SC_VERSION\""
+sc_replace="version \= \"$SC_NEXT_VERSION\-SNAPSHOT\""
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/java/io/swagger/petstore/resource/DefinitionResource.java
diff --git a/CI/pre-release.sh b/CI/pre-release.sh
new file mode 100755
index 00000000..95746f76
--- /dev/null
+++ b/CI/pre-release.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+CUR=$(pwd)
+
+export SC_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+export SC_NEXT_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+SC_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+#SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+SC_LAST_RELEASE=`python $CUR/CI/lastRelease.py`
+
+
+SC_RELEASE_TAG="$SC_VERSION"
+
+
+#####################
+### build and test maven ###
+#####################
+mvn --no-transfer-progress -B install --file pom.xml
diff --git a/CI/prepare-release.sh b/CI/prepare-release.sh
new file mode 100755
index 00000000..2541a829
--- /dev/null
+++ b/CI/prepare-release.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+
+CUR=$(pwd)
+
+export SC_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+export SC_NEXT_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+SC_QUALIFIER=`mvn -q -Dexec.executable="echo" -Dexec.args='${parsedVersion.qualifier}' --non-recursive build-helper:parse-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+#SC_LAST_RELEASE=`mvn -q -Dexec.executable="echo" -Dexec.args='${releasedVersion.version}' --non-recursive org.codehaus.mojo:build-helper-maven-plugin:3.2.0:released-version org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
+SC_LAST_RELEASE=`python $CUR/CI/lastRelease.py`
+
+
+
+SC_RELEASE_TITLE="Swagger Petstore OpenAPI 3.1 release $SC_VERSION"
+SC_RELEASE_TAG="swagger-petstore-v31-$SC_VERSION"
+
+echo "SC_VERSION: $SC_VERSION"
+echo "SC_NEXT_VERSION: $SC_NEXT_VERSION"
+echo "SC_LAST_RELEASE: $SC_LAST_RELEASE"
+echo "SC_RELEASE_TITLE: $SC_RELEASE_TITLE"
+echo "SC_RELEASE_TAG: $SC_RELEASE_TAG"
+
+#####################
+### draft release Notes with next release after last release, with tag
+#####################
+python $CUR/CI/releaseNotes.py "$SC_LAST_RELEASE" "$SC_RELEASE_TITLE" "$SC_RELEASE_TAG"
+
+#####################
+### update the version to release in maven project with set version
+#####################
+mvn versions:set -DnewVersion=$SC_VERSION
+mvn versions:commit
+
+#####################
+### update versions in files around ###
+#####################
+sc_find="version\: $SC_VERSION\-SNAPSHOT"
+sc_replace="version: $SC_VERSION"
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/webapp/design-first/petstore.yaml
+
+
+sc_find="version\: $SC_VERSION\-SNAPSHOT"
+sc_replace="version: $SC_VERSION"
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/webapp/code-first/openapi.yaml
+
+
+sc_find="\"version\" \: \"$SC_VERSION\-SNAPSHOT\""
+sc_replace="\"version\" \: \"$SC_VERSION\""
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/webapp/code-first/openapi.json
+
+sc_find="version \= \"$SC_VERSION\-SNAPSHOT\""
+sc_replace="version \= \"$SC_VERSION\""
+sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/java/io/swagger/petstore/resource/DefinitionResource.java
+
+#####################
+### build and test maven ###
+#####################
+mvn --no-transfer-progress -B install --file pom.xml
+
diff --git a/CI/publishRelease.py b/CI/publishRelease.py
new file mode 100755
index 00000000..40db50e2
--- /dev/null
+++ b/CI/publishRelease.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import sys
+import ghApiClient
+
+def lastReleaseId(tag):
+ content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases')
+ for l in content:
+ draft = l["draft"]
+ draft_tag = l["tag_name"]
+ if str(draft) == 'True' and tag == draft_tag:
+ return l["id"]
+
+def publishRelease(tag):
+ id = lastReleaseId(tag)
+ payload = "{\"tag_name\":\"" + tag + "\", "
+ payload += "\"draft\":" + "false" + ", "
+ payload += "\"target_commitish\":\"" + "v31" + "\"}"
+ content = ghApiClient.postUrl('repos/swagger-api/swagger-petstore/releases/' + str(id), payload)
+ return content
+
+# main
+def main(tag):
+ publishRelease (tag)
+
+# here start main
+main(sys.argv[1])
diff --git a/CI/releaseNotes.py b/CI/releaseNotes.py
new file mode 100755
index 00000000..26c842d2
--- /dev/null
+++ b/CI/releaseNotes.py
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+import sys
+import json
+from datetime import datetime
+import ghApiClient
+
+def allPulls(releaseDate):
+
+ result = ""
+
+ baseurl = "https://api.github.com/repos/swagger-api/swagger-petstore/pulls/"
+ content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/pulls?state=closed&base=v31&per_page=100')
+ for l in content:
+ stripped = l["url"][len(baseurl):]
+ mergedAt = l["merged_at"]
+ if mergedAt is not None:
+ if datetime.strptime(mergedAt, '%Y-%m-%dT%H:%M:%SZ') > releaseDate:
+ if not l['title'].startswith("bump snap"):
+ result += '\n'
+ result += "* " + l['title'] + " (#" + stripped + ")"
+ return result
+
+
+def lastReleaseDate(tag):
+ content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases/tags/' + tag)
+ publishedAt = content["published_at"]
+ return datetime.strptime(publishedAt, '%Y-%m-%dT%H:%M:%SZ')
+
+
+def addRelease(release_title, tag, content):
+ payload = "{\"tag_name\":\"" + tag + "\", "
+ payload += "\"name\":" + json.dumps(release_title) + ", "
+ payload += "\"body\":" + json.dumps(content) + ", "
+ payload += "\"draft\":" + "true" + ", "
+ payload += "\"prerelease\":" + "false" + ", "
+ payload += "\"target_commitish\":\"" + "v31" + "\"}"
+ content = ghApiClient.postUrl('repos/swagger-api/swagger-petstore/releases', payload)
+ return content
+
+def getReleases():
+ content = ghApiClient.readUrl('repos/swagger-api/swagger-petstore/releases')
+ return content
+
+# main
+def main(last_release, release_title, tag):
+ result = allPulls(lastReleaseDate(last_release))
+ addRelease (release_title, tag, result)
+
+# here start main
+main(sys.argv[1], sys.argv[2], sys.argv[3])
+
diff --git a/CI/version.sh b/CI/version.sh
new file mode 100755
index 00000000..68739000
--- /dev/null
+++ b/CI/version.sh
@@ -0,0 +1 @@
+grep version pom.xml | grep -v -e '//g' | awk '{print $1}'
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 6eac34c5..9378a77b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
swagger-petstore-v31
war
Swagger Petstore V3.1
- 1.0.3
+ 1.0.4-SNAPSHOT
https://github.com/swagger-api/swagger-petstore
scm:git:git@github.com:swagger-api/swagger-petstore.git
diff --git a/src/main/java/io/swagger/petstore/resource/DefinitionResource.java b/src/main/java/io/swagger/petstore/resource/DefinitionResource.java
index ac66f611..319600a1 100644
--- a/src/main/java/io/swagger/petstore/resource/DefinitionResource.java
+++ b/src/main/java/io/swagger/petstore/resource/DefinitionResource.java
@@ -22,7 +22,7 @@
info = @Info(
title = "Swagger Petstore - OpenAPI 3.1",
summary = "Pet Store 3.1",
- version = "1.0.3",
+ version = "1.0.4-SNAPSHOT",
description = "This is a sample Pet Store Server based on the OpenAPI 3.1 specification.\nYou can find out more about\nSwagger at [http://swagger.io](http://swagger.io).",
termsOfService = "http://swagger.io/terms/",
contact = @Contact (
diff --git a/src/main/webapp/code-first/openapi.json b/src/main/webapp/code-first/openapi.json
index 7303c0ca..a9d5c21d 100644
--- a/src/main/webapp/code-first/openapi.json
+++ b/src/main/webapp/code-first/openapi.json
@@ -11,7 +11,7 @@
"name" : "Apache 2.0 AND (MIT OR GPL-2.0-only)",
"identifier" : "Apache-2.0 AND (MIT OR GPL-2.0-only)"
},
- "version" : "1.0.3",
+ "version" : "1.0.4-SNAPSHOT",
"summary" : "Pet Store 3.1",
"x-namespace" : "swagger"
},
diff --git a/src/main/webapp/code-first/openapi.yaml b/src/main/webapp/code-first/openapi.yaml
index 8ee29581..b93fc84f 100644
--- a/src/main/webapp/code-first/openapi.yaml
+++ b/src/main/webapp/code-first/openapi.yaml
@@ -11,7 +11,7 @@ info:
license:
name: Apache 2.0 AND (MIT OR GPL-2.0-only)
identifier: Apache-2.0 AND (MIT OR GPL-2.0-only)
- version: 1.0.3
+ version: 1.0.4-SNAPSHOT
summary: Pet Store 3.1
x-namespace: swagger
externalDocs:
diff --git a/src/main/webapp/design-first/petstore.yaml b/src/main/webapp/design-first/petstore.yaml
index 3e2474a5..f4e4b94a 100644
--- a/src/main/webapp/design-first/petstore.yaml
+++ b/src/main/webapp/design-first/petstore.yaml
@@ -10,7 +10,7 @@ info:
license:
name: Apache 2.0 AND (MIT OR GPL-2.0-only)
identifier: Apache-2.0 AND (MIT OR GPL-2.0-only)
- version: 1.0.3
+ version: 1.0.4-SNAPSHOT
x-namespace: Swagger
externalDocs:
description: Find out more about Swagger