From ff3915991c917fa348f4760f763ebc093027e01f Mon Sep 17 00:00:00 2001 From: MicRyc Date: Wed, 13 Mar 2024 13:00:56 +0100 Subject: [PATCH 1/7] Add CI/CD workflows for petstore-v31 --- .github/workflows/codeql-analysis.yml | 54 +++++++ .github/workflows/dependency-review.yml | 16 ++ .github/workflows/deploy-docker.yml | 134 ++++++++++++++++ .github/workflows/dockerhub-release.yaml | 61 ++++++++ .github/workflows/maven-pulls.yml | 30 ++++ .github/workflows/maven.yml | 36 +++++ .github/workflows/prepare-release.yml | 54 +++++++ .github/workflows/release.yml | 190 +++++++++++++++++++++++ CI/docker-release.sh | 16 ++ CI/ghApiClient.py | 59 +++++++ CI/lastRelease.py | 20 +++ CI/post-release.sh | 25 +++ CI/pre-release.sh | 18 +++ CI/prepare-release.sh | 44 ++++++ CI/publishRelease.py | 27 ++++ CI/releaseNotes.py | 52 +++++++ CI/version.sh | 1 + 17 files changed, 837 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/dependency-review.yml create mode 100644 .github/workflows/deploy-docker.yml create mode 100644 .github/workflows/dockerhub-release.yaml create mode 100644 .github/workflows/maven-pulls.yml create mode 100644 .github/workflows/maven.yml create mode 100644 .github/workflows/prepare-release.yml create mode 100644 .github/workflows/release.yml create mode 100755 CI/docker-release.sh create mode 100755 CI/ghApiClient.py create mode 100755 CI/lastRelease.py create mode 100755 CI/post-release.sh create mode 100755 CI/pre-release.sh create mode 100755 CI/prepare-release.sh create mode 100755 CI/publishRelease.py create mode 100755 CI/releaseNotes.py create mode 100755 CI/version.sh diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 00000000..c0a95e31 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,54 @@ +name: "Code scanning - action" + +on: + push: + branches: ["master", "v2", "v31"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["master"] + 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..e3da0978 --- /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/swagger-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..2766e4c0 --- /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-3" + DEPLOY_IMAGE="swaggerapi/petstore3:$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/CI/docker-release.sh b/CI/docker-release.sh new file mode 100755 index 00000000..645801c8 --- /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 petstore3 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..9a7a6e31 --- /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.2") + return "swagger-petstore-v31-1.0.2" +# 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..1e1f2ee5 --- /dev/null +++ b/CI/post-release.sh @@ -0,0 +1,25 @@ +#!/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/resources/openapi.yaml 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..ab683592 --- /dev/null +++ b/CI/prepare-release.sh @@ -0,0 +1,44 @@ +#!/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 version in openapi.yaml file ### +##################### +sc_find="version\: $SC_VERSION\-SNAPSHOT" +sc_replace="version: $SC_VERSION" +sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/resources/openapi.yaml + +##################### +### 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..3c762903 --- /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\":\"" + "master" + "\"}" + 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..c933f92c --- /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=master&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\":\"" + "master" + "\"}" + 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 From 8503b4b9f2c04d51056fc32ca8fb575157465d4a Mon Sep 17 00:00:00 2001 From: MicRyc Date: Thu, 14 Mar 2024 14:03:46 +0100 Subject: [PATCH 2/7] CI - fix gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) 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 From 7bfde2bf8b63caef8dde7573fd9eaaec8dacf229 Mon Sep 17 00:00:00 2001 From: MicRyc Date: Thu, 14 Mar 2024 14:18:32 +0100 Subject: [PATCH 3/7] Fix deploy docker image name --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/release.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c0a95e31..ec580d19 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -2,7 +2,7 @@ name: "Code scanning - action" on: push: - branches: ["master", "v2", "v31"] + branches: ["v31"] pull_request: # The branches below must be a subset of the branches above branches: ["master"] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2766e4c0..ec993c1c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -78,8 +78,8 @@ jobs: CLUSTER_ID="c-n8zp2" NAMESPACE_NAME="swagger-oss" K8S_OBJECT_TYPE="daemonsets" - K8S_OBJECT_NAME="swagger-petstore-3" - DEPLOY_IMAGE="swaggerapi/petstore3:$SC_RELEASE_TAG" + K8S_OBJECT_NAME="swagger-petstore-31" + DEPLOY_IMAGE="swaggerapi/petstore31:$SC_RELEASE_TAG" workloadStatus="" getStatus() { From a1614e3c42cdf37332d789d6ef5cbb8d86236a70 Mon Sep 17 00:00:00 2001 From: MicRyc Date: Wed, 20 Mar 2024 22:16:46 +0100 Subject: [PATCH 4/7] Update post/prepare release scripts --- CI/post-release.sh | 8 +++++++- CI/prepare-release.sh | 8 +++++++- pom.xml | 2 +- src/main/webapp/code-first/openapi.yaml | 2 +- src/main/webapp/design-first/petstore.yaml | 2 +- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CI/post-release.sh b/CI/post-release.sh index 1e1f2ee5..d383f440 100755 --- a/CI/post-release.sh +++ b/CI/post-release.sh @@ -22,4 +22,10 @@ mvn versions:commit sc_find="version\: $SC_VERSION" sc_replace="version: $SC_NEXT_VERSION-SNAPSHOT" -sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/resources/openapi.yaml +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/design-first/petstore.yaml diff --git a/CI/prepare-release.sh b/CI/prepare-release.sh index ab683592..3994f835 100755 --- a/CI/prepare-release.sh +++ b/CI/prepare-release.sh @@ -35,7 +35,13 @@ mvn versions:commit ##################### sc_find="version\: $SC_VERSION\-SNAPSHOT" sc_replace="version: $SC_VERSION" -sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/resources/openapi.yaml +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 ##################### ### build and test maven ### diff --git a/pom.xml b/pom.xml index 6eac34c5..940f57ca 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ swagger-petstore-v31 war Swagger Petstore V3.1 - 1.0.3 + 1.0.3-SNAPSHOT https://github.com/swagger-api/swagger-petstore scm:git:git@github.com:swagger-api/swagger-petstore.git diff --git a/src/main/webapp/code-first/openapi.yaml b/src/main/webapp/code-first/openapi.yaml index 8ee29581..941920b6 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.3-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..9bff3378 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.3-SNAPSHOT x-namespace: Swagger externalDocs: description: Find out more about Swagger From b9d9ac0f50a58b444750090a2a50a90619828a5a Mon Sep 17 00:00:00 2001 From: MicRyc Date: Thu, 21 Mar 2024 09:30:28 +0100 Subject: [PATCH 5/7] Fix-CI scripts and references --- .github/workflows/codeql-analysis.yml | 2 +- .github/workflows/deploy-docker.yml | 2 +- CI/docker-release.sh | 2 +- CI/post-release.sh | 18 +++++++++++++----- CI/prepare-release.sh | 10 +++++++++- CI/publishRelease.py | 2 +- CI/releaseNotes.py | 4 ++-- .../petstore/resource/DefinitionResource.java | 2 +- src/main/webapp/code-first/openapi.json | 2 +- 9 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ec580d19..cea99809 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -5,7 +5,7 @@ on: branches: ["v31"] pull_request: # The branches below must be a subset of the branches above - branches: ["master"] + branches: ["v31"] schedule: - cron: '0 19 * * 1' diff --git a/.github/workflows/deploy-docker.yml b/.github/workflows/deploy-docker.yml index e3da0978..f99f7245 100644 --- a/.github/workflows/deploy-docker.yml +++ b/.github/workflows/deploy-docker.yml @@ -24,7 +24,7 @@ jobs: NAMESPACE_NAME="swagger-oss" K8S_OBJECT_TYPE="daemonsets" K8S_OBJECT_NAME="swagger-petstore-31" - DEPLOY_IMAGE="swaggerapi/swagger-petstore31:$SC_RELEASE_TAG" + DEPLOY_IMAGE="swaggerapi/petstore31:$SC_RELEASE_TAG" workloadStatus="" getStatus() { diff --git a/CI/docker-release.sh b/CI/docker-release.sh index 645801c8..0cbf0212 100755 --- a/CI/docker-release.sh +++ b/CI/docker-release.sh @@ -13,4 +13,4 @@ docker tag $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG $DOCKER_PETSTORE_IMAGE_NA docker push $DOCKER_PETSTORE_IMAGE_NAME:$SC_RELEASE_TAG docker push $DOCKER_PETSTORE_IMAGE_NAME:latest echo "docker images:" -docker images | grep -i petstore3 +docker images | grep -i petstore31 diff --git a/CI/post-release.sh b/CI/post-release.sh index d383f440..1e5f81d1 100755 --- a/CI/post-release.sh +++ b/CI/post-release.sh @@ -20,12 +20,20 @@ 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" +sc_find="version: $SC_VERSION" +sc_replace="version\: $SC_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_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_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/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/java/io/swagger/petstore/resource/DefinitionResource.java diff --git a/CI/prepare-release.sh b/CI/prepare-release.sh index 3994f835..f59ec0da 100755 --- a/CI/prepare-release.sh +++ b/CI/prepare-release.sh @@ -38,11 +38,19 @@ 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 ### ##################### diff --git a/CI/publishRelease.py b/CI/publishRelease.py index 3c762903..40db50e2 100755 --- a/CI/publishRelease.py +++ b/CI/publishRelease.py @@ -15,7 +15,7 @@ def publishRelease(tag): id = lastReleaseId(tag) payload = "{\"tag_name\":\"" + tag + "\", " payload += "\"draft\":" + "false" + ", " - payload += "\"target_commitish\":\"" + "master" + "\"}" + payload += "\"target_commitish\":\"" + "v31" + "\"}" content = ghApiClient.postUrl('repos/swagger-api/swagger-petstore/releases/' + str(id), payload) return content diff --git a/CI/releaseNotes.py b/CI/releaseNotes.py index c933f92c..26c842d2 100755 --- a/CI/releaseNotes.py +++ b/CI/releaseNotes.py @@ -10,7 +10,7 @@ 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=master&per_page=100') + 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"] @@ -34,7 +34,7 @@ def addRelease(release_title, tag, content): payload += "\"body\":" + json.dumps(content) + ", " payload += "\"draft\":" + "true" + ", " payload += "\"prerelease\":" + "false" + ", " - payload += "\"target_commitish\":\"" + "master" + "\"}" + payload += "\"target_commitish\":\"" + "v31" + "\"}" content = ghApiClient.postUrl('repos/swagger-api/swagger-petstore/releases', payload) return content diff --git a/src/main/java/io/swagger/petstore/resource/DefinitionResource.java b/src/main/java/io/swagger/petstore/resource/DefinitionResource.java index ac66f611..2a38b34e 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.3-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..0430fba1 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.3-SNAPSHOT", "summary" : "Pet Store 3.1", "x-namespace" : "swagger" }, From 6d476a121bf470307031fc49bd3739e2ceac5a54 Mon Sep 17 00:00:00 2001 From: MicRyc Date: Thu, 21 Mar 2024 09:55:59 +0100 Subject: [PATCH 6/7] Fix prepare/post release script --- CI/post-release.sh | 10 +++++----- CI/prepare-release.sh | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CI/post-release.sh b/CI/post-release.sh index 1e5f81d1..8713450e 100755 --- a/CI/post-release.sh +++ b/CI/post-release.sh @@ -21,19 +21,19 @@ mvn versions:commit ##################### sc_find="version: $SC_VERSION" -sc_replace="version\: $SC_SC_NEXT_VERSION\-SNAPSHOT" +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_SC_NEXT_VERSION\-SNAPSHOT" +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_SC_NEXT_VERSION\-SNAPSHOT\"" +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\"" +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/prepare-release.sh b/CI/prepare-release.sh index f59ec0da..324ba959 100755 --- a/CI/prepare-release.sh +++ b/CI/prepare-release.sh @@ -43,12 +43,12 @@ 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_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\"" +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 ##################### From 507c90ab745c906b3ce6e7b65215b1c776f60890 Mon Sep 17 00:00:00 2001 From: MicRyc Date: Thu, 21 Mar 2024 11:38:45 +0100 Subject: [PATCH 7/7] Add 1.0.4-SNAPSHOT/sed syntax fix --- CI/lastRelease.py | 4 ++-- CI/post-release.sh | 2 +- CI/prepare-release.sh | 2 +- pom.xml | 2 +- .../java/io/swagger/petstore/resource/DefinitionResource.java | 2 +- src/main/webapp/code-first/openapi.json | 2 +- src/main/webapp/code-first/openapi.yaml | 2 +- src/main/webapp/design-first/petstore.yaml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CI/lastRelease.py b/CI/lastRelease.py index 9a7a6e31..04782cca 100755 --- a/CI/lastRelease.py +++ b/CI/lastRelease.py @@ -9,8 +9,8 @@ def getLastReleaseTag(): 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.2") - return "swagger-petstore-v31-1.0.2" + 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() diff --git a/CI/post-release.sh b/CI/post-release.sh index 8713450e..ea734254 100755 --- a/CI/post-release.sh +++ b/CI/post-release.sh @@ -31,7 +31,7 @@ sed -i -e "s/$sc_find/$sc_replace/g" $CUR/src/main/webapp/code-first/openapi.yam sc_find="\"version\" \: \"$SC_VERSION\"" -sc_replace="\"version \: \"$SC_NEXT_VERSION\-SNAPSHOT\"" +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\"" diff --git a/CI/prepare-release.sh b/CI/prepare-release.sh index 324ba959..2541a829 100755 --- a/CI/prepare-release.sh +++ b/CI/prepare-release.sh @@ -31,7 +31,7 @@ mvn versions:set -DnewVersion=$SC_VERSION mvn versions:commit ##################### -### update version in openapi.yaml file ### +### update versions in files around ### ##################### sc_find="version\: $SC_VERSION\-SNAPSHOT" sc_replace="version: $SC_VERSION" diff --git a/pom.xml b/pom.xml index 940f57ca..9378a77b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ swagger-petstore-v31 war Swagger Petstore V3.1 - 1.0.3-SNAPSHOT + 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 2a38b34e..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-SNAPSHOT", + 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 0430fba1..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-SNAPSHOT", + "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 941920b6..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-SNAPSHOT + 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 9bff3378..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-SNAPSHOT + version: 1.0.4-SNAPSHOT x-namespace: Swagger externalDocs: description: Find out more about Swagger