| 
 | 1 | +name: Release Codegen 3.0 and Generators  | 
 | 2 | + | 
 | 3 | +on:  | 
 | 4 | +  workflow_dispatch:  | 
 | 5 | +    branches: [ "3.0.0" ]  | 
 | 6 | + | 
 | 7 | +jobs:  | 
 | 8 | +  release:  | 
 | 9 | +    runs-on: ubuntu-latest  | 
 | 10 | +    steps:  | 
 | 11 | +      - name: Checkout swagger-codegen (3.0.0)  | 
 | 12 | +        uses: actions/checkout@v4  | 
 | 13 | +        with:  | 
 | 14 | +          token: ${{ secrets.GITHUB_TOKEN }}  | 
 | 15 | +          ref: 3.0.0  | 
 | 16 | + | 
 | 17 | +      - name: Checkout swagger-codegen-generators  | 
 | 18 | +        uses: actions/checkout@v4  | 
 | 19 | +        with:  | 
 | 20 | +          repository: swagger-api/swagger-codegen-generators  | 
 | 21 | +          token: ${{ secrets.GITHUB_TOKEN }}  | 
 | 22 | +          ref: master  | 
 | 23 | +          path: generators-repo  | 
 | 24 | +      - uses: tibdex/github-app-token@v2  | 
 | 25 | +        id: generate-token  | 
 | 26 | +        with:  | 
 | 27 | +          app_id: ${{ secrets.APP_ID }}  | 
 | 28 | +          private_key: ${{ secrets.APP_PRIVATE_KEY }}  | 
 | 29 | +      - name: Set up Java and Maven  | 
 | 30 | +        uses: actions/setup-java@v4  | 
 | 31 | +        with:  | 
 | 32 | +          java-version: '17'  | 
 | 33 | +          distribution: 'temurin'  | 
 | 34 | +          server-id: central  | 
 | 35 | +          server-username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}  | 
 | 36 | +          server-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}  | 
 | 37 | +          gpg-private-key: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }}  | 
 | 38 | +      - name: Cache Maven repository  | 
 | 39 | +        uses: actions/cache@v4  | 
 | 40 | +        with:  | 
 | 41 | +          path: ~/.m2/repository  | 
 | 42 | +          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}  | 
 | 43 | +      - name: configure git user email  | 
 | 44 | +        run: |  | 
 | 45 | +          git config --global user.email "[email protected]"  | 
 | 46 | +          git config --global user.name "GitHub Action"  | 
 | 47 | +          git config --global hub.protocol https  | 
 | 48 | +          git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:[email protected]/swagger-api/swagger-codegen.git  | 
 | 49 | +      - name: Check Release Version codegen  | 
 | 50 | +        id: preRelease  | 
 | 51 | +        run: |  | 
 | 52 | +          # export GPG_TTY=$(tty)  | 
 | 53 | +          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`  | 
 | 54 | +          if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];  | 
 | 55 | +          then  | 
 | 56 | +            echo "not releasing snapshot version: " ${MY_POM_VERSION}  | 
 | 57 | +            echo "RELEASE_OK=no" >> $GITHUB_ENV  | 
 | 58 | +          else  | 
 | 59 | +            echo "RELEASE_OK=yes" >> $GITHUB_ENV  | 
 | 60 | +          fi  | 
 | 61 | +          echo "SC_VERSION=$MY_POM_VERSION" >> $GITHUB_ENV  | 
 | 62 | +      - name: Check Release Version codegen-generators  | 
 | 63 | +        id: preRelease generators  | 
 | 64 | +        if: env.RELEASE_OK == 'yes'  | 
 | 65 | +        working-directory: generators-repo  | 
 | 66 | +        run: |  | 
 | 67 | +          # export GPG_TTY=$(tty)  | 
 | 68 | +          export MY_POM_VERSION_GENERATORS=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`  | 
 | 69 | +          if [[ $MY_POM_VERSION_GENERATORS =~ ^.*SNAPSHOT$ ]];  | 
 | 70 | +          then  | 
 | 71 | +            echo "not releasing snapshot version: " ${MY_POM_VERSION_GENERATORS}  | 
 | 72 | +            echo "RELEASE_OK=no" >> $GITHUB_ENV  | 
 | 73 | +          else  | 
 | 74 | +            echo "RELEASE_OK=yes" >> $GITHUB_ENV  | 
 | 75 | +          fi  | 
 | 76 | +          echo "SC_VERSION_GENERATORS=$MY_POM_VERSION_GENERATORS" >> $GITHUB_ENV  | 
 | 77 | +      - name:  Run maven install for codegen-generators  | 
 | 78 | +        if: env.RELEASE_OK == 'yes'  | 
 | 79 | +        working-directory: generators-repo  | 
 | 80 | +        run: |  | 
 | 81 | +          SNAP_API="https://central.sonatype.com/repository/maven-snapshots"  | 
 | 82 | +          ARTIFACT_PATH="io/swagger/codegen/v3/swagger-codegen"  | 
 | 83 | +          ROOT_META="${SNAP_API}/${ARTIFACT_PATH}/maven-metadata.xml"  | 
 | 84 | +          export LAST_SNAP=$(curl -s "$ROOT_META" | grep -oP '(?<=<version>)3\.[^<]+' | sort -V | tail -n1)  | 
 | 85 | +          echo "LAST_SNAP $LAST_SNAP"  | 
 | 86 | +          export CODEGEN_VERSION_PROPERTY=-Dswagger-codegen-version=$LAST_SNAP  | 
 | 87 | +          mvn clean install -U ${CODEGEN_VERSION_PROPERTY}  | 
 | 88 | +      - name:  Run maven install for codegen  | 
 | 89 | +        if: env.RELEASE_OK == 'yes'  | 
 | 90 | +        run: |  | 
 | 91 | +          SNAP_API="https://central.sonatype.com/repository/maven-snapshots"  | 
 | 92 | +          ARTIFACT_PATH="io/swagger/codegen/v3/swagger-codegen-generators"  | 
 | 93 | +          ROOT_META="${SNAP_API}/${ARTIFACT_PATH}/maven-metadata.xml"  | 
 | 94 | +          export LAST_SNAP=$(curl -s "$ROOT_META" | grep -oP '(?<=<version>)1\.[^<]+' | sort -V | tail -n1)  | 
 | 95 | +          echo "LAST_SNAP $LAST_SNAP"  | 
 | 96 | +          export GENERATORS_VERSION_PROPERTY=-Dswagger-codegen-generators-version=$LAST_SNAP  | 
 | 97 | +          mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089 ${GENERATORS_VERSION_PROPERTY}  | 
 | 98 | +      - name:  Run maven deploy/release for codegen-generators  | 
 | 99 | +        if: env.RELEASE_OK == 'yes'  | 
 | 100 | +        working-directory: generators-repo  | 
 | 101 | +        run: |  | 
 | 102 | +          mvn --no-transfer-progress -B -Prelease deploy  | 
 | 103 | +      - name:  Run maven deploy/release for codegen  | 
 | 104 | +        if: env.RELEASE_OK == 'yes'  | 
 | 105 | +        run: |  | 
 | 106 | +          mvn --no-transfer-progress -B -Prelease deploy  | 
 | 107 | +      - name: Set up QEMU  | 
 | 108 | +        uses: docker/setup-qemu-action@v3  | 
 | 109 | +      - name: Set up Docker Buildx  | 
 | 110 | +        uses: docker/setup-buildx-action@v3  | 
 | 111 | +      - name: preliminary checks  | 
 | 112 | +        run: |  | 
 | 113 | +          docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }}  | 
 | 114 | +          set -e  | 
 | 115 | +      - name: Build with Maven  | 
 | 116 | +        run: |  | 
 | 117 | +          mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089  | 
 | 118 | +      - name: docker generator build and push  | 
 | 119 | +        if: env.RELEASE_OK == 'yes'  | 
 | 120 | +        uses: docker/build-push-action@v5  | 
 | 121 | +        with:  | 
 | 122 | +          context: ./modules/swagger-generator  | 
 | 123 | +          file: ./modules/swagger-generator/Dockerfile  | 
 | 124 | +          push: true  | 
 | 125 | +          platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x  | 
 | 126 | +          provenance: false  | 
 | 127 | +          build-args: |  | 
 | 128 | +            HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml  | 
 | 129 | +            JAVA_MEM=1024m  | 
 | 130 | +            HTTP_PORT=8080  | 
 | 131 | +          tags: swaggerapi/swagger-generator-v3:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3:latest  | 
 | 132 | +      - name: docker generator root build and push  | 
 | 133 | +        if: env.RELEASE_OK == 'yes'  | 
 | 134 | +        uses: docker/build-push-action@v5  | 
 | 135 | +        with:  | 
 | 136 | +          context: ./modules/swagger-generator  | 
 | 137 | +          file: ./modules/swagger-generator/Dockerfile_root  | 
 | 138 | +          push: true  | 
 | 139 | +          platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x  | 
 | 140 | +          provenance: false  | 
 | 141 | +          build-args: |  | 
 | 142 | +            HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml  | 
 | 143 | +            JAVA_MEM=1024m  | 
 | 144 | +            HTTP_PORT=8080  | 
 | 145 | +          tags: swaggerapi/swagger-generator-v3-root:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-root:latest  | 
 | 146 | +      - name: docker cli build and push  | 
 | 147 | +        if: env.RELEASE_OK == 'yes'  | 
 | 148 | +        uses: docker/build-push-action@v5  | 
 | 149 | +        with:  | 
 | 150 | +          context: ./modules/swagger-generator  | 
 | 151 | +          file: ./modules/swagger-generator/Dockerfile_minimal  | 
 | 152 | +          push: true  | 
 | 153 | +          platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x  | 
 | 154 | +          provenance: false  | 
 | 155 | +          tags: swaggerapi/swagger-codegen-cli-v3:${{ env.SC_VERSION }},swaggerapi/swagger-codegen-cli-v3:latest  | 
 | 156 | +      - name: docker minimal build and push  | 
 | 157 | +        if: env.RELEASE_OK == 'yes'  | 
 | 158 | +        uses: docker/build-push-action@v5  | 
 | 159 | +        with:  | 
 | 160 | +          context: ./modules/swagger-generator  | 
 | 161 | +          file: ./modules/swagger-generator/Dockerfile_minimal  | 
 | 162 | +          push: true  | 
 | 163 | +          platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x  | 
 | 164 | +          provenance: false  | 
 | 165 | +          tags: swaggerapi/swagger-generator-v3-minimal:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-minimal:latest  | 
 | 166 | +      - name: deploy  | 
 | 167 | +        run: |  | 
 | 168 | +          echo "${{ env.SC_VERSION }}"  | 
 | 169 | +
  | 
 | 170 | +          TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}"  | 
 | 171 | +          RANCHER_HOST="rancher.tools.swagger.io"  | 
 | 172 | +          CLUSTER_ID="c-n8zp2"  | 
 | 173 | +          NAMESPACE_NAME="swagger-oss"  | 
 | 174 | +          K8S_OBJECT_TYPE="daemonsets"  | 
 | 175 | +          K8S_OBJECT_NAME="swagger-generator-v3"  | 
 | 176 | +          DEPLOY_IMAGE="swaggerapi/swagger-generator-v3:${{ env.SC_VERSION }}"  | 
 | 177 | +
  | 
 | 178 | +          workloadStatus=""  | 
 | 179 | +          getStatus() {  | 
 | 180 | +              echo "Getting update status..."  | 
 | 181 | +              if ! workloadStatus="$(curl -s -X GET \  | 
 | 182 | +                -H "Authorization: Bearer ${TOKEN}" \  | 
 | 183 | +                -H 'Content-Type: application/json' \  | 
 | 184 | +                "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")"  | 
 | 185 | +              then  | 
 | 186 | +                  echo 'ERROR - get status k8s API call failed!'  | 
 | 187 | +                  echo "Exiting build"...  | 
 | 188 | +                  exit 1  | 
 | 189 | +              fi  | 
 | 190 | +          }  | 
 | 191 | +
  | 
 | 192 | +          # $1 = image to deploy  | 
 | 193 | +          updateObject() {  | 
 | 194 | +              local image="${1}"  | 
 | 195 | +              echo "Updating image value..."  | 
 | 196 | +
  | 
 | 197 | +              if ! curl -s -X PATCH \  | 
 | 198 | +                -H "Authorization: Bearer ${TOKEN}" \  | 
 | 199 | +                -H 'Content-Type: application/json-patch+json' \  | 
 | 200 | +                "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \  | 
 | 201 | +                -d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}]"  | 
 | 202 | +              then  | 
 | 203 | +                  echo 'ERROR - image update k8s API call failed!'  | 
 | 204 | +                  echo "Exiting build..."  | 
 | 205 | +                  exit 1  | 
 | 206 | +              fi  | 
 | 207 | +          }  | 
 | 208 | +
  | 
 | 209 | +
  | 
 | 210 | +          # Check that the TAG is valid  | 
 | 211 | +          if [[ ${{ env.SC_VERSION }} =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then  | 
 | 212 | +              echo ""  | 
 | 213 | +              echo "This is a Valid TAG..."  | 
 | 214 | +
  | 
 | 215 | +              # Get current image/tag in case we need to rollback  | 
 | 216 | +              getStatus  | 
 | 217 | +              ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')"  | 
 | 218 | +              echo ""  | 
 | 219 | +              echo "Current image: ${ROLLBACK_IMAGE}"  | 
 | 220 | +
  | 
 | 221 | +              # Update image and validate response  | 
 | 222 | +              echo ""  | 
 | 223 | +              updateObject "${DEPLOY_IMAGE}"  | 
 | 224 | +              echo ""  | 
 | 225 | +
  | 
 | 226 | +              echo ""  | 
 | 227 | +              echo "Waiting for pods to start..."  | 
 | 228 | +              echo ""  | 
 | 229 | +              sleep 60s  | 
 | 230 | +
  | 
 | 231 | +              # Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error  | 
 | 232 | +              getStatus  | 
 | 233 | +                  status="$(echo "${workloadStatus}" | jq '.status')"  | 
 | 234 | +              echo ""  | 
 | 235 | +              echo "${status}"  | 
 | 236 | +              echo ""  | 
 | 237 | +
  | 
 | 238 | +              numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"  | 
 | 239 | +              numberReady="$(echo "${status}" | jq -r '.numberReady')"  | 
 | 240 | +
  | 
 | 241 | +              if (( numberReady == numberDesired )); then  | 
 | 242 | +                  echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}"  | 
 | 243 | +
  | 
 | 244 | +              # If pods are not starting, rollback the upgrade and exit the build with error  | 
 | 245 | +              else  | 
 | 246 | +                  echo "state = error...rolling back upgrade"  | 
 | 247 | +                  updateObject "${ROLLBACK_IMAGE}"  | 
 | 248 | +                  echo ""  | 
 | 249 | +
  | 
 | 250 | +                  echo ""  | 
 | 251 | +                  echo "Waiting for rollback pods to start..."  | 
 | 252 | +                  echo ""  | 
 | 253 | +                  sleep 60s  | 
 | 254 | +
  | 
 | 255 | +                  getStatus  | 
 | 256 | +                  status="$(echo "${workloadStatus}" | jq '.status')"  | 
 | 257 | +                  echo ""  | 
 | 258 | +                  echo "${status}"  | 
 | 259 | +                  echo ""  | 
 | 260 | +
  | 
 | 261 | +                  numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"  | 
 | 262 | +                  numberReady="$(echo "${status}" | jq -r '.numberReady')"  | 
 | 263 | +
  | 
 | 264 | +                  if (( numberReady == numberDesired )); then  | 
 | 265 | +                      echo "Rollback to ${ROLLBACK_IMAGE} completed."  | 
 | 266 | +                  else  | 
 | 267 | +                      echo "FATAL - rollback failed"  | 
 | 268 | +                  fi  | 
 | 269 | +                  echo "Exiting Build..."  | 
 | 270 | +                  exit 1  | 
 | 271 | +              fi  | 
 | 272 | +
  | 
 | 273 | +          else  | 
 | 274 | +              echo "This TAG is not in a valid format..."  | 
 | 275 | +              echo "Exiting Build..."  | 
 | 276 | +              exit 0  | 
 | 277 | +          fi  | 
 | 278 | +          echo "Exiting Build..."  | 
 | 279 | +          exit 0  | 
 | 280 | +    env:  | 
 | 281 | +      ACTIONS_ALLOW_UNSECURE_COMMANDS:  true  | 
 | 282 | +      MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}  | 
 | 283 | +      MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}  | 
 | 284 | +      GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}  | 
 | 285 | +      SC_VERSION:  | 
 | 286 | +      SC_VERSION_GENERATORS:  | 
 | 287 | +      GPG_PRIVATE_KEY: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }}  | 
 | 288 | +      GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }}  | 
0 commit comments